automation_model 1.0.732-dev → 1.0.732-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/lib/api.js +4 -3
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +4 -2
- package/lib/auto_page.js +153 -86
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +19 -25
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.js.map +1 -1
- package/lib/check_performance.d.ts +1 -0
- package/lib/check_performance.js +57 -0
- package/lib/check_performance.js.map +1 -0
- package/lib/command_common.js +18 -2
- package/lib/command_common.js.map +1 -1
- package/lib/file_checker.js +129 -25
- package/lib/file_checker.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/init_browser.d.ts +1 -2
- package/lib/init_browser.js +121 -125
- package/lib/init_browser.js.map +1 -1
- package/lib/locator.d.ts +1 -0
- package/lib/locator.js +9 -2
- package/lib/locator.js.map +1 -1
- package/lib/network.d.ts +2 -0
- package/lib/network.js +374 -86
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +21 -0
- package/lib/route.js +535 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +3 -3
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +27 -2
- package/lib/stable_browser.js +770 -54
- package/lib/stable_browser.js.map +1 -1
- package/lib/table.d.ts +9 -7
- package/lib/table.js +82 -12
- package/lib/table.js.map +1 -1
- package/lib/table_helper.js +14 -0
- package/lib/table_helper.js.map +1 -1
- package/lib/test_context.d.ts +1 -0
- package/lib/test_context.js +1 -0
- package/lib/test_context.js.map +1 -1
- package/lib/utils.d.ts +3 -1
- package/lib/utils.js +38 -6
- package/lib/utils.js.map +1 -1
- package/package.json +11 -9
package/lib/stable_browser.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
+
import { check_performance } from "./check_performance.js";
|
|
2
3
|
import { expect } from "@playwright/test";
|
|
3
4
|
import dayjs from "dayjs";
|
|
4
5
|
import fs from "fs";
|
|
@@ -10,7 +11,8 @@ import { getDateTimeValue } from "./date_time.js";
|
|
|
10
11
|
import drawRectangle from "./drawRect.js";
|
|
11
12
|
//import { closeUnexpectedPopups } from "./popups.js";
|
|
12
13
|
import { getTableCells, getTableData } from "./table_analyze.js";
|
|
13
|
-
import
|
|
14
|
+
import errorStackParser from "error-stack-parser";
|
|
15
|
+
import { _convertToRegexQuery, _copyContext, _fixLocatorUsingParams, _fixUsingParams, _getServerUrl, extractStepExampleParameters, KEYBOARD_EVENTS, maskValue, replaceWithLocalTestData, scrollPageToLoadLazyElements, unEscapeString, _getDataFile, testForRegex, performAction, _getTestData, } from "./utils.js";
|
|
14
16
|
import csv from "csv-parser";
|
|
15
17
|
import { Readable } from "node:stream";
|
|
16
18
|
import readline from "readline";
|
|
@@ -19,16 +21,20 @@ import { getTestData } from "./auto_page.js";
|
|
|
19
21
|
import { locate_element } from "./locate_element.js";
|
|
20
22
|
import { randomUUID } from "crypto";
|
|
21
23
|
import { _commandError, _commandFinally, _preCommand, _validateSelectors, _screenshot, _reportToWorld, } from "./command_common.js";
|
|
22
|
-
import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
24
|
+
import { networkAfterStep, networkBeforeStep, registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
23
25
|
import { LocatorLog } from "./locator_log.js";
|
|
24
26
|
import axios from "axios";
|
|
25
27
|
import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
26
|
-
import { snapshotValidation } from "./snapshot_validation.js";
|
|
28
|
+
import { highlightSnapshot, snapshotValidation } from "./snapshot_validation.js";
|
|
27
29
|
import { loadBrunoParams } from "./bruno.js";
|
|
30
|
+
import { registerAfterStepRoutes, registerBeforeStepRoutes } from "./route.js";
|
|
31
|
+
import { existsSync } from "node:fs";
|
|
28
32
|
export const Types = {
|
|
29
33
|
CLICK: "click_element",
|
|
30
34
|
WAIT_ELEMENT: "wait_element",
|
|
31
|
-
NAVIGATE: "navigate",
|
|
35
|
+
NAVIGATE: "navigate",
|
|
36
|
+
GO_BACK: "go_back",
|
|
37
|
+
GO_FORWARD: "go_forward",
|
|
32
38
|
FILL: "fill_element",
|
|
33
39
|
EXECUTE: "execute_page_method", //
|
|
34
40
|
OPEN: "open_environment", //
|
|
@@ -41,6 +47,7 @@ export const Types = {
|
|
|
41
47
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
42
48
|
ANALYZE_TABLE: "analyze_table",
|
|
43
49
|
SELECT: "select_combobox", //
|
|
50
|
+
VERIFY_PROPERTY: "verify_element_property",
|
|
44
51
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
45
52
|
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
46
53
|
TYPE_PRESS: "type_press",
|
|
@@ -49,6 +56,7 @@ export const Types = {
|
|
|
49
56
|
CHECK: "check_element",
|
|
50
57
|
UNCHECK: "uncheck_element",
|
|
51
58
|
EXTRACT: "extract_attribute",
|
|
59
|
+
EXTRACT_PROPERTY: "extract_property",
|
|
52
60
|
CLOSE_PAGE: "close_page",
|
|
53
61
|
TABLE_OPERATION: "table_operation",
|
|
54
62
|
SET_DATE_TIME: "set_date_time",
|
|
@@ -60,11 +68,13 @@ export const Types = {
|
|
|
60
68
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
61
69
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
62
70
|
BRUNO: "bruno",
|
|
63
|
-
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
64
71
|
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
65
72
|
SET_INPUT_FILES: "set_input_files",
|
|
73
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
66
74
|
REPORT_COMMAND: "report_command",
|
|
67
75
|
STEP_COMPLETE: "step_complete",
|
|
76
|
+
SLEEP: "sleep",
|
|
77
|
+
CONDITIONAL_WAIT: "conditional_wait",
|
|
68
78
|
};
|
|
69
79
|
export const apps = {};
|
|
70
80
|
const formatElementName = (elementName) => {
|
|
@@ -76,6 +86,8 @@ class StableBrowser {
|
|
|
76
86
|
logger;
|
|
77
87
|
context;
|
|
78
88
|
world;
|
|
89
|
+
fastMode;
|
|
90
|
+
stepTags;
|
|
79
91
|
project_path = null;
|
|
80
92
|
webLogFile = null;
|
|
81
93
|
networkLogger = null;
|
|
@@ -84,12 +96,15 @@ class StableBrowser {
|
|
|
84
96
|
tags = null;
|
|
85
97
|
isRecording = false;
|
|
86
98
|
initSnapshotTaken = false;
|
|
87
|
-
|
|
99
|
+
onlyFailuresScreenshot = process.env.SCREENSHOT_ON_FAILURE_ONLY === "true";
|
|
100
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false, stepTags = []) {
|
|
88
101
|
this.browser = browser;
|
|
89
102
|
this.page = page;
|
|
90
103
|
this.logger = logger;
|
|
91
104
|
this.context = context;
|
|
92
105
|
this.world = world;
|
|
106
|
+
this.fastMode = fastMode;
|
|
107
|
+
this.stepTags = stepTags;
|
|
93
108
|
if (!this.logger) {
|
|
94
109
|
this.logger = console;
|
|
95
110
|
}
|
|
@@ -118,6 +133,19 @@ class StableBrowser {
|
|
|
118
133
|
context.pages = [this.page];
|
|
119
134
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
120
135
|
this.world = world;
|
|
136
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
137
|
+
this.fastMode = true;
|
|
138
|
+
}
|
|
139
|
+
if (process.env.FAST_MODE === "true") {
|
|
140
|
+
// console.log("Fast mode enabled from environment variable");
|
|
141
|
+
this.fastMode = true;
|
|
142
|
+
}
|
|
143
|
+
if (process.env.FAST_MODE === "false") {
|
|
144
|
+
this.fastMode = false;
|
|
145
|
+
}
|
|
146
|
+
if (this.context) {
|
|
147
|
+
this.context.fastMode = this.fastMode;
|
|
148
|
+
}
|
|
121
149
|
this.registerEventListeners(this.context);
|
|
122
150
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
123
151
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -128,6 +156,9 @@ class StableBrowser {
|
|
|
128
156
|
if (!context.pageLoading) {
|
|
129
157
|
context.pageLoading = { status: false };
|
|
130
158
|
}
|
|
159
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
160
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
161
|
+
}
|
|
131
162
|
context.playContext.on("page", async function (page) {
|
|
132
163
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
133
164
|
console.log("close unexpected popups");
|
|
@@ -136,11 +167,20 @@ class StableBrowser {
|
|
|
136
167
|
}
|
|
137
168
|
context.pageLoading.status = true;
|
|
138
169
|
this.page = page;
|
|
170
|
+
try {
|
|
171
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
172
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
console.error("Error on dialog accept registration", error);
|
|
177
|
+
}
|
|
139
178
|
context.page = page;
|
|
140
179
|
context.pages.push(page);
|
|
141
180
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
142
181
|
registerDownloadEvent(this.page, this.world, context);
|
|
143
182
|
page.on("close", async () => {
|
|
183
|
+
// return if browser context is already closed
|
|
144
184
|
if (this.context && this.context.pages && this.context.pages.length > 1) {
|
|
145
185
|
this.context.pages.pop();
|
|
146
186
|
this.page = this.context.pages[this.context.pages.length - 1];
|
|
@@ -150,7 +190,12 @@ class StableBrowser {
|
|
|
150
190
|
console.log("Switched to page " + title);
|
|
151
191
|
}
|
|
152
192
|
catch (error) {
|
|
153
|
-
|
|
193
|
+
if (error?.message?.includes("Target page, context or browser has been closed")) {
|
|
194
|
+
// Ignore this error
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.error("Error on page close", error);
|
|
198
|
+
}
|
|
154
199
|
}
|
|
155
200
|
}
|
|
156
201
|
});
|
|
@@ -159,7 +204,12 @@ class StableBrowser {
|
|
|
159
204
|
console.log("Switch page: " + (await page.title()));
|
|
160
205
|
}
|
|
161
206
|
catch (e) {
|
|
162
|
-
|
|
207
|
+
if (e?.message?.includes("Target page, context or browser has been closed")) {
|
|
208
|
+
// Ignore this error
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this.logger.error("error on page load " + e);
|
|
212
|
+
}
|
|
163
213
|
}
|
|
164
214
|
context.pageLoading.status = false;
|
|
165
215
|
}.bind(this));
|
|
@@ -187,7 +237,9 @@ class StableBrowser {
|
|
|
187
237
|
if (newContextCreated) {
|
|
188
238
|
this.registerEventListeners(this.context);
|
|
189
239
|
await this.goto(this.context.environment.baseUrl);
|
|
190
|
-
|
|
240
|
+
if (!this.fastMode && !this.stepTags.includes("fast-mode")) {
|
|
241
|
+
await this.waitForPageLoad();
|
|
242
|
+
}
|
|
191
243
|
}
|
|
192
244
|
}
|
|
193
245
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -313,6 +365,64 @@ class StableBrowser {
|
|
|
313
365
|
await _commandFinally(state, this);
|
|
314
366
|
}
|
|
315
367
|
}
|
|
368
|
+
async goBack(options, world = null) {
|
|
369
|
+
const state = {
|
|
370
|
+
value: "",
|
|
371
|
+
world: world,
|
|
372
|
+
type: Types.GO_BACK,
|
|
373
|
+
text: `Browser navigate back`,
|
|
374
|
+
operation: "goBack",
|
|
375
|
+
log: "***** navigate back *****\n",
|
|
376
|
+
info: {},
|
|
377
|
+
locate: false,
|
|
378
|
+
scroll: false,
|
|
379
|
+
screenshot: false,
|
|
380
|
+
highlight: false,
|
|
381
|
+
};
|
|
382
|
+
try {
|
|
383
|
+
await _preCommand(state, this);
|
|
384
|
+
await this.page.goBack({
|
|
385
|
+
waitUntil: "load",
|
|
386
|
+
});
|
|
387
|
+
await _screenshot(state, this);
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
console.error("Error on goBack", error);
|
|
391
|
+
_commandError(state, error, this);
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
await _commandFinally(state, this);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
async goForward(options, world = null) {
|
|
398
|
+
const state = {
|
|
399
|
+
value: "",
|
|
400
|
+
world: world,
|
|
401
|
+
type: Types.GO_FORWARD,
|
|
402
|
+
text: `Browser navigate forward`,
|
|
403
|
+
operation: "goForward",
|
|
404
|
+
log: "***** navigate forward *****\n",
|
|
405
|
+
info: {},
|
|
406
|
+
locate: false,
|
|
407
|
+
scroll: false,
|
|
408
|
+
screenshot: false,
|
|
409
|
+
highlight: false,
|
|
410
|
+
};
|
|
411
|
+
try {
|
|
412
|
+
await _preCommand(state, this);
|
|
413
|
+
await this.page.goForward({
|
|
414
|
+
waitUntil: "load",
|
|
415
|
+
});
|
|
416
|
+
await _screenshot(state, this);
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
console.error("Error on goForward", error);
|
|
420
|
+
_commandError(state, error, this);
|
|
421
|
+
}
|
|
422
|
+
finally {
|
|
423
|
+
await _commandFinally(state, this);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
316
426
|
async _getLocator(locator, scope, _params) {
|
|
317
427
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
318
428
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -411,12 +521,6 @@ class StableBrowser {
|
|
|
411
521
|
if (!el.setAttribute) {
|
|
412
522
|
el = el.parentElement;
|
|
413
523
|
}
|
|
414
|
-
// remove any attributes start with data-blinq-id
|
|
415
|
-
// for (let i = 0; i < el.attributes.length; i++) {
|
|
416
|
-
// if (el.attributes[i].name.startsWith("data-blinq-id")) {
|
|
417
|
-
// el.removeAttribute(el.attributes[i].name);
|
|
418
|
-
// }
|
|
419
|
-
// }
|
|
420
524
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
421
525
|
return true;
|
|
422
526
|
}, [tag1, randomToken]))) {
|
|
@@ -438,14 +542,13 @@ class StableBrowser {
|
|
|
438
542
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
439
543
|
}
|
|
440
544
|
let locatorSearch = selectorHierarchy[index];
|
|
441
|
-
let originalLocatorSearch = "";
|
|
442
545
|
try {
|
|
443
|
-
|
|
444
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
546
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
445
547
|
}
|
|
446
548
|
catch (e) {
|
|
447
549
|
console.error(e);
|
|
448
550
|
}
|
|
551
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
449
552
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
450
553
|
let locator = null;
|
|
451
554
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -587,34 +690,183 @@ class StableBrowser {
|
|
|
587
690
|
}
|
|
588
691
|
return { rerun: false };
|
|
589
692
|
}
|
|
693
|
+
getFilePath() {
|
|
694
|
+
const stackFrames = errorStackParser.parse(new Error());
|
|
695
|
+
const stackFrame = stackFrames.findLast((frame) => frame.fileName && frame.fileName.endsWith(".mjs"));
|
|
696
|
+
// return stackFrame?.fileName || null;
|
|
697
|
+
const filepath = stackFrame?.fileName;
|
|
698
|
+
if (filepath) {
|
|
699
|
+
let jsonFilePath = filepath.replace(".mjs", ".json");
|
|
700
|
+
if (existsSync(jsonFilePath)) {
|
|
701
|
+
return jsonFilePath;
|
|
702
|
+
}
|
|
703
|
+
const config = this.configuration ?? {};
|
|
704
|
+
if (!config?.locatorsMetadataDir) {
|
|
705
|
+
config.locatorsMetadataDir = "features/step_definitions/locators";
|
|
706
|
+
}
|
|
707
|
+
if (config && config.locatorsMetadataDir) {
|
|
708
|
+
jsonFilePath = path.join(config.locatorsMetadataDir, path.basename(jsonFilePath));
|
|
709
|
+
}
|
|
710
|
+
if (existsSync(jsonFilePath)) {
|
|
711
|
+
return jsonFilePath;
|
|
712
|
+
}
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
getFullElementLocators(selectors, filePath) {
|
|
718
|
+
if (!filePath || !existsSync(filePath)) {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
722
|
+
try {
|
|
723
|
+
const allElements = JSON.parse(content);
|
|
724
|
+
const element_key = selectors?.element_key;
|
|
725
|
+
if (element_key && allElements[element_key]) {
|
|
726
|
+
return allElements[element_key];
|
|
727
|
+
}
|
|
728
|
+
for (const elementKey in allElements) {
|
|
729
|
+
const element = allElements[elementKey];
|
|
730
|
+
let foundStrategy = null;
|
|
731
|
+
for (const key in element) {
|
|
732
|
+
if (key === "strategy") {
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
const locators = element[key];
|
|
736
|
+
if (!locators || !locators.length) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
for (const locator of locators) {
|
|
740
|
+
delete locator.score;
|
|
741
|
+
}
|
|
742
|
+
if (JSON.stringify(locators) === JSON.stringify(selectors.locators)) {
|
|
743
|
+
foundStrategy = key;
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
if (foundStrategy) {
|
|
748
|
+
return element;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
console.error("Error parsing locators from file: " + filePath, error);
|
|
754
|
+
}
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
590
757
|
async _locate(selectors, info, _params, timeout, allowDisabled = false) {
|
|
591
758
|
if (!timeout) {
|
|
592
759
|
timeout = 30000;
|
|
593
760
|
}
|
|
761
|
+
let element = null;
|
|
762
|
+
let allStrategyLocators = null;
|
|
763
|
+
let selectedStrategy = null;
|
|
764
|
+
if (this.tryAllStrategies) {
|
|
765
|
+
allStrategyLocators = this.getFullElementLocators(selectors, this.getFilePath());
|
|
766
|
+
selectedStrategy = allStrategyLocators?.strategy;
|
|
767
|
+
}
|
|
594
768
|
for (let i = 0; i < 3; i++) {
|
|
595
769
|
info.log += "attempt " + i + ": total locators " + selectors.locators.length + "\n";
|
|
596
770
|
for (let j = 0; j < selectors.locators.length; j++) {
|
|
597
771
|
let selector = selectors.locators[j];
|
|
598
772
|
info.log += "searching for locator " + j + ":" + JSON.stringify(selector) + "\n";
|
|
599
773
|
}
|
|
600
|
-
|
|
774
|
+
if (this.tryAllStrategies && selectedStrategy) {
|
|
775
|
+
const strategyLocators = allStrategyLocators[selectedStrategy];
|
|
776
|
+
let err;
|
|
777
|
+
if (strategyLocators && strategyLocators.length) {
|
|
778
|
+
try {
|
|
779
|
+
selectors.locators = strategyLocators;
|
|
780
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
781
|
+
info.selectedStrategy = selectedStrategy;
|
|
782
|
+
info.log += "element found using strategy " + selectedStrategy + "\n";
|
|
783
|
+
}
|
|
784
|
+
catch (error) {
|
|
785
|
+
err = error;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (!element) {
|
|
789
|
+
for (const key in allStrategyLocators) {
|
|
790
|
+
if (key === "strategy" || key === selectedStrategy) {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
const strategyLocators = allStrategyLocators[key];
|
|
794
|
+
if (strategyLocators && strategyLocators.length) {
|
|
795
|
+
try {
|
|
796
|
+
info.log += "using strategy " + key + " with locators " + JSON.stringify(strategyLocators) + "\n";
|
|
797
|
+
selectors.locators = strategyLocators;
|
|
798
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
799
|
+
err = null;
|
|
800
|
+
info.selectedStrategy = key;
|
|
801
|
+
info.log += "element found using strategy " + key + "\n";
|
|
802
|
+
break;
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
err = error;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (err) {
|
|
811
|
+
throw err;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
816
|
+
}
|
|
601
817
|
if (!element.rerun) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
818
|
+
let newElementSelector = "";
|
|
819
|
+
if (this.configuration && this.configuration.stableLocatorStrategy === "csschain") {
|
|
820
|
+
const cssSelector = await element.evaluate((el) => {
|
|
821
|
+
function getCssSelector(el) {
|
|
822
|
+
if (!el || el.nodeType !== 1 || el === document.body)
|
|
823
|
+
return el.tagName.toLowerCase();
|
|
824
|
+
const parent = el.parentElement;
|
|
825
|
+
const tag = el.tagName.toLowerCase();
|
|
826
|
+
// Find the index of the element among its siblings of the same tag
|
|
827
|
+
let index = 1;
|
|
828
|
+
for (let sibling = el.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
|
|
829
|
+
if (sibling.tagName === el.tagName) {
|
|
830
|
+
index++;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// Use nth-child if necessary (i.e., if there's more than one of the same tag)
|
|
834
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === el.tagName);
|
|
835
|
+
const needsNthChild = siblings.length > 1;
|
|
836
|
+
const selector = needsNthChild ? `${tag}:nth-child(${[...parent.children].indexOf(el) + 1})` : tag;
|
|
837
|
+
return getCssSelector(parent) + " > " + selector;
|
|
838
|
+
}
|
|
839
|
+
const cssSelector = getCssSelector(el);
|
|
840
|
+
return cssSelector;
|
|
841
|
+
});
|
|
842
|
+
newElementSelector = cssSelector;
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
const randomToken = "blinq_" + Math.random().toString(36).substring(7);
|
|
846
|
+
const id = await element.evaluate((el, randomToken) => {
|
|
847
|
+
// check if the element has id attribute
|
|
848
|
+
if (el.id) {
|
|
849
|
+
return el.id;
|
|
850
|
+
}
|
|
851
|
+
el.setAttribute("id", randomToken);
|
|
852
|
+
console.log("set id=" + randomToken + " on element", el);
|
|
853
|
+
return randomToken;
|
|
854
|
+
}, randomToken);
|
|
855
|
+
newElementSelector = "#" + id;
|
|
856
|
+
// check if the id contains :
|
|
857
|
+
if (id.includes(":")) {
|
|
858
|
+
// //*[@id="radix-:r0:"]
|
|
859
|
+
newElementSelector = `//*[@id="${id}"]`;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
609
862
|
const scope = element._frame ?? element.page();
|
|
610
|
-
let newElementSelector = "[data-blinq-id-" + randomToken + "]";
|
|
611
863
|
let prefixSelector = "";
|
|
612
864
|
const frameControlSelector = " >> internal:control=enter-frame";
|
|
613
865
|
const frameSelectorIndex = element._selector.lastIndexOf(frameControlSelector);
|
|
614
866
|
if (frameSelectorIndex !== -1) {
|
|
615
867
|
// remove everything after the >> internal:control=enter-frame
|
|
616
868
|
const frameSelector = element._selector.substring(0, frameSelectorIndex);
|
|
617
|
-
prefixSelector = frameSelector + " >> internal:control=enter-frame >>";
|
|
869
|
+
prefixSelector = frameSelector + " >> internal:control=enter-frame >> ";
|
|
618
870
|
}
|
|
619
871
|
// if (element?._frame?._selector) {
|
|
620
872
|
// prefixSelector = element._frame._selector + " >> " + prefixSelector;
|
|
@@ -653,7 +905,7 @@ class StableBrowser {
|
|
|
653
905
|
break;
|
|
654
906
|
}
|
|
655
907
|
catch (error) {
|
|
656
|
-
console.error("frame not found " + frameLocator.css);
|
|
908
|
+
// console.error("frame not found " + frameLocator.css);
|
|
657
909
|
}
|
|
658
910
|
}
|
|
659
911
|
}
|
|
@@ -731,7 +983,6 @@ class StableBrowser {
|
|
|
731
983
|
let locatorsCount = 0;
|
|
732
984
|
let lazy_scroll = false;
|
|
733
985
|
//let arrayMode = Array.isArray(selectors);
|
|
734
|
-
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
735
986
|
let selectorsLocators = null;
|
|
736
987
|
selectorsLocators = selectors.locators;
|
|
737
988
|
// group selectors by priority
|
|
@@ -759,6 +1010,7 @@ class StableBrowser {
|
|
|
759
1010
|
let highPriorityOnly = true;
|
|
760
1011
|
let visibleOnly = true;
|
|
761
1012
|
while (true) {
|
|
1013
|
+
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
762
1014
|
locatorsCount = 0;
|
|
763
1015
|
let result = [];
|
|
764
1016
|
let popupResult = await this.closeUnexpectedPopups(info, _params);
|
|
@@ -874,9 +1126,13 @@ class StableBrowser {
|
|
|
874
1126
|
}
|
|
875
1127
|
}
|
|
876
1128
|
if (foundLocators.length === 1) {
|
|
1129
|
+
let box = null;
|
|
1130
|
+
if (!this.onlyFailuresScreenshot) {
|
|
1131
|
+
box = await foundLocators[0].boundingBox();
|
|
1132
|
+
}
|
|
877
1133
|
result.foundElements.push({
|
|
878
1134
|
locator: foundLocators[0],
|
|
879
|
-
box:
|
|
1135
|
+
box: box,
|
|
880
1136
|
unique: true,
|
|
881
1137
|
});
|
|
882
1138
|
result.locatorIndex = i;
|
|
@@ -1031,17 +1287,30 @@ class StableBrowser {
|
|
|
1031
1287
|
operation: "click",
|
|
1032
1288
|
log: "***** click on " + selectors.element_name + " *****\n",
|
|
1033
1289
|
};
|
|
1290
|
+
check_performance("click_all ***", this.context, true);
|
|
1034
1291
|
try {
|
|
1292
|
+
check_performance("click_preCommand", this.context, true);
|
|
1035
1293
|
await _preCommand(state, this);
|
|
1294
|
+
check_performance("click_preCommand", this.context, false);
|
|
1036
1295
|
await performAction("click", state.element, options, this, state, _params);
|
|
1037
|
-
|
|
1296
|
+
if (!this.fastMode && !this.stepTags.includes("fast-mode")) {
|
|
1297
|
+
check_performance("click_waitForPageLoad", this.context, true);
|
|
1298
|
+
await this.waitForPageLoad({ noSleep: true });
|
|
1299
|
+
check_performance("click_waitForPageLoad", this.context, false);
|
|
1300
|
+
}
|
|
1038
1301
|
return state.info;
|
|
1039
1302
|
}
|
|
1040
1303
|
catch (e) {
|
|
1041
1304
|
await _commandError(state, e, this);
|
|
1042
1305
|
}
|
|
1043
1306
|
finally {
|
|
1307
|
+
check_performance("click_commandFinally", this.context, true);
|
|
1044
1308
|
await _commandFinally(state, this);
|
|
1309
|
+
check_performance("click_commandFinally", this.context, false);
|
|
1310
|
+
check_performance("click_all ***", this.context, false);
|
|
1311
|
+
if (this.context.profile) {
|
|
1312
|
+
console.log(JSON.stringify(this.context.profile, null, 2));
|
|
1313
|
+
}
|
|
1045
1314
|
}
|
|
1046
1315
|
}
|
|
1047
1316
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1133,7 +1402,7 @@ class StableBrowser {
|
|
|
1133
1402
|
}
|
|
1134
1403
|
}
|
|
1135
1404
|
}
|
|
1136
|
-
await this.waitForPageLoad();
|
|
1405
|
+
//await this.waitForPageLoad();
|
|
1137
1406
|
return state.info;
|
|
1138
1407
|
}
|
|
1139
1408
|
catch (e) {
|
|
@@ -1159,7 +1428,7 @@ class StableBrowser {
|
|
|
1159
1428
|
await _preCommand(state, this);
|
|
1160
1429
|
await performAction("hover", state.element, options, this, state, _params);
|
|
1161
1430
|
await _screenshot(state, this);
|
|
1162
|
-
await this.waitForPageLoad();
|
|
1431
|
+
//await this.waitForPageLoad();
|
|
1163
1432
|
return state.info;
|
|
1164
1433
|
}
|
|
1165
1434
|
catch (e) {
|
|
@@ -1195,7 +1464,7 @@ class StableBrowser {
|
|
|
1195
1464
|
state.info.log += "selectOption failed, will try force" + "\n";
|
|
1196
1465
|
await state.element.selectOption(values, { timeout: 10000, force: true });
|
|
1197
1466
|
}
|
|
1198
|
-
await this.waitForPageLoad();
|
|
1467
|
+
//await this.waitForPageLoad();
|
|
1199
1468
|
return state.info;
|
|
1200
1469
|
}
|
|
1201
1470
|
catch (e) {
|
|
@@ -1426,7 +1695,9 @@ class StableBrowser {
|
|
|
1426
1695
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1427
1696
|
}
|
|
1428
1697
|
}
|
|
1698
|
+
//if (!this.fastMode) {
|
|
1429
1699
|
await _screenshot(state, this);
|
|
1700
|
+
//}
|
|
1430
1701
|
if (enter === true) {
|
|
1431
1702
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1432
1703
|
await this.page.keyboard.press("Enter");
|
|
@@ -1475,8 +1746,8 @@ class StableBrowser {
|
|
|
1475
1746
|
if (enter) {
|
|
1476
1747
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1477
1748
|
await this.page.keyboard.press("Enter");
|
|
1749
|
+
await this.waitForPageLoad();
|
|
1478
1750
|
}
|
|
1479
|
-
await this.waitForPageLoad();
|
|
1480
1751
|
return state.info;
|
|
1481
1752
|
}
|
|
1482
1753
|
catch (e) {
|
|
@@ -1768,6 +2039,11 @@ class StableBrowser {
|
|
|
1768
2039
|
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1769
2040
|
}
|
|
1770
2041
|
// highlight and screenshot
|
|
2042
|
+
try {
|
|
2043
|
+
await await highlightSnapshot(newValue, scope);
|
|
2044
|
+
await _screenshot(state, this);
|
|
2045
|
+
}
|
|
2046
|
+
catch (e) { }
|
|
1771
2047
|
return state.info;
|
|
1772
2048
|
}
|
|
1773
2049
|
catch (e) {
|
|
@@ -1926,12 +2202,7 @@ class StableBrowser {
|
|
|
1926
2202
|
}
|
|
1927
2203
|
}
|
|
1928
2204
|
getTestData(world = null) {
|
|
1929
|
-
|
|
1930
|
-
let data = {};
|
|
1931
|
-
if (fs.existsSync(dataFile)) {
|
|
1932
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1933
|
-
}
|
|
1934
|
-
return data;
|
|
2205
|
+
return _getTestData(world, this.context, this);
|
|
1935
2206
|
}
|
|
1936
2207
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1937
2208
|
// collect url/path/title
|
|
@@ -2151,6 +2422,77 @@ class StableBrowser {
|
|
|
2151
2422
|
await _commandFinally(state, this);
|
|
2152
2423
|
}
|
|
2153
2424
|
}
|
|
2425
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2426
|
+
const state = {
|
|
2427
|
+
selectors,
|
|
2428
|
+
_params,
|
|
2429
|
+
property,
|
|
2430
|
+
variable,
|
|
2431
|
+
options,
|
|
2432
|
+
world,
|
|
2433
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2434
|
+
text: `Extract property from element`,
|
|
2435
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2436
|
+
operation: "extractProperty",
|
|
2437
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2438
|
+
allowDisabled: true,
|
|
2439
|
+
};
|
|
2440
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2441
|
+
try {
|
|
2442
|
+
await _preCommand(state, this);
|
|
2443
|
+
switch (property) {
|
|
2444
|
+
case "inner_text":
|
|
2445
|
+
state.value = await state.element.innerText();
|
|
2446
|
+
break;
|
|
2447
|
+
case "href":
|
|
2448
|
+
state.value = await state.element.getAttribute("href");
|
|
2449
|
+
break;
|
|
2450
|
+
case "value":
|
|
2451
|
+
state.value = await state.element.inputValue();
|
|
2452
|
+
break;
|
|
2453
|
+
case "text":
|
|
2454
|
+
state.value = await state.element.textContent();
|
|
2455
|
+
break;
|
|
2456
|
+
default:
|
|
2457
|
+
if (property.startsWith("dataset.")) {
|
|
2458
|
+
const dataAttribute = property.substring(8);
|
|
2459
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2460
|
+
}
|
|
2461
|
+
else {
|
|
2462
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
if (options !== null) {
|
|
2466
|
+
if (options.regex && options.regex !== "") {
|
|
2467
|
+
// Construct a regex pattern from the provided string
|
|
2468
|
+
const regex = options.regex.slice(1, -1);
|
|
2469
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2470
|
+
const matches = state.value.match(regexPattern);
|
|
2471
|
+
if (matches) {
|
|
2472
|
+
let newValue = "";
|
|
2473
|
+
for (const match of matches) {
|
|
2474
|
+
newValue += match;
|
|
2475
|
+
}
|
|
2476
|
+
state.value = newValue;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2480
|
+
state.value = state.value.trim();
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
state.info.value = state.value;
|
|
2484
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2485
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2486
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2487
|
+
return state.info;
|
|
2488
|
+
}
|
|
2489
|
+
catch (e) {
|
|
2490
|
+
await _commandError(state, e, this);
|
|
2491
|
+
}
|
|
2492
|
+
finally {
|
|
2493
|
+
await _commandFinally(state, this);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2154
2496
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
2155
2497
|
const state = {
|
|
2156
2498
|
selectors,
|
|
@@ -2249,6 +2591,261 @@ class StableBrowser {
|
|
|
2249
2591
|
await _commandFinally(state, this);
|
|
2250
2592
|
}
|
|
2251
2593
|
}
|
|
2594
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2595
|
+
const state = {
|
|
2596
|
+
selectors,
|
|
2597
|
+
_params,
|
|
2598
|
+
property,
|
|
2599
|
+
value,
|
|
2600
|
+
options,
|
|
2601
|
+
world,
|
|
2602
|
+
type: Types.VERIFY_PROPERTY,
|
|
2603
|
+
highlight: true,
|
|
2604
|
+
screenshot: true,
|
|
2605
|
+
text: `Verify element property`,
|
|
2606
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2607
|
+
operation: "verifyProperty",
|
|
2608
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2609
|
+
allowDisabled: true,
|
|
2610
|
+
};
|
|
2611
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2612
|
+
let val;
|
|
2613
|
+
let expectedValue;
|
|
2614
|
+
try {
|
|
2615
|
+
await _preCommand(state, this);
|
|
2616
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2617
|
+
state.info.expectedValue = expectedValue;
|
|
2618
|
+
switch (property) {
|
|
2619
|
+
case "innerText":
|
|
2620
|
+
val = String(await state.element.innerText());
|
|
2621
|
+
break;
|
|
2622
|
+
case "text":
|
|
2623
|
+
val = String(await state.element.textContent());
|
|
2624
|
+
break;
|
|
2625
|
+
case "value":
|
|
2626
|
+
val = String(await state.element.inputValue());
|
|
2627
|
+
break;
|
|
2628
|
+
case "checked":
|
|
2629
|
+
val = String(await state.element.isChecked());
|
|
2630
|
+
break;
|
|
2631
|
+
case "disabled":
|
|
2632
|
+
val = String(await state.element.isDisabled());
|
|
2633
|
+
break;
|
|
2634
|
+
case "readOnly":
|
|
2635
|
+
const isEditable = await state.element.isEditable();
|
|
2636
|
+
val = String(!isEditable);
|
|
2637
|
+
break;
|
|
2638
|
+
case "innerHTML":
|
|
2639
|
+
val = String(await state.element.innerHTML());
|
|
2640
|
+
break;
|
|
2641
|
+
case "outerHTML":
|
|
2642
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2643
|
+
break;
|
|
2644
|
+
default:
|
|
2645
|
+
if (property.startsWith("dataset.")) {
|
|
2646
|
+
const dataAttribute = property.substring(8);
|
|
2647
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2648
|
+
}
|
|
2649
|
+
else {
|
|
2650
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
// Helper function to remove all style="" attributes
|
|
2654
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2655
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2656
|
+
};
|
|
2657
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2658
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2659
|
+
val = removeStyleAttributes(val);
|
|
2660
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2661
|
+
}
|
|
2662
|
+
state.info.value = val;
|
|
2663
|
+
let regex;
|
|
2664
|
+
state.info.value = val;
|
|
2665
|
+
const isRegex = expectedValue.startsWith("regex:");
|
|
2666
|
+
const isContains = expectedValue.startsWith("contains:");
|
|
2667
|
+
const isExact = expectedValue.startsWith("exact:");
|
|
2668
|
+
let matchPassed = false;
|
|
2669
|
+
if (isRegex) {
|
|
2670
|
+
const rawPattern = expectedValue.slice(6); // remove "regex:"
|
|
2671
|
+
const lastSlashIndex = rawPattern.lastIndexOf("/");
|
|
2672
|
+
if (rawPattern.startsWith("/") && lastSlashIndex > 0) {
|
|
2673
|
+
const patternBody = rawPattern.slice(1, lastSlashIndex).replace(/\n/g, ".*");
|
|
2674
|
+
const flags = rawPattern.slice(lastSlashIndex + 1) || "gs";
|
|
2675
|
+
const regex = new RegExp(patternBody, flags);
|
|
2676
|
+
state.info.regex = true;
|
|
2677
|
+
matchPassed = regex.test(val);
|
|
2678
|
+
}
|
|
2679
|
+
else {
|
|
2680
|
+
// Fallback: treat as literal
|
|
2681
|
+
const escapedPattern = rawPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2682
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2683
|
+
matchPassed = regex.test(val);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
else if (isContains) {
|
|
2687
|
+
const containsValue = expectedValue.slice(9); // remove "contains:"
|
|
2688
|
+
matchPassed = val.includes(containsValue);
|
|
2689
|
+
}
|
|
2690
|
+
else if (isExact) {
|
|
2691
|
+
const exactValue = expectedValue.slice(6); // remove "exact:"
|
|
2692
|
+
matchPassed = val === exactValue;
|
|
2693
|
+
}
|
|
2694
|
+
else if (property === "innerText") {
|
|
2695
|
+
// Default innerText logic
|
|
2696
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2697
|
+
const valLines = val.split("\n");
|
|
2698
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2699
|
+
matchPassed = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2700
|
+
}
|
|
2701
|
+
else {
|
|
2702
|
+
// Fallback exact or loose match
|
|
2703
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2704
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2705
|
+
matchPassed = regex.test(val);
|
|
2706
|
+
}
|
|
2707
|
+
if (!matchPassed) {
|
|
2708
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2709
|
+
state.info.failCause.assertionFailed = true;
|
|
2710
|
+
state.info.failCause.lastError = errorMessage;
|
|
2711
|
+
throw new Error(errorMessage);
|
|
2712
|
+
}
|
|
2713
|
+
return state.info;
|
|
2714
|
+
}
|
|
2715
|
+
catch (e) {
|
|
2716
|
+
await _commandError(state, e, this);
|
|
2717
|
+
}
|
|
2718
|
+
finally {
|
|
2719
|
+
await _commandFinally(state, this);
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2723
|
+
// Convert timeout from seconds to milliseconds
|
|
2724
|
+
const timeoutMs = timeout * 1000;
|
|
2725
|
+
const state = {
|
|
2726
|
+
selectors,
|
|
2727
|
+
_params,
|
|
2728
|
+
condition,
|
|
2729
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2730
|
+
options,
|
|
2731
|
+
world,
|
|
2732
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2733
|
+
highlight: true,
|
|
2734
|
+
screenshot: true,
|
|
2735
|
+
text: `Conditional wait for element`,
|
|
2736
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2737
|
+
operation: "conditionalWait",
|
|
2738
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2739
|
+
allowDisabled: true,
|
|
2740
|
+
info: {},
|
|
2741
|
+
};
|
|
2742
|
+
state.options ??= { timeout: timeoutMs };
|
|
2743
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2744
|
+
const startTime = Date.now();
|
|
2745
|
+
let conditionMet = false;
|
|
2746
|
+
let currentValue = null;
|
|
2747
|
+
let lastError = null;
|
|
2748
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2749
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2750
|
+
const elapsedTime = Date.now() - startTime;
|
|
2751
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2752
|
+
try {
|
|
2753
|
+
// Try to execute _preCommand (element location)
|
|
2754
|
+
await _preCommand(state, this);
|
|
2755
|
+
// If _preCommand succeeds, start condition checking
|
|
2756
|
+
const checkCondition = async () => {
|
|
2757
|
+
try {
|
|
2758
|
+
switch (condition.toLowerCase()) {
|
|
2759
|
+
case "checked":
|
|
2760
|
+
currentValue = await state.element.isChecked();
|
|
2761
|
+
return currentValue === true;
|
|
2762
|
+
case "unchecked":
|
|
2763
|
+
currentValue = await state.element.isChecked();
|
|
2764
|
+
return currentValue === false;
|
|
2765
|
+
case "visible":
|
|
2766
|
+
currentValue = await state.element.isVisible();
|
|
2767
|
+
return currentValue === true;
|
|
2768
|
+
case "hidden":
|
|
2769
|
+
currentValue = await state.element.isVisible();
|
|
2770
|
+
return currentValue === false;
|
|
2771
|
+
case "enabled":
|
|
2772
|
+
currentValue = await state.element.isDisabled();
|
|
2773
|
+
return currentValue === false;
|
|
2774
|
+
case "disabled":
|
|
2775
|
+
currentValue = await state.element.isDisabled();
|
|
2776
|
+
return currentValue === true;
|
|
2777
|
+
case "editable":
|
|
2778
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2779
|
+
currentValue = await state.element.isContentEditable();
|
|
2780
|
+
return currentValue === true;
|
|
2781
|
+
default:
|
|
2782
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2783
|
+
state.info.success = false;
|
|
2784
|
+
return false;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
catch (error) {
|
|
2788
|
+
// Don't throw here, just return false to continue retrying
|
|
2789
|
+
return false;
|
|
2790
|
+
}
|
|
2791
|
+
};
|
|
2792
|
+
// Inner loop for condition checking (once element is located)
|
|
2793
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2794
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2795
|
+
conditionMet = await checkCondition();
|
|
2796
|
+
if (conditionMet) {
|
|
2797
|
+
break;
|
|
2798
|
+
}
|
|
2799
|
+
// Check if we still have time for another attempt
|
|
2800
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2801
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2802
|
+
}
|
|
2803
|
+
else {
|
|
2804
|
+
break;
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
// If we got here and condition is met, break out of main loop
|
|
2808
|
+
if (conditionMet) {
|
|
2809
|
+
break;
|
|
2810
|
+
}
|
|
2811
|
+
// If condition not met but no exception, we've timed out
|
|
2812
|
+
break;
|
|
2813
|
+
}
|
|
2814
|
+
catch (e) {
|
|
2815
|
+
lastError = e;
|
|
2816
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2817
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2818
|
+
// Check if we have enough time left to retry
|
|
2819
|
+
if (timeLeft > 100) {
|
|
2820
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2821
|
+
}
|
|
2822
|
+
else {
|
|
2823
|
+
break;
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2828
|
+
state.info = {
|
|
2829
|
+
success: conditionMet,
|
|
2830
|
+
conditionMet,
|
|
2831
|
+
actualWaitTime,
|
|
2832
|
+
currentValue,
|
|
2833
|
+
lastError: lastError?.message || null,
|
|
2834
|
+
message: conditionMet
|
|
2835
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2836
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2837
|
+
};
|
|
2838
|
+
if (lastError) {
|
|
2839
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2840
|
+
}
|
|
2841
|
+
try {
|
|
2842
|
+
await _commandFinally(state, this);
|
|
2843
|
+
}
|
|
2844
|
+
catch (finallyError) {
|
|
2845
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2846
|
+
}
|
|
2847
|
+
return state.info;
|
|
2848
|
+
}
|
|
2252
2849
|
async extractEmailData(emailAddress, options, world) {
|
|
2253
2850
|
if (!emailAddress) {
|
|
2254
2851
|
throw new Error("email address is null");
|
|
@@ -2845,6 +3442,8 @@ class StableBrowser {
|
|
|
2845
3442
|
operation: "verify_text_with_relation",
|
|
2846
3443
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2847
3444
|
};
|
|
3445
|
+
const cmdStartTime = Date.now();
|
|
3446
|
+
let cmdEndTime = null;
|
|
2848
3447
|
const timeout = this._getFindElementTimeout(options);
|
|
2849
3448
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2850
3449
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2880,6 +3479,17 @@ class StableBrowser {
|
|
|
2880
3479
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2881
3480
|
continue;
|
|
2882
3481
|
}
|
|
3482
|
+
else {
|
|
3483
|
+
cmdEndTime = Date.now();
|
|
3484
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3485
|
+
if (foundAncore) {
|
|
3486
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3487
|
+
}
|
|
3488
|
+
else {
|
|
3489
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
2883
3493
|
try {
|
|
2884
3494
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2885
3495
|
foundAncore = true;
|
|
@@ -3279,6 +3889,43 @@ class StableBrowser {
|
|
|
3279
3889
|
});
|
|
3280
3890
|
}
|
|
3281
3891
|
}
|
|
3892
|
+
/**
|
|
3893
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3894
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3895
|
+
* @param options - Optional configuration object
|
|
3896
|
+
* @param world - Optional world context
|
|
3897
|
+
* @returns Promise that resolves after the specified duration
|
|
3898
|
+
*/
|
|
3899
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3900
|
+
const state = {
|
|
3901
|
+
duration,
|
|
3902
|
+
options,
|
|
3903
|
+
world,
|
|
3904
|
+
locate: false,
|
|
3905
|
+
scroll: false,
|
|
3906
|
+
screenshot: false,
|
|
3907
|
+
highlight: false,
|
|
3908
|
+
type: Types.SLEEP,
|
|
3909
|
+
text: `Sleep for ${duration} ms`,
|
|
3910
|
+
_text: `Sleep for ${duration} ms`,
|
|
3911
|
+
operation: "sleep",
|
|
3912
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3913
|
+
};
|
|
3914
|
+
try {
|
|
3915
|
+
await _preCommand(state, this);
|
|
3916
|
+
if (duration < 0) {
|
|
3917
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3918
|
+
}
|
|
3919
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3920
|
+
return state.info;
|
|
3921
|
+
}
|
|
3922
|
+
catch (e) {
|
|
3923
|
+
await _commandError(state, e, this);
|
|
3924
|
+
}
|
|
3925
|
+
finally {
|
|
3926
|
+
await _commandFinally(state, this);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3282
3929
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3283
3930
|
try {
|
|
3284
3931
|
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
@@ -3330,6 +3977,22 @@ class StableBrowser {
|
|
|
3330
3977
|
}
|
|
3331
3978
|
}
|
|
3332
3979
|
async waitForPageLoad(options = {}, world = null) {
|
|
3980
|
+
// try {
|
|
3981
|
+
// let currentPagePath = null;
|
|
3982
|
+
// currentPagePath = new URL(this.page.url()).pathname;
|
|
3983
|
+
// if (this.latestPagePath) {
|
|
3984
|
+
// // get the currect page path and compare with the latest page path
|
|
3985
|
+
// if (this.latestPagePath === currentPagePath) {
|
|
3986
|
+
// // if the page path is the same, do not wait for page load
|
|
3987
|
+
// console.log("No page change: " + currentPagePath);
|
|
3988
|
+
// return;
|
|
3989
|
+
// }
|
|
3990
|
+
// }
|
|
3991
|
+
// this.latestPagePath = currentPagePath;
|
|
3992
|
+
// } catch (e) {
|
|
3993
|
+
// console.debug("Error getting current page path: ", e);
|
|
3994
|
+
// }
|
|
3995
|
+
//console.log("Waiting for page load");
|
|
3333
3996
|
let timeout = this._getLoadTimeout(options);
|
|
3334
3997
|
const promiseArray = [];
|
|
3335
3998
|
// let waitForNetworkIdle = true;
|
|
@@ -3362,10 +4025,12 @@ class StableBrowser {
|
|
|
3362
4025
|
else if (e.label === "domcontentloaded") {
|
|
3363
4026
|
console.log("waited for the domcontent loaded timeout");
|
|
3364
4027
|
}
|
|
3365
|
-
console.log(".");
|
|
3366
4028
|
}
|
|
3367
4029
|
finally {
|
|
3368
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
4030
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
4031
|
+
if (options && !options.noSleep) {
|
|
4032
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
4033
|
+
}
|
|
3369
4034
|
({ screenshotId, screenshotPath } = await this._screenShot(options, world));
|
|
3370
4035
|
const endTime = Date.now();
|
|
3371
4036
|
_reportToWorld(world, {
|
|
@@ -3406,7 +4071,6 @@ class StableBrowser {
|
|
|
3406
4071
|
await this.page.close();
|
|
3407
4072
|
}
|
|
3408
4073
|
catch (e) {
|
|
3409
|
-
console.log(".");
|
|
3410
4074
|
await _commandError(state, e, this);
|
|
3411
4075
|
}
|
|
3412
4076
|
finally {
|
|
@@ -3420,7 +4084,7 @@ class StableBrowser {
|
|
|
3420
4084
|
}
|
|
3421
4085
|
operation = options.operation;
|
|
3422
4086
|
// validate operation is one of the supported operations
|
|
3423
|
-
if (operation != "click" && operation != "hover+click") {
|
|
4087
|
+
if (operation != "click" && operation != "hover+click" && operation != "hover") {
|
|
3424
4088
|
throw new Error("operation is not supported");
|
|
3425
4089
|
}
|
|
3426
4090
|
const state = {
|
|
@@ -3489,6 +4153,17 @@ class StableBrowser {
|
|
|
3489
4153
|
state.element = results[0];
|
|
3490
4154
|
await performAction("hover+click", state.element, options, this, state, _params);
|
|
3491
4155
|
break;
|
|
4156
|
+
case "hover":
|
|
4157
|
+
if (!options.css) {
|
|
4158
|
+
throw new Error("css is not defined");
|
|
4159
|
+
}
|
|
4160
|
+
const result1 = await findElementsInArea(options.css, cellArea, this, options);
|
|
4161
|
+
if (result1.length === 0) {
|
|
4162
|
+
throw new Error(`Element not found in cell area`);
|
|
4163
|
+
}
|
|
4164
|
+
state.element = result1[0];
|
|
4165
|
+
await performAction("hover", state.element, options, this, state, _params);
|
|
4166
|
+
break;
|
|
3492
4167
|
default:
|
|
3493
4168
|
throw new Error("operation is not supported");
|
|
3494
4169
|
}
|
|
@@ -3521,7 +4196,6 @@ class StableBrowser {
|
|
|
3521
4196
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3522
4197
|
}
|
|
3523
4198
|
catch (e) {
|
|
3524
|
-
console.log(".");
|
|
3525
4199
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3526
4200
|
}
|
|
3527
4201
|
finally {
|
|
@@ -3559,7 +4233,6 @@ class StableBrowser {
|
|
|
3559
4233
|
await this.page.reload();
|
|
3560
4234
|
}
|
|
3561
4235
|
catch (e) {
|
|
3562
|
-
console.log(".");
|
|
3563
4236
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3564
4237
|
}
|
|
3565
4238
|
finally {
|
|
@@ -3603,6 +4276,10 @@ class StableBrowser {
|
|
|
3603
4276
|
}
|
|
3604
4277
|
}
|
|
3605
4278
|
async beforeScenario(world, scenario) {
|
|
4279
|
+
if (world && world.attach) {
|
|
4280
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4281
|
+
}
|
|
4282
|
+
this.context.loadedRoutes = null;
|
|
3606
4283
|
this.beforeScenarioCalled = true;
|
|
3607
4284
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
3608
4285
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -3626,14 +4303,16 @@ class StableBrowser {
|
|
|
3626
4303
|
envName = this.context.environment.name;
|
|
3627
4304
|
}
|
|
3628
4305
|
if (!process.env.TEMP_RUN) {
|
|
3629
|
-
await getTestData(envName, world, undefined, this.featureName, this.scenarioName);
|
|
4306
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
3630
4307
|
}
|
|
3631
4308
|
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3632
4309
|
}
|
|
3633
4310
|
async afterScenario(world, scenario) { }
|
|
3634
4311
|
async beforeStep(world, step) {
|
|
4312
|
+
this.stepTags = [];
|
|
3635
4313
|
if (!this.beforeScenarioCalled) {
|
|
3636
4314
|
this.beforeScenario(world, step);
|
|
4315
|
+
this.context.loadedRoutes = null;
|
|
3637
4316
|
}
|
|
3638
4317
|
if (this.stepIndex === undefined) {
|
|
3639
4318
|
this.stepIndex = 0;
|
|
@@ -3643,7 +4322,12 @@ class StableBrowser {
|
|
|
3643
4322
|
}
|
|
3644
4323
|
if (step && step.pickleStep && step.pickleStep.text) {
|
|
3645
4324
|
this.stepName = step.pickleStep.text;
|
|
3646
|
-
|
|
4325
|
+
let printableStepName = this.stepName;
|
|
4326
|
+
// take the printableStepName and replace quated value with \x1b[33m and \x1b[0m
|
|
4327
|
+
printableStepName = printableStepName.replace(/"([^"]*)"/g, (match, p1) => {
|
|
4328
|
+
return `\x1b[33m"${p1}"\x1b[0m`;
|
|
4329
|
+
});
|
|
4330
|
+
this.logger.info("\x1b[38;5;208mstep:\x1b[0m " + printableStepName);
|
|
3647
4331
|
}
|
|
3648
4332
|
else if (step && step.text) {
|
|
3649
4333
|
this.stepName = step.text;
|
|
@@ -3658,13 +4342,22 @@ class StableBrowser {
|
|
|
3658
4342
|
}
|
|
3659
4343
|
if (this.initSnapshotTaken === false) {
|
|
3660
4344
|
this.initSnapshotTaken = true;
|
|
3661
|
-
if (world &&
|
|
4345
|
+
if (world &&
|
|
4346
|
+
world.attach &&
|
|
4347
|
+
!process.env.DISABLE_SNAPSHOT &&
|
|
4348
|
+
(!this.fastMode || this.stepTags.includes("fast-mode"))) {
|
|
3662
4349
|
const snapshot = await this.getAriaSnapshot();
|
|
3663
4350
|
if (snapshot) {
|
|
3664
4351
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3665
4352
|
}
|
|
3666
4353
|
}
|
|
3667
4354
|
}
|
|
4355
|
+
this.context.routeResults = null;
|
|
4356
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4357
|
+
networkBeforeStep(this.stepName);
|
|
4358
|
+
}
|
|
4359
|
+
setStepTags(tags) {
|
|
4360
|
+
this.stepTags = tags;
|
|
3668
4361
|
}
|
|
3669
4362
|
async getAriaSnapshot() {
|
|
3670
4363
|
try {
|
|
@@ -3684,12 +4377,18 @@ class StableBrowser {
|
|
|
3684
4377
|
try {
|
|
3685
4378
|
// Ensure frame is attached and has body
|
|
3686
4379
|
const body = frame.locator("body");
|
|
3687
|
-
await body.waitFor({ timeout:
|
|
4380
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
3688
4381
|
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4382
|
+
if (!snapshot) {
|
|
4383
|
+
continue;
|
|
4384
|
+
}
|
|
3689
4385
|
content.push(`- frame: ${i}`);
|
|
3690
4386
|
content.push(snapshot);
|
|
3691
4387
|
}
|
|
3692
|
-
catch (innerErr) {
|
|
4388
|
+
catch (innerErr) {
|
|
4389
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4390
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4391
|
+
}
|
|
3693
4392
|
}
|
|
3694
4393
|
return content.join("\n");
|
|
3695
4394
|
}
|
|
@@ -3761,13 +4460,23 @@ class StableBrowser {
|
|
|
3761
4460
|
if (this.context) {
|
|
3762
4461
|
this.context.examplesRow = null;
|
|
3763
4462
|
}
|
|
3764
|
-
if (world &&
|
|
4463
|
+
if (world &&
|
|
4464
|
+
world.attach &&
|
|
4465
|
+
!process.env.DISABLE_SNAPSHOT &&
|
|
4466
|
+
!this.fastMode &&
|
|
4467
|
+
!this.stepTags.includes("fast-mode")) {
|
|
3765
4468
|
const snapshot = await this.getAriaSnapshot();
|
|
3766
4469
|
if (snapshot) {
|
|
3767
4470
|
const obj = {};
|
|
3768
4471
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3769
4472
|
}
|
|
3770
4473
|
}
|
|
4474
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4475
|
+
if (this.context.routeResults) {
|
|
4476
|
+
if (world && world.attach) {
|
|
4477
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4478
|
+
}
|
|
4479
|
+
}
|
|
3771
4480
|
if (!process.env.TEMP_RUN) {
|
|
3772
4481
|
const state = {
|
|
3773
4482
|
world,
|
|
@@ -3791,6 +4500,13 @@ class StableBrowser {
|
|
|
3791
4500
|
await _commandFinally(state, this);
|
|
3792
4501
|
}
|
|
3793
4502
|
}
|
|
4503
|
+
networkAfterStep(this.stepName);
|
|
4504
|
+
if (process.env.TEMP_RUN === "true") {
|
|
4505
|
+
// Put a sleep for some time to allow the browser to finish processing
|
|
4506
|
+
if (!this.stepTags.includes("fast-mode")) {
|
|
4507
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
3794
4510
|
}
|
|
3795
4511
|
}
|
|
3796
4512
|
function createTimedPromise(promise, label) {
|