automation_model 1.0.688-dev → 1.0.688-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/analyze_helper.js.map +1 -1
- package/lib/api.d.ts +0 -1
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +4 -2
- package/lib/auto_page.js +122 -28
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +36 -10
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.d.ts +1 -0
- package/lib/bruno.js +120 -21
- package/lib/bruno.js.map +1 -1
- package/lib/command_common.d.ts +1 -1
- package/lib/command_common.js +18 -1
- package/lib/command_common.js.map +1 -1
- package/lib/date_time.js.map +1 -1
- package/lib/drawRect.js.map +1 -1
- package/lib/environment.d.ts +1 -0
- package/lib/environment.js +1 -0
- package/lib/environment.js.map +1 -1
- package/lib/error-messages.js.map +1 -1
- package/lib/file_checker.d.ts +1 -0
- package/lib/file_checker.js +165 -0
- package/lib/file_checker.js.map +1 -0
- package/lib/find_function.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/init_browser.js +4 -4
- package/lib/init_browser.js.map +1 -1
- package/lib/locate_element.js.map +1 -1
- package/lib/locator.d.ts +1 -0
- package/lib/locator.js +10 -3
- package/lib/locator.js.map +1 -1
- package/lib/locator_log.js.map +1 -1
- package/lib/network.d.ts +2 -0
- package/lib/network.js +227 -4
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +21 -0
- package/lib/route.js +390 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +3 -3
- package/lib/snapshot_validation.d.ts +37 -0
- package/lib/snapshot_validation.js +357 -0
- package/lib/snapshot_validation.js.map +1 -0
- package/lib/stable_browser.d.ts +61 -25
- package/lib/stable_browser.js +1022 -198
- 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_analyze.js.map +1 -1
- 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 -2
- package/lib/utils.js +78 -59
- package/lib/utils.js.map +1 -1
- package/package.json +14 -8
package/lib/stable_browser.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getDateTimeValue } from "./date_time.js";
|
|
|
10
10
|
import drawRectangle from "./drawRect.js";
|
|
11
11
|
//import { closeUnexpectedPopups } from "./popups.js";
|
|
12
12
|
import { getTableCells, getTableData } from "./table_analyze.js";
|
|
13
|
-
import { _convertToRegexQuery, _copyContext, _fixLocatorUsingParams, _fixUsingParams, _getServerUrl, extractStepExampleParameters, KEYBOARD_EVENTS, maskValue, replaceWithLocalTestData, scrollPageToLoadLazyElements, unEscapeString, _getDataFile, testForRegex, performAction, } from "./utils.js";
|
|
13
|
+
import { _convertToRegexQuery, _copyContext, _fixLocatorUsingParams, _fixUsingParams, _getServerUrl, extractStepExampleParameters, KEYBOARD_EVENTS, maskValue, replaceWithLocalTestData, scrollPageToLoadLazyElements, unEscapeString, _getDataFile, testForRegex, performAction, _getTestData, } from "./utils.js";
|
|
14
14
|
import csv from "csv-parser";
|
|
15
15
|
import { Readable } from "node:stream";
|
|
16
16
|
import readline from "readline";
|
|
@@ -19,27 +19,33 @@ import { getTestData } from "./auto_page.js";
|
|
|
19
19
|
import { locate_element } from "./locate_element.js";
|
|
20
20
|
import { randomUUID } from "crypto";
|
|
21
21
|
import { _commandError, _commandFinally, _preCommand, _validateSelectors, _screenshot, _reportToWorld, } from "./command_common.js";
|
|
22
|
-
import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
22
|
+
import { networkAfterStep, networkBeforeStep, registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
23
23
|
import { LocatorLog } from "./locator_log.js";
|
|
24
24
|
import axios from "axios";
|
|
25
25
|
import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
26
|
+
import { highlightSnapshot, snapshotValidation } from "./snapshot_validation.js";
|
|
27
|
+
import { loadBrunoParams } from "./bruno.js";
|
|
28
|
+
import { registerAfterStepRoutes, registerBeforeStepRoutes } from "./route.js";
|
|
26
29
|
export const Types = {
|
|
27
30
|
CLICK: "click_element",
|
|
28
31
|
WAIT_ELEMENT: "wait_element",
|
|
29
32
|
NAVIGATE: "navigate",
|
|
33
|
+
GO_BACK: "go_back",
|
|
34
|
+
GO_FORWARD: "go_forward",
|
|
30
35
|
FILL: "fill_element",
|
|
31
|
-
EXECUTE: "execute_page_method",
|
|
32
|
-
OPEN: "open_environment",
|
|
36
|
+
EXECUTE: "execute_page_method", //
|
|
37
|
+
OPEN: "open_environment", //
|
|
33
38
|
COMPLETE: "step_complete",
|
|
34
39
|
ASK: "information_needed",
|
|
35
|
-
GET_PAGE_STATUS: "get_page_status",
|
|
36
|
-
CLICK_ROW_ACTION: "click_row_action",
|
|
40
|
+
GET_PAGE_STATUS: "get_page_status", ///
|
|
41
|
+
CLICK_ROW_ACTION: "click_row_action", //
|
|
37
42
|
VERIFY_ELEMENT_CONTAINS_TEXT: "verify_element_contains_text",
|
|
38
43
|
VERIFY_PAGE_CONTAINS_TEXT: "verify_page_contains_text",
|
|
39
44
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
40
45
|
ANALYZE_TABLE: "analyze_table",
|
|
41
|
-
SELECT: "select_combobox",
|
|
46
|
+
SELECT: "select_combobox", //
|
|
42
47
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
48
|
+
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
43
49
|
TYPE_PRESS: "type_press",
|
|
44
50
|
PRESS: "press_key",
|
|
45
51
|
HOVER: "hover_element",
|
|
@@ -57,6 +63,13 @@ export const Types = {
|
|
|
57
63
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
58
64
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
59
65
|
BRUNO: "bruno",
|
|
66
|
+
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
67
|
+
SET_INPUT_FILES: "set_input_files",
|
|
68
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
69
|
+
REPORT_COMMAND: "report_command",
|
|
70
|
+
STEP_COMPLETE: "step_complete",
|
|
71
|
+
SLEEP: "sleep",
|
|
72
|
+
CONDITIONAL_WAIT: "conditional_wait",
|
|
60
73
|
};
|
|
61
74
|
export const apps = {};
|
|
62
75
|
const formatElementName = (elementName) => {
|
|
@@ -68,6 +81,7 @@ class StableBrowser {
|
|
|
68
81
|
logger;
|
|
69
82
|
context;
|
|
70
83
|
world;
|
|
84
|
+
fastMode;
|
|
71
85
|
project_path = null;
|
|
72
86
|
webLogFile = null;
|
|
73
87
|
networkLogger = null;
|
|
@@ -76,12 +90,14 @@ class StableBrowser {
|
|
|
76
90
|
tags = null;
|
|
77
91
|
isRecording = false;
|
|
78
92
|
initSnapshotTaken = false;
|
|
79
|
-
|
|
93
|
+
abortedExecution = false;
|
|
94
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
80
95
|
this.browser = browser;
|
|
81
96
|
this.page = page;
|
|
82
97
|
this.logger = logger;
|
|
83
98
|
this.context = context;
|
|
84
99
|
this.world = world;
|
|
100
|
+
this.fastMode = fastMode;
|
|
85
101
|
if (!this.logger) {
|
|
86
102
|
this.logger = console;
|
|
87
103
|
}
|
|
@@ -110,6 +126,19 @@ class StableBrowser {
|
|
|
110
126
|
context.pages = [this.page];
|
|
111
127
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
112
128
|
this.world = world;
|
|
129
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
130
|
+
this.fastMode = true;
|
|
131
|
+
}
|
|
132
|
+
if (process.env.FAST_MODE === "true") {
|
|
133
|
+
// console.log("Fast mode enabled from environment variable");
|
|
134
|
+
this.fastMode = true;
|
|
135
|
+
}
|
|
136
|
+
if (process.env.FAST_MODE === "false") {
|
|
137
|
+
this.fastMode = false;
|
|
138
|
+
}
|
|
139
|
+
if (this.context) {
|
|
140
|
+
this.context.fastMode = this.fastMode;
|
|
141
|
+
}
|
|
113
142
|
this.registerEventListeners(this.context);
|
|
114
143
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
115
144
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -120,6 +149,9 @@ class StableBrowser {
|
|
|
120
149
|
if (!context.pageLoading) {
|
|
121
150
|
context.pageLoading = { status: false };
|
|
122
151
|
}
|
|
152
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
153
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
154
|
+
}
|
|
123
155
|
context.playContext.on("page", async function (page) {
|
|
124
156
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
125
157
|
console.log("close unexpected popups");
|
|
@@ -128,6 +160,14 @@ class StableBrowser {
|
|
|
128
160
|
}
|
|
129
161
|
context.pageLoading.status = true;
|
|
130
162
|
this.page = page;
|
|
163
|
+
try {
|
|
164
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
165
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.error("Error on dialog accept registration", error);
|
|
170
|
+
}
|
|
131
171
|
context.page = page;
|
|
132
172
|
context.pages.push(page);
|
|
133
173
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -179,7 +219,9 @@ class StableBrowser {
|
|
|
179
219
|
if (newContextCreated) {
|
|
180
220
|
this.registerEventListeners(this.context);
|
|
181
221
|
await this.goto(this.context.environment.baseUrl);
|
|
182
|
-
|
|
222
|
+
if (!this.fastMode) {
|
|
223
|
+
await this.waitForPageLoad();
|
|
224
|
+
}
|
|
183
225
|
}
|
|
184
226
|
}
|
|
185
227
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -273,6 +315,7 @@ class StableBrowser {
|
|
|
273
315
|
if (!url) {
|
|
274
316
|
throw new Error("url is null, verify that the environment file is correct");
|
|
275
317
|
}
|
|
318
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
276
319
|
if (!url.startsWith("http")) {
|
|
277
320
|
url = "https://" + url;
|
|
278
321
|
}
|
|
@@ -304,6 +347,64 @@ class StableBrowser {
|
|
|
304
347
|
await _commandFinally(state, this);
|
|
305
348
|
}
|
|
306
349
|
}
|
|
350
|
+
async goBack(options, world = null) {
|
|
351
|
+
const state = {
|
|
352
|
+
value: "",
|
|
353
|
+
world: world,
|
|
354
|
+
type: Types.GO_BACK,
|
|
355
|
+
text: `Browser navigate back`,
|
|
356
|
+
operation: "goBack",
|
|
357
|
+
log: "***** navigate back *****\n",
|
|
358
|
+
info: {},
|
|
359
|
+
locate: false,
|
|
360
|
+
scroll: false,
|
|
361
|
+
screenshot: false,
|
|
362
|
+
highlight: false,
|
|
363
|
+
};
|
|
364
|
+
try {
|
|
365
|
+
await _preCommand(state, this);
|
|
366
|
+
await this.page.goBack({
|
|
367
|
+
waitUntil: "load",
|
|
368
|
+
});
|
|
369
|
+
await _screenshot(state, this);
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
console.error("Error on goBack", error);
|
|
373
|
+
_commandError(state, error, this);
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
await _commandFinally(state, this);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async goForward(options, world = null) {
|
|
380
|
+
const state = {
|
|
381
|
+
value: "",
|
|
382
|
+
world: world,
|
|
383
|
+
type: Types.GO_FORWARD,
|
|
384
|
+
text: `Browser navigate forward`,
|
|
385
|
+
operation: "goForward",
|
|
386
|
+
log: "***** navigate forward *****\n",
|
|
387
|
+
info: {},
|
|
388
|
+
locate: false,
|
|
389
|
+
scroll: false,
|
|
390
|
+
screenshot: false,
|
|
391
|
+
highlight: false,
|
|
392
|
+
};
|
|
393
|
+
try {
|
|
394
|
+
await _preCommand(state, this);
|
|
395
|
+
await this.page.goForward({
|
|
396
|
+
waitUntil: "load",
|
|
397
|
+
});
|
|
398
|
+
await _screenshot(state, this);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
console.error("Error on goForward", error);
|
|
402
|
+
_commandError(state, error, this);
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
await _commandFinally(state, this);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
307
408
|
async _getLocator(locator, scope, _params) {
|
|
308
409
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
309
410
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -417,7 +518,7 @@ class StableBrowser {
|
|
|
417
518
|
}
|
|
418
519
|
return { elementCount: tagCount, randomToken };
|
|
419
520
|
}
|
|
420
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
521
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
421
522
|
if (!info) {
|
|
422
523
|
info = {};
|
|
423
524
|
}
|
|
@@ -429,14 +530,13 @@ class StableBrowser {
|
|
|
429
530
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
430
531
|
}
|
|
431
532
|
let locatorSearch = selectorHierarchy[index];
|
|
432
|
-
let originalLocatorSearch = "";
|
|
433
533
|
try {
|
|
434
|
-
|
|
435
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
534
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
436
535
|
}
|
|
437
536
|
catch (e) {
|
|
438
537
|
console.error(e);
|
|
439
538
|
}
|
|
539
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
440
540
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
441
541
|
let locator = null;
|
|
442
542
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -484,7 +584,7 @@ class StableBrowser {
|
|
|
484
584
|
}
|
|
485
585
|
return;
|
|
486
586
|
}
|
|
487
|
-
if (info.locatorLog && count === 0) {
|
|
587
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
488
588
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
489
589
|
}
|
|
490
590
|
for (let j = 0; j < count; j++) {
|
|
@@ -499,7 +599,7 @@ class StableBrowser {
|
|
|
499
599
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
500
600
|
}
|
|
501
601
|
}
|
|
502
|
-
else {
|
|
602
|
+
else if (logErrors) {
|
|
503
603
|
info.failCause.visible = visible;
|
|
504
604
|
info.failCause.enabled = enabled;
|
|
505
605
|
if (!info.printMessages) {
|
|
@@ -591,7 +691,7 @@ class StableBrowser {
|
|
|
591
691
|
let element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
592
692
|
if (!element.rerun) {
|
|
593
693
|
const randomToken = Math.random().toString(36).substring(7);
|
|
594
|
-
element.evaluate((el, randomToken) => {
|
|
694
|
+
await element.evaluate((el, randomToken) => {
|
|
595
695
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
596
696
|
}, randomToken);
|
|
597
697
|
// if (element._frame) {
|
|
@@ -644,7 +744,7 @@ class StableBrowser {
|
|
|
644
744
|
break;
|
|
645
745
|
}
|
|
646
746
|
catch (error) {
|
|
647
|
-
console.error("frame not found " + frameLocator.css);
|
|
747
|
+
// console.error("frame not found " + frameLocator.css);
|
|
648
748
|
}
|
|
649
749
|
}
|
|
650
750
|
}
|
|
@@ -840,7 +940,7 @@ class StableBrowser {
|
|
|
840
940
|
}
|
|
841
941
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
842
942
|
}
|
|
843
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
943
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
844
944
|
let foundElements = [];
|
|
845
945
|
const result = {
|
|
846
946
|
foundElements: foundElements,
|
|
@@ -859,7 +959,9 @@ class StableBrowser {
|
|
|
859
959
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
860
960
|
}
|
|
861
961
|
catch (e) {
|
|
862
|
-
|
|
962
|
+
if (logErrors) {
|
|
963
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
964
|
+
}
|
|
863
965
|
}
|
|
864
966
|
}
|
|
865
967
|
if (foundLocators.length === 1) {
|
|
@@ -900,7 +1002,7 @@ class StableBrowser {
|
|
|
900
1002
|
});
|
|
901
1003
|
result.locatorIndex = i;
|
|
902
1004
|
}
|
|
903
|
-
else {
|
|
1005
|
+
else if (logErrors) {
|
|
904
1006
|
info.failCause.foundMultiple = true;
|
|
905
1007
|
if (info.locatorLog) {
|
|
906
1008
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -1023,7 +1125,9 @@ class StableBrowser {
|
|
|
1023
1125
|
try {
|
|
1024
1126
|
await _preCommand(state, this);
|
|
1025
1127
|
await performAction("click", state.element, options, this, state, _params);
|
|
1026
|
-
|
|
1128
|
+
if (!this.fastMode) {
|
|
1129
|
+
await this.waitForPageLoad();
|
|
1130
|
+
}
|
|
1027
1131
|
return state.info;
|
|
1028
1132
|
}
|
|
1029
1133
|
catch (e) {
|
|
@@ -1086,7 +1190,7 @@ class StableBrowser {
|
|
|
1086
1190
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1087
1191
|
// console.log(`Highlighting while running from recorder`);
|
|
1088
1192
|
await this._highlightElements(state.element);
|
|
1089
|
-
await state.element.setChecked(checked);
|
|
1193
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1090
1194
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1091
1195
|
// await this._unHighlightElements(element);
|
|
1092
1196
|
// }
|
|
@@ -1098,11 +1202,28 @@ class StableBrowser {
|
|
|
1098
1202
|
this.logger.info("element did not change its state, ignoring...");
|
|
1099
1203
|
}
|
|
1100
1204
|
else {
|
|
1205
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1101
1206
|
//await this.closeUnexpectedPopups();
|
|
1102
1207
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1103
|
-
state.
|
|
1104
|
-
|
|
1105
|
-
|
|
1208
|
+
state.element_found = false;
|
|
1209
|
+
try {
|
|
1210
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1211
|
+
state.element_found = true;
|
|
1212
|
+
// check the check state
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
// element dismissed
|
|
1216
|
+
}
|
|
1217
|
+
if (state.element_found) {
|
|
1218
|
+
const isChecked = await state.element.isChecked();
|
|
1219
|
+
if (isChecked !== checked) {
|
|
1220
|
+
// perform click
|
|
1221
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1222
|
+
}
|
|
1223
|
+
else {
|
|
1224
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1106
1227
|
}
|
|
1107
1228
|
}
|
|
1108
1229
|
await this.waitForPageLoad();
|
|
@@ -1398,7 +1519,9 @@ class StableBrowser {
|
|
|
1398
1519
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1399
1520
|
}
|
|
1400
1521
|
}
|
|
1522
|
+
//if (!this.fastMode) {
|
|
1401
1523
|
await _screenshot(state, this);
|
|
1524
|
+
//}
|
|
1402
1525
|
if (enter === true) {
|
|
1403
1526
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1404
1527
|
await this.page.keyboard.press("Enter");
|
|
@@ -1458,6 +1581,41 @@ class StableBrowser {
|
|
|
1458
1581
|
await _commandFinally(state, this);
|
|
1459
1582
|
}
|
|
1460
1583
|
}
|
|
1584
|
+
async setInputFiles(selectors, files, _params = null, options = {}, world = null) {
|
|
1585
|
+
const state = {
|
|
1586
|
+
selectors,
|
|
1587
|
+
_params,
|
|
1588
|
+
files,
|
|
1589
|
+
value: '"' + files.join('", "') + '"',
|
|
1590
|
+
options,
|
|
1591
|
+
world,
|
|
1592
|
+
type: Types.SET_INPUT_FILES,
|
|
1593
|
+
text: `Set input files`,
|
|
1594
|
+
_text: `Set input files on ${selectors.element_name}`,
|
|
1595
|
+
operation: "setInputFiles",
|
|
1596
|
+
log: "***** set input files " + selectors.element_name + " *****\n",
|
|
1597
|
+
};
|
|
1598
|
+
const uploadsFolder = this.configuration.uploadsFolder ?? "data/uploads";
|
|
1599
|
+
try {
|
|
1600
|
+
await _preCommand(state, this);
|
|
1601
|
+
for (let i = 0; i < files.length; i++) {
|
|
1602
|
+
const file = files[i];
|
|
1603
|
+
const filePath = path.join(uploadsFolder, file);
|
|
1604
|
+
if (!fs.existsSync(filePath)) {
|
|
1605
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1606
|
+
}
|
|
1607
|
+
state.files[i] = filePath;
|
|
1608
|
+
}
|
|
1609
|
+
await state.element.setInputFiles(files);
|
|
1610
|
+
return state.info;
|
|
1611
|
+
}
|
|
1612
|
+
catch (e) {
|
|
1613
|
+
await _commandError(state, e, this);
|
|
1614
|
+
}
|
|
1615
|
+
finally {
|
|
1616
|
+
await _commandFinally(state, this);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1461
1619
|
async getText(selectors, _params = null, options = {}, info = {}, world = null) {
|
|
1462
1620
|
return await this._getText(selectors, 0, _params, options, info, world);
|
|
1463
1621
|
}
|
|
@@ -1651,6 +1809,83 @@ class StableBrowser {
|
|
|
1651
1809
|
await _commandFinally(state, this);
|
|
1652
1810
|
}
|
|
1653
1811
|
}
|
|
1812
|
+
async snapshotValidation(frameSelectors, referanceSnapshot, _params = null, options = {}, world = null) {
|
|
1813
|
+
const timeout = this._getFindElementTimeout(options);
|
|
1814
|
+
const startTime = Date.now();
|
|
1815
|
+
const state = {
|
|
1816
|
+
_params,
|
|
1817
|
+
value: referanceSnapshot,
|
|
1818
|
+
options,
|
|
1819
|
+
world,
|
|
1820
|
+
locate: false,
|
|
1821
|
+
scroll: false,
|
|
1822
|
+
screenshot: true,
|
|
1823
|
+
highlight: false,
|
|
1824
|
+
type: Types.SNAPSHOT_VALIDATION,
|
|
1825
|
+
text: `verify snapshot: ${referanceSnapshot}`,
|
|
1826
|
+
operation: "snapshotValidation",
|
|
1827
|
+
log: "***** verify snapshot *****\n",
|
|
1828
|
+
};
|
|
1829
|
+
if (!referanceSnapshot) {
|
|
1830
|
+
throw new Error("referanceSnapshot is null");
|
|
1831
|
+
}
|
|
1832
|
+
let text = null;
|
|
1833
|
+
if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"))) {
|
|
1834
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"), "utf8");
|
|
1835
|
+
}
|
|
1836
|
+
else if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"))) {
|
|
1837
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"), "utf8");
|
|
1838
|
+
}
|
|
1839
|
+
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1840
|
+
text = referanceSnapshot.substring(5);
|
|
1841
|
+
}
|
|
1842
|
+
else {
|
|
1843
|
+
throw new Error("referenceSnapshot file not found: " + referanceSnapshot);
|
|
1844
|
+
}
|
|
1845
|
+
state.text = text;
|
|
1846
|
+
const newValue = await this._replaceWithLocalData(text, world);
|
|
1847
|
+
await _preCommand(state, this);
|
|
1848
|
+
let foundObj = null;
|
|
1849
|
+
try {
|
|
1850
|
+
let matchResult = null;
|
|
1851
|
+
while (Date.now() - startTime < timeout) {
|
|
1852
|
+
try {
|
|
1853
|
+
let scope = null;
|
|
1854
|
+
if (!frameSelectors) {
|
|
1855
|
+
scope = this.page;
|
|
1856
|
+
}
|
|
1857
|
+
else {
|
|
1858
|
+
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1859
|
+
}
|
|
1860
|
+
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
1861
|
+
matchResult = snapshotValidation(snapshot, newValue, referanceSnapshot);
|
|
1862
|
+
if (matchResult.errorLine !== -1) {
|
|
1863
|
+
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1864
|
+
}
|
|
1865
|
+
// highlight and screenshot
|
|
1866
|
+
try {
|
|
1867
|
+
await await highlightSnapshot(newValue, scope);
|
|
1868
|
+
await _screenshot(state, this);
|
|
1869
|
+
}
|
|
1870
|
+
catch (e) { }
|
|
1871
|
+
return state.info;
|
|
1872
|
+
}
|
|
1873
|
+
catch (e) {
|
|
1874
|
+
// Log error but continue retrying until timeout is reached
|
|
1875
|
+
//this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
1876
|
+
}
|
|
1877
|
+
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 1 second before retrying
|
|
1878
|
+
}
|
|
1879
|
+
throw new Error("No snapshot match " + matchResult?.errorLineText);
|
|
1880
|
+
}
|
|
1881
|
+
catch (e) {
|
|
1882
|
+
await _commandError(state, e, this);
|
|
1883
|
+
throw e;
|
|
1884
|
+
}
|
|
1885
|
+
finally {
|
|
1886
|
+
await _commandFinally(state, this);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1654
1889
|
async waitForUserInput(message, world = null) {
|
|
1655
1890
|
if (!message) {
|
|
1656
1891
|
message = "# Wait for user input. Press any key to continue";
|
|
@@ -1791,12 +2026,7 @@ class StableBrowser {
|
|
|
1791
2026
|
}
|
|
1792
2027
|
}
|
|
1793
2028
|
getTestData(world = null) {
|
|
1794
|
-
|
|
1795
|
-
let data = {};
|
|
1796
|
-
if (fs.existsSync(dataFile)) {
|
|
1797
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1798
|
-
}
|
|
1799
|
-
return data;
|
|
2029
|
+
return _getTestData(world, this.context, this);
|
|
1800
2030
|
}
|
|
1801
2031
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1802
2032
|
// collect url/path/title
|
|
@@ -1985,6 +2215,95 @@ class StableBrowser {
|
|
|
1985
2215
|
state.value = await state.element.getAttribute(attribute);
|
|
1986
2216
|
break;
|
|
1987
2217
|
}
|
|
2218
|
+
if (options !== null) {
|
|
2219
|
+
if (options.regex && options.regex !== "") {
|
|
2220
|
+
// Construct a regex pattern from the provided string
|
|
2221
|
+
const regex = options.regex.slice(1, -1);
|
|
2222
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2223
|
+
const matches = state.value.match(regexPattern);
|
|
2224
|
+
if (matches) {
|
|
2225
|
+
let newValue = "";
|
|
2226
|
+
for (const match of matches) {
|
|
2227
|
+
newValue += match;
|
|
2228
|
+
}
|
|
2229
|
+
state.value = newValue;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2233
|
+
state.value = state.value.trim();
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
state.info.value = state.value;
|
|
2237
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2238
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2239
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2240
|
+
return state.info;
|
|
2241
|
+
}
|
|
2242
|
+
catch (e) {
|
|
2243
|
+
await _commandError(state, e, this);
|
|
2244
|
+
}
|
|
2245
|
+
finally {
|
|
2246
|
+
await _commandFinally(state, this);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2250
|
+
const state = {
|
|
2251
|
+
selectors,
|
|
2252
|
+
_params,
|
|
2253
|
+
property,
|
|
2254
|
+
variable,
|
|
2255
|
+
options,
|
|
2256
|
+
world,
|
|
2257
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2258
|
+
text: `Extract property from element`,
|
|
2259
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2260
|
+
operation: "extractProperty",
|
|
2261
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2262
|
+
allowDisabled: true,
|
|
2263
|
+
};
|
|
2264
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2265
|
+
try {
|
|
2266
|
+
await _preCommand(state, this);
|
|
2267
|
+
switch (property) {
|
|
2268
|
+
case "inner_text":
|
|
2269
|
+
state.value = await state.element.innerText();
|
|
2270
|
+
break;
|
|
2271
|
+
case "href":
|
|
2272
|
+
state.value = await state.element.getAttribute("href");
|
|
2273
|
+
break;
|
|
2274
|
+
case "value":
|
|
2275
|
+
state.value = await state.element.inputValue();
|
|
2276
|
+
break;
|
|
2277
|
+
case "text":
|
|
2278
|
+
state.value = await state.element.textContent();
|
|
2279
|
+
break;
|
|
2280
|
+
default:
|
|
2281
|
+
if (property.startsWith("dataset.")) {
|
|
2282
|
+
const dataAttribute = property.substring(8);
|
|
2283
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2284
|
+
}
|
|
2285
|
+
else {
|
|
2286
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
if (options !== null) {
|
|
2290
|
+
if (options.regex && options.regex !== "") {
|
|
2291
|
+
// Construct a regex pattern from the provided string
|
|
2292
|
+
const regex = options.regex.slice(1, -1);
|
|
2293
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2294
|
+
const matches = state.value.match(regexPattern);
|
|
2295
|
+
if (matches) {
|
|
2296
|
+
let newValue = "";
|
|
2297
|
+
for (const match of matches) {
|
|
2298
|
+
newValue += match;
|
|
2299
|
+
}
|
|
2300
|
+
state.value = newValue;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2304
|
+
state.value = state.value.trim();
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
1988
2307
|
state.info.value = state.value;
|
|
1989
2308
|
this.setTestData({ [variable]: state.value }, world);
|
|
1990
2309
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
@@ -2050,17 +2369,42 @@ class StableBrowser {
|
|
|
2050
2369
|
let regex;
|
|
2051
2370
|
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2052
2371
|
const patternBody = expectedValue.slice(1, -1);
|
|
2053
|
-
|
|
2372
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2373
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2374
|
+
state.info.regex = true;
|
|
2054
2375
|
}
|
|
2055
2376
|
else {
|
|
2056
2377
|
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2057
2378
|
regex = new RegExp(escapedPattern, "g");
|
|
2058
2379
|
}
|
|
2059
|
-
if (
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2380
|
+
if (attribute === "innerText") {
|
|
2381
|
+
if (state.info.regex) {
|
|
2382
|
+
if (!regex.test(val)) {
|
|
2383
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2384
|
+
state.info.failCause.assertionFailed = true;
|
|
2385
|
+
state.info.failCause.lastError = errorMessage;
|
|
2386
|
+
throw new Error(errorMessage);
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
else {
|
|
2390
|
+
const valLines = val.split("\n");
|
|
2391
|
+
const expectedLines = expectedValue.split("\n");
|
|
2392
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine === expectedLine));
|
|
2393
|
+
if (!isPart) {
|
|
2394
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2395
|
+
state.info.failCause.assertionFailed = true;
|
|
2396
|
+
state.info.failCause.lastError = errorMessage;
|
|
2397
|
+
throw new Error(errorMessage);
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
else {
|
|
2402
|
+
if (!val.match(regex)) {
|
|
2403
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2404
|
+
state.info.failCause.assertionFailed = true;
|
|
2405
|
+
state.info.failCause.lastError = errorMessage;
|
|
2406
|
+
throw new Error(errorMessage);
|
|
2407
|
+
}
|
|
2064
2408
|
}
|
|
2065
2409
|
return state.info;
|
|
2066
2410
|
}
|
|
@@ -2071,6 +2415,253 @@ class StableBrowser {
|
|
|
2071
2415
|
await _commandFinally(state, this);
|
|
2072
2416
|
}
|
|
2073
2417
|
}
|
|
2418
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2419
|
+
const state = {
|
|
2420
|
+
selectors,
|
|
2421
|
+
_params,
|
|
2422
|
+
property,
|
|
2423
|
+
value,
|
|
2424
|
+
options,
|
|
2425
|
+
world,
|
|
2426
|
+
type: Types.VERIFY_PROPERTY,
|
|
2427
|
+
highlight: true,
|
|
2428
|
+
screenshot: true,
|
|
2429
|
+
text: `Verify element property`,
|
|
2430
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2431
|
+
operation: "verifyProperty",
|
|
2432
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2433
|
+
allowDisabled: true,
|
|
2434
|
+
};
|
|
2435
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2436
|
+
let val;
|
|
2437
|
+
let expectedValue;
|
|
2438
|
+
try {
|
|
2439
|
+
await _preCommand(state, this);
|
|
2440
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2441
|
+
state.info.expectedValue = expectedValue;
|
|
2442
|
+
switch (property) {
|
|
2443
|
+
case "innerText":
|
|
2444
|
+
val = String(await state.element.innerText());
|
|
2445
|
+
break;
|
|
2446
|
+
case "text":
|
|
2447
|
+
val = String(await state.element.textContent());
|
|
2448
|
+
break;
|
|
2449
|
+
case "value":
|
|
2450
|
+
val = String(await state.element.inputValue());
|
|
2451
|
+
break;
|
|
2452
|
+
case "checked":
|
|
2453
|
+
val = String(await state.element.isChecked());
|
|
2454
|
+
break;
|
|
2455
|
+
case "disabled":
|
|
2456
|
+
val = String(await state.element.isDisabled());
|
|
2457
|
+
break;
|
|
2458
|
+
case "readOnly":
|
|
2459
|
+
const isEditable = await state.element.isEditable();
|
|
2460
|
+
val = String(!isEditable);
|
|
2461
|
+
break;
|
|
2462
|
+
case "innerHTML":
|
|
2463
|
+
val = String(await state.element.innerHTML());
|
|
2464
|
+
break;
|
|
2465
|
+
case "outerHTML":
|
|
2466
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2467
|
+
break;
|
|
2468
|
+
default:
|
|
2469
|
+
if (property.startsWith("dataset.")) {
|
|
2470
|
+
const dataAttribute = property.substring(8);
|
|
2471
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2472
|
+
}
|
|
2473
|
+
else {
|
|
2474
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
// Helper function to remove all style="" attributes
|
|
2478
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2479
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2480
|
+
};
|
|
2481
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2482
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2483
|
+
val = removeStyleAttributes(val);
|
|
2484
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2485
|
+
}
|
|
2486
|
+
state.info.value = val;
|
|
2487
|
+
let regex;
|
|
2488
|
+
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2489
|
+
const patternBody = expectedValue.slice(1, -1);
|
|
2490
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2491
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2492
|
+
state.info.regex = true;
|
|
2493
|
+
}
|
|
2494
|
+
else {
|
|
2495
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2496
|
+
regex = new RegExp(escapedPattern, "g");
|
|
2497
|
+
}
|
|
2498
|
+
if (property === "innerText") {
|
|
2499
|
+
if (state.info.regex) {
|
|
2500
|
+
if (!regex.test(val)) {
|
|
2501
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2502
|
+
state.info.failCause.assertionFailed = true;
|
|
2503
|
+
state.info.failCause.lastError = errorMessage;
|
|
2504
|
+
throw new Error(errorMessage);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
else {
|
|
2508
|
+
// Fix: Replace escaped newlines with actual newlines before splitting
|
|
2509
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2510
|
+
const valLines = val.split("\n");
|
|
2511
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2512
|
+
// Check if all expected lines are present in the actual lines
|
|
2513
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2514
|
+
if (!isPart) {
|
|
2515
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2516
|
+
state.info.failCause.assertionFailed = true;
|
|
2517
|
+
state.info.failCause.lastError = errorMessage;
|
|
2518
|
+
throw new Error(errorMessage);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
else {
|
|
2523
|
+
if (!val.match(regex)) {
|
|
2524
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2525
|
+
state.info.failCause.assertionFailed = true;
|
|
2526
|
+
state.info.failCause.lastError = errorMessage;
|
|
2527
|
+
throw new Error(errorMessage);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
return state.info;
|
|
2531
|
+
}
|
|
2532
|
+
catch (e) {
|
|
2533
|
+
await _commandError(state, e, this);
|
|
2534
|
+
}
|
|
2535
|
+
finally {
|
|
2536
|
+
await _commandFinally(state, this);
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2540
|
+
// Convert timeout from seconds to milliseconds
|
|
2541
|
+
const timeoutMs = timeout * 1000;
|
|
2542
|
+
const state = {
|
|
2543
|
+
selectors,
|
|
2544
|
+
_params,
|
|
2545
|
+
condition,
|
|
2546
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2547
|
+
options,
|
|
2548
|
+
world,
|
|
2549
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2550
|
+
highlight: true,
|
|
2551
|
+
screenshot: true,
|
|
2552
|
+
text: `Conditional wait for element`,
|
|
2553
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2554
|
+
operation: "conditionalWait",
|
|
2555
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2556
|
+
allowDisabled: true,
|
|
2557
|
+
info: {},
|
|
2558
|
+
};
|
|
2559
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2560
|
+
const startTime = Date.now();
|
|
2561
|
+
let conditionMet = false;
|
|
2562
|
+
let currentValue = null;
|
|
2563
|
+
let lastError = null;
|
|
2564
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2565
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2566
|
+
const elapsedTime = Date.now() - startTime;
|
|
2567
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2568
|
+
try {
|
|
2569
|
+
// Try to execute _preCommand (element location)
|
|
2570
|
+
await _preCommand(state, this);
|
|
2571
|
+
// If _preCommand succeeds, start condition checking
|
|
2572
|
+
const checkCondition = async () => {
|
|
2573
|
+
try {
|
|
2574
|
+
switch (condition.toLowerCase()) {
|
|
2575
|
+
case "checked":
|
|
2576
|
+
currentValue = await state.element.isChecked();
|
|
2577
|
+
return currentValue === true;
|
|
2578
|
+
case "unchecked":
|
|
2579
|
+
currentValue = await state.element.isChecked();
|
|
2580
|
+
return currentValue === false;
|
|
2581
|
+
case "visible":
|
|
2582
|
+
currentValue = await state.element.isVisible();
|
|
2583
|
+
return currentValue === true;
|
|
2584
|
+
case "hidden":
|
|
2585
|
+
currentValue = await state.element.isVisible();
|
|
2586
|
+
return currentValue === false;
|
|
2587
|
+
case "enabled":
|
|
2588
|
+
currentValue = await state.element.isDisabled();
|
|
2589
|
+
return currentValue === false;
|
|
2590
|
+
case "disabled":
|
|
2591
|
+
currentValue = await state.element.isDisabled();
|
|
2592
|
+
return currentValue === true;
|
|
2593
|
+
case "editable":
|
|
2594
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2595
|
+
currentValue = await state.element.isContentEditable();
|
|
2596
|
+
return currentValue === true;
|
|
2597
|
+
default:
|
|
2598
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2599
|
+
state.info.success = false;
|
|
2600
|
+
return false;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
catch (error) {
|
|
2604
|
+
// Don't throw here, just return false to continue retrying
|
|
2605
|
+
return false;
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
// Inner loop for condition checking (once element is located)
|
|
2609
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2610
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2611
|
+
conditionMet = await checkCondition();
|
|
2612
|
+
if (conditionMet) {
|
|
2613
|
+
break;
|
|
2614
|
+
}
|
|
2615
|
+
// Check if we still have time for another attempt
|
|
2616
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2617
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2618
|
+
}
|
|
2619
|
+
else {
|
|
2620
|
+
break;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
// If we got here and condition is met, break out of main loop
|
|
2624
|
+
if (conditionMet) {
|
|
2625
|
+
break;
|
|
2626
|
+
}
|
|
2627
|
+
// If condition not met but no exception, we've timed out
|
|
2628
|
+
break;
|
|
2629
|
+
}
|
|
2630
|
+
catch (e) {
|
|
2631
|
+
lastError = e;
|
|
2632
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2633
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2634
|
+
// Check if we have enough time left to retry
|
|
2635
|
+
if (timeLeft > 100) {
|
|
2636
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2637
|
+
}
|
|
2638
|
+
else {
|
|
2639
|
+
break;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2644
|
+
state.info = {
|
|
2645
|
+
success: conditionMet,
|
|
2646
|
+
conditionMet,
|
|
2647
|
+
actualWaitTime,
|
|
2648
|
+
currentValue,
|
|
2649
|
+
lastError: lastError?.message || null,
|
|
2650
|
+
message: conditionMet
|
|
2651
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2652
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2653
|
+
};
|
|
2654
|
+
if (lastError) {
|
|
2655
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2656
|
+
}
|
|
2657
|
+
try {
|
|
2658
|
+
await _commandFinally(state, this);
|
|
2659
|
+
}
|
|
2660
|
+
catch (finallyError) {
|
|
2661
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2662
|
+
}
|
|
2663
|
+
return state.info;
|
|
2664
|
+
}
|
|
2074
2665
|
async extractEmailData(emailAddress, options, world) {
|
|
2075
2666
|
if (!emailAddress) {
|
|
2076
2667
|
throw new Error("email address is null");
|
|
@@ -2228,56 +2819,49 @@ class StableBrowser {
|
|
|
2228
2819
|
console.debug(error);
|
|
2229
2820
|
}
|
|
2230
2821
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
// });
|
|
2274
|
-
// }
|
|
2275
|
-
// } catch (error) {
|
|
2276
|
-
// // console.debug(error);
|
|
2277
|
-
// }
|
|
2278
|
-
// }
|
|
2822
|
+
_matcher(text) {
|
|
2823
|
+
if (!text) {
|
|
2824
|
+
return { matcher: "contains", queryText: "" };
|
|
2825
|
+
}
|
|
2826
|
+
if (text.length < 2) {
|
|
2827
|
+
return { matcher: "contains", queryText: text };
|
|
2828
|
+
}
|
|
2829
|
+
const split = text.split(":");
|
|
2830
|
+
const matcher = split[0].toLowerCase();
|
|
2831
|
+
const queryText = split.slice(1).join(":").trim();
|
|
2832
|
+
return { matcher, queryText };
|
|
2833
|
+
}
|
|
2834
|
+
_getDomain(url) {
|
|
2835
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
2836
|
+
return "";
|
|
2837
|
+
}
|
|
2838
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
2839
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
2840
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
2841
|
+
}
|
|
2842
|
+
let n = hostnameFragments.length;
|
|
2843
|
+
let fragments = [...hostnameFragments];
|
|
2844
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
2845
|
+
hostnameFragments.pop();
|
|
2846
|
+
n = hostnameFragments.length;
|
|
2847
|
+
}
|
|
2848
|
+
if (n == 0) {
|
|
2849
|
+
if (fragments[0] === "www")
|
|
2850
|
+
fragments = fragments.slice(1);
|
|
2851
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
2852
|
+
}
|
|
2853
|
+
if (hostnameFragments[0] === "www")
|
|
2854
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
2855
|
+
return hostnameFragments.join(".");
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Verify the page path matches the given path.
|
|
2859
|
+
* @param {string} pathPart - The path to verify.
|
|
2860
|
+
* @param {object} options - Options for verification.
|
|
2861
|
+
* @param {object} world - The world context.
|
|
2862
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2863
|
+
*/
|
|
2279
2864
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2280
|
-
const startTime = Date.now();
|
|
2281
2865
|
let error = null;
|
|
2282
2866
|
let screenshotId = null;
|
|
2283
2867
|
let screenshotPath = null;
|
|
@@ -2291,113 +2875,212 @@ class StableBrowser {
|
|
|
2291
2875
|
pathPart = newValue;
|
|
2292
2876
|
}
|
|
2293
2877
|
info.pathPart = pathPart;
|
|
2878
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
2879
|
+
const state = {
|
|
2880
|
+
text_search: queryText,
|
|
2881
|
+
options,
|
|
2882
|
+
world,
|
|
2883
|
+
locate: false,
|
|
2884
|
+
scroll: false,
|
|
2885
|
+
highlight: false,
|
|
2886
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
2887
|
+
text: `Verify the page url is ${queryText}`,
|
|
2888
|
+
_text: `Verify the page url is ${queryText}`,
|
|
2889
|
+
operation: "verifyPagePath",
|
|
2890
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
2891
|
+
};
|
|
2294
2892
|
try {
|
|
2893
|
+
await _preCommand(state, this);
|
|
2894
|
+
state.info.text = queryText;
|
|
2295
2895
|
for (let i = 0; i < 30; i++) {
|
|
2296
2896
|
const url = await this.page.url();
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2897
|
+
switch (matcher) {
|
|
2898
|
+
case "exact":
|
|
2899
|
+
if (url !== queryText) {
|
|
2900
|
+
if (i === 29) {
|
|
2901
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
2902
|
+
}
|
|
2903
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2904
|
+
continue;
|
|
2905
|
+
}
|
|
2906
|
+
break;
|
|
2907
|
+
case "contains":
|
|
2908
|
+
if (!url.includes(queryText)) {
|
|
2909
|
+
if (i === 29) {
|
|
2910
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
2911
|
+
}
|
|
2912
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2913
|
+
continue;
|
|
2914
|
+
}
|
|
2915
|
+
break;
|
|
2916
|
+
case "starts-with":
|
|
2917
|
+
{
|
|
2918
|
+
const domain = this._getDomain(url);
|
|
2919
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
2920
|
+
if (i === 29) {
|
|
2921
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
2922
|
+
}
|
|
2923
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2924
|
+
continue;
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
break;
|
|
2928
|
+
case "ends-with":
|
|
2929
|
+
{
|
|
2930
|
+
const urlObj = new URL(url);
|
|
2931
|
+
let route = "/";
|
|
2932
|
+
if (urlObj.pathname !== "/") {
|
|
2933
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
2934
|
+
}
|
|
2935
|
+
else {
|
|
2936
|
+
route = "/";
|
|
2937
|
+
}
|
|
2938
|
+
if (route !== queryText) {
|
|
2939
|
+
if (i === 29) {
|
|
2940
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
2941
|
+
}
|
|
2942
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2943
|
+
continue;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
break;
|
|
2947
|
+
case "regex":
|
|
2948
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
2949
|
+
if (!regex.test(url)) {
|
|
2950
|
+
if (i === 29) {
|
|
2951
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
2952
|
+
}
|
|
2953
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2954
|
+
continue;
|
|
2955
|
+
}
|
|
2956
|
+
break;
|
|
2957
|
+
default:
|
|
2958
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
2959
|
+
if (!url.includes(pathPart)) {
|
|
2960
|
+
if (i === 29) {
|
|
2961
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
2962
|
+
}
|
|
2963
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2964
|
+
continue;
|
|
2965
|
+
}
|
|
2303
2966
|
}
|
|
2304
|
-
|
|
2305
|
-
return info;
|
|
2967
|
+
await _screenshot(state, this);
|
|
2968
|
+
return state.info;
|
|
2306
2969
|
}
|
|
2307
2970
|
}
|
|
2308
2971
|
catch (e) {
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
info.screenshotPath = screenshotPath;
|
|
2313
|
-
Object.assign(e, { info: info });
|
|
2314
|
-
error = e;
|
|
2315
|
-
// throw e;
|
|
2316
|
-
await _commandError({ text: "verifyPagePath", operation: "verifyPagePath", pathPart, info }, e, this);
|
|
2972
|
+
state.info.failCause.lastError = e.message;
|
|
2973
|
+
state.info.failCause.assertionFailed = true;
|
|
2974
|
+
await _commandError(state, e, this);
|
|
2317
2975
|
}
|
|
2318
2976
|
finally {
|
|
2319
|
-
|
|
2320
|
-
_reportToWorld(world, {
|
|
2321
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2322
|
-
text: "Verify page path",
|
|
2323
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2324
|
-
screenshotId,
|
|
2325
|
-
result: error
|
|
2326
|
-
? {
|
|
2327
|
-
status: "FAILED",
|
|
2328
|
-
startTime,
|
|
2329
|
-
endTime,
|
|
2330
|
-
message: error?.message,
|
|
2331
|
-
}
|
|
2332
|
-
: {
|
|
2333
|
-
status: "PASSED",
|
|
2334
|
-
startTime,
|
|
2335
|
-
endTime,
|
|
2336
|
-
},
|
|
2337
|
-
info: info,
|
|
2338
|
-
});
|
|
2977
|
+
await _commandFinally(state, this);
|
|
2339
2978
|
}
|
|
2340
2979
|
}
|
|
2980
|
+
/**
|
|
2981
|
+
* Verify the page title matches the given title.
|
|
2982
|
+
* @param {string} title - The title to verify.
|
|
2983
|
+
* @param {object} options - Options for verification.
|
|
2984
|
+
* @param {object} world - The world context.
|
|
2985
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2986
|
+
*/
|
|
2341
2987
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2342
|
-
const startTime = Date.now();
|
|
2343
2988
|
let error = null;
|
|
2344
2989
|
let screenshotId = null;
|
|
2345
2990
|
let screenshotPath = null;
|
|
2346
2991
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2347
|
-
const info = {};
|
|
2348
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2349
|
-
info.operation = "verifyPageTitle";
|
|
2350
2992
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2351
2993
|
if (newValue !== title) {
|
|
2352
2994
|
this.logger.info(title + "=" + newValue);
|
|
2353
2995
|
title = newValue;
|
|
2354
2996
|
}
|
|
2355
|
-
|
|
2997
|
+
const { matcher, queryText } = this._matcher(title);
|
|
2998
|
+
const state = {
|
|
2999
|
+
text_search: queryText,
|
|
3000
|
+
options,
|
|
3001
|
+
world,
|
|
3002
|
+
locate: false,
|
|
3003
|
+
scroll: false,
|
|
3004
|
+
highlight: false,
|
|
3005
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
3006
|
+
text: `Verify the page title is ${queryText}`,
|
|
3007
|
+
_text: `Verify the page title is ${queryText}`,
|
|
3008
|
+
operation: "verifyPageTitle",
|
|
3009
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
3010
|
+
};
|
|
2356
3011
|
try {
|
|
3012
|
+
await _preCommand(state, this);
|
|
3013
|
+
state.info.text = queryText;
|
|
2357
3014
|
for (let i = 0; i < 30; i++) {
|
|
2358
3015
|
const foundTitle = await this.page.title();
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
3016
|
+
switch (matcher) {
|
|
3017
|
+
case "exact":
|
|
3018
|
+
if (foundTitle !== queryText) {
|
|
3019
|
+
if (i === 29) {
|
|
3020
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
3021
|
+
}
|
|
3022
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3023
|
+
continue;
|
|
3024
|
+
}
|
|
3025
|
+
break;
|
|
3026
|
+
case "contains":
|
|
3027
|
+
if (!foundTitle.includes(queryText)) {
|
|
3028
|
+
if (i === 29) {
|
|
3029
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
3030
|
+
}
|
|
3031
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3032
|
+
continue;
|
|
3033
|
+
}
|
|
3034
|
+
break;
|
|
3035
|
+
case "starts-with":
|
|
3036
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3037
|
+
if (i === 29) {
|
|
3038
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3039
|
+
}
|
|
3040
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
break;
|
|
3044
|
+
case "ends-with":
|
|
3045
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3046
|
+
if (i === 29) {
|
|
3047
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3048
|
+
}
|
|
3049
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3050
|
+
continue;
|
|
3051
|
+
}
|
|
3052
|
+
break;
|
|
3053
|
+
case "regex":
|
|
3054
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3055
|
+
if (!regex.test(foundTitle)) {
|
|
3056
|
+
if (i === 29) {
|
|
3057
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3058
|
+
}
|
|
3059
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3060
|
+
continue;
|
|
3061
|
+
}
|
|
3062
|
+
break;
|
|
3063
|
+
default:
|
|
3064
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3065
|
+
if (!foundTitle.includes(title)) {
|
|
3066
|
+
if (i === 29) {
|
|
3067
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3068
|
+
}
|
|
3069
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3070
|
+
continue;
|
|
3071
|
+
}
|
|
2365
3072
|
}
|
|
2366
|
-
|
|
2367
|
-
return info;
|
|
3073
|
+
await _screenshot(state, this);
|
|
3074
|
+
return state.info;
|
|
2368
3075
|
}
|
|
2369
3076
|
}
|
|
2370
3077
|
catch (e) {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
info.screenshotPath = screenshotPath;
|
|
2375
|
-
Object.assign(e, { info: info });
|
|
2376
|
-
error = e;
|
|
2377
|
-
// throw e;
|
|
2378
|
-
await _commandError({ text: "verifyPageTitle", operation: "verifyPageTitle", title, info, throwError: true }, e, this);
|
|
3078
|
+
state.info.failCause.lastError = e.message;
|
|
3079
|
+
state.info.failCause.assertionFailed = true;
|
|
3080
|
+
await _commandError(state, e, this);
|
|
2379
3081
|
}
|
|
2380
3082
|
finally {
|
|
2381
|
-
|
|
2382
|
-
_reportToWorld(world, {
|
|
2383
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2384
|
-
text: "Verify page title",
|
|
2385
|
-
_text: "Verify the page title contains " + title,
|
|
2386
|
-
screenshotId,
|
|
2387
|
-
result: error
|
|
2388
|
-
? {
|
|
2389
|
-
status: "FAILED",
|
|
2390
|
-
startTime,
|
|
2391
|
-
endTime,
|
|
2392
|
-
message: error?.message,
|
|
2393
|
-
}
|
|
2394
|
-
: {
|
|
2395
|
-
status: "PASSED",
|
|
2396
|
-
startTime,
|
|
2397
|
-
endTime,
|
|
2398
|
-
},
|
|
2399
|
-
info: info,
|
|
2400
|
-
});
|
|
3083
|
+
await _commandFinally(state, this);
|
|
2401
3084
|
}
|
|
2402
3085
|
}
|
|
2403
3086
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2439,7 +3122,7 @@ class StableBrowser {
|
|
|
2439
3122
|
scroll: false,
|
|
2440
3123
|
highlight: false,
|
|
2441
3124
|
type: Types.VERIFY_PAGE_CONTAINS_TEXT,
|
|
2442
|
-
text: `Verify the text '${text}' exists in page`,
|
|
3125
|
+
text: `Verify the text '${maskValue(text)}' exists in page`,
|
|
2443
3126
|
_text: `Verify the text '${text}' exists in page`,
|
|
2444
3127
|
operation: "verifyTextExistInPage",
|
|
2445
3128
|
log: "***** verify text " + text + " exists in page *****\n",
|
|
@@ -2481,27 +3164,10 @@ class StableBrowser {
|
|
|
2481
3164
|
const frame = resultWithElementsFound[0].frame;
|
|
2482
3165
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2483
3166
|
await this._highlightElements(frame, dataAttribute);
|
|
2484
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2485
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2486
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2487
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2488
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2489
|
-
// .then(async () => {
|
|
2490
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2491
|
-
// })
|
|
2492
|
-
// .catch(
|
|
2493
|
-
// (e) => {}
|
|
2494
|
-
// console.error(e)
|
|
2495
|
-
// );
|
|
2496
|
-
// });
|
|
2497
|
-
// }
|
|
2498
3167
|
const element = await frame.locator(dataAttribute).first();
|
|
2499
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2500
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2501
3168
|
if (element) {
|
|
2502
3169
|
await this.scrollIfNeeded(element, state.info);
|
|
2503
3170
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2504
|
-
// await _screenshot(state, this, element);
|
|
2505
3171
|
}
|
|
2506
3172
|
}
|
|
2507
3173
|
await _screenshot(state, this);
|
|
@@ -2511,7 +3177,6 @@ class StableBrowser {
|
|
|
2511
3177
|
console.error(error);
|
|
2512
3178
|
}
|
|
2513
3179
|
}
|
|
2514
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2515
3180
|
}
|
|
2516
3181
|
catch (e) {
|
|
2517
3182
|
await _commandError(state, e, this);
|
|
@@ -2530,7 +3195,7 @@ class StableBrowser {
|
|
|
2530
3195
|
scroll: false,
|
|
2531
3196
|
highlight: false,
|
|
2532
3197
|
type: Types.WAIT_FOR_TEXT_TO_DISAPPEAR,
|
|
2533
|
-
text: `Verify the text '${text}' does not exist in page`,
|
|
3198
|
+
text: `Verify the text '${maskValue(text)}' does not exist in page`,
|
|
2534
3199
|
_text: `Verify the text '${text}' does not exist in page`,
|
|
2535
3200
|
operation: "verifyTextNotExistInPage",
|
|
2536
3201
|
log: "***** verify text " + text + " does not exist in page *****\n",
|
|
@@ -2593,6 +3258,8 @@ class StableBrowser {
|
|
|
2593
3258
|
operation: "verify_text_with_relation",
|
|
2594
3259
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2595
3260
|
};
|
|
3261
|
+
const cmdStartTime = Date.now();
|
|
3262
|
+
let cmdEndTime = null;
|
|
2596
3263
|
const timeout = this._getFindElementTimeout(options);
|
|
2597
3264
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2598
3265
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2628,6 +3295,17 @@ class StableBrowser {
|
|
|
2628
3295
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2629
3296
|
continue;
|
|
2630
3297
|
}
|
|
3298
|
+
else {
|
|
3299
|
+
cmdEndTime = Date.now();
|
|
3300
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3301
|
+
if (foundAncore) {
|
|
3302
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3303
|
+
}
|
|
3304
|
+
else {
|
|
3305
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
2631
3309
|
try {
|
|
2632
3310
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2633
3311
|
foundAncore = true;
|
|
@@ -3027,8 +3705,51 @@ class StableBrowser {
|
|
|
3027
3705
|
});
|
|
3028
3706
|
}
|
|
3029
3707
|
}
|
|
3708
|
+
/**
|
|
3709
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3710
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3711
|
+
* @param options - Optional configuration object
|
|
3712
|
+
* @param world - Optional world context
|
|
3713
|
+
* @returns Promise that resolves after the specified duration
|
|
3714
|
+
*/
|
|
3715
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3716
|
+
const state = {
|
|
3717
|
+
duration,
|
|
3718
|
+
options,
|
|
3719
|
+
world,
|
|
3720
|
+
locate: false,
|
|
3721
|
+
scroll: false,
|
|
3722
|
+
screenshot: false,
|
|
3723
|
+
highlight: false,
|
|
3724
|
+
type: Types.SLEEP,
|
|
3725
|
+
text: `Sleep for ${duration} ms`,
|
|
3726
|
+
_text: `Sleep for ${duration} ms`,
|
|
3727
|
+
operation: "sleep",
|
|
3728
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3729
|
+
};
|
|
3730
|
+
try {
|
|
3731
|
+
await _preCommand(state, this);
|
|
3732
|
+
if (duration < 0) {
|
|
3733
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3734
|
+
}
|
|
3735
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3736
|
+
return state.info;
|
|
3737
|
+
}
|
|
3738
|
+
catch (e) {
|
|
3739
|
+
await _commandError(state, e, this);
|
|
3740
|
+
}
|
|
3741
|
+
finally {
|
|
3742
|
+
await _commandFinally(state, this);
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3030
3745
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3031
|
-
|
|
3746
|
+
try {
|
|
3747
|
+
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
3748
|
+
}
|
|
3749
|
+
catch (error) {
|
|
3750
|
+
this.logger.debug(error);
|
|
3751
|
+
throw error;
|
|
3752
|
+
}
|
|
3032
3753
|
}
|
|
3033
3754
|
_getLoadTimeout(options) {
|
|
3034
3755
|
let timeout = 15000;
|
|
@@ -3051,6 +3772,7 @@ class StableBrowser {
|
|
|
3051
3772
|
}
|
|
3052
3773
|
async saveStoreState(path = null, world = null) {
|
|
3053
3774
|
const storageState = await this.page.context().storageState();
|
|
3775
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3054
3776
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3055
3777
|
if (path) {
|
|
3056
3778
|
// save { storageState: storageState } into the path
|
|
@@ -3061,10 +3783,14 @@ class StableBrowser {
|
|
|
3061
3783
|
}
|
|
3062
3784
|
}
|
|
3063
3785
|
async restoreSaveState(path = null, world = null) {
|
|
3786
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3064
3787
|
await refreshBrowser(this, path, world);
|
|
3065
3788
|
this.registerEventListeners(this.context);
|
|
3066
3789
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
3067
3790
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
3791
|
+
if (this.onRestoreSaveState) {
|
|
3792
|
+
this.onRestoreSaveState(path);
|
|
3793
|
+
}
|
|
3068
3794
|
}
|
|
3069
3795
|
async waitForPageLoad(options = {}, world = null) {
|
|
3070
3796
|
let timeout = this._getLoadTimeout(options);
|
|
@@ -3099,7 +3825,6 @@ class StableBrowser {
|
|
|
3099
3825
|
else if (e.label === "domcontentloaded") {
|
|
3100
3826
|
console.log("waited for the domcontent loaded timeout");
|
|
3101
3827
|
}
|
|
3102
|
-
console.log(".");
|
|
3103
3828
|
}
|
|
3104
3829
|
finally {
|
|
3105
3830
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -3143,7 +3868,6 @@ class StableBrowser {
|
|
|
3143
3868
|
await this.page.close();
|
|
3144
3869
|
}
|
|
3145
3870
|
catch (e) {
|
|
3146
|
-
console.log(".");
|
|
3147
3871
|
await _commandError(state, e, this);
|
|
3148
3872
|
}
|
|
3149
3873
|
finally {
|
|
@@ -3258,7 +3982,6 @@ class StableBrowser {
|
|
|
3258
3982
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3259
3983
|
}
|
|
3260
3984
|
catch (e) {
|
|
3261
|
-
console.log(".");
|
|
3262
3985
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3263
3986
|
}
|
|
3264
3987
|
finally {
|
|
@@ -3296,7 +4019,6 @@ class StableBrowser {
|
|
|
3296
4019
|
await this.page.reload();
|
|
3297
4020
|
}
|
|
3298
4021
|
catch (e) {
|
|
3299
|
-
console.log(".");
|
|
3300
4022
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3301
4023
|
}
|
|
3302
4024
|
finally {
|
|
@@ -3340,6 +4062,10 @@ class StableBrowser {
|
|
|
3340
4062
|
}
|
|
3341
4063
|
}
|
|
3342
4064
|
async beforeScenario(world, scenario) {
|
|
4065
|
+
if (world && world.attach) {
|
|
4066
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4067
|
+
}
|
|
4068
|
+
this.context.loadedRoutes = null;
|
|
3343
4069
|
this.beforeScenarioCalled = true;
|
|
3344
4070
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
3345
4071
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -3362,12 +4088,19 @@ class StableBrowser {
|
|
|
3362
4088
|
if (this.context && this.context.environment) {
|
|
3363
4089
|
envName = this.context.environment.name;
|
|
3364
4090
|
}
|
|
3365
|
-
|
|
4091
|
+
if (!process.env.TEMP_RUN) {
|
|
4092
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
4093
|
+
}
|
|
4094
|
+
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3366
4095
|
}
|
|
3367
4096
|
async afterScenario(world, scenario) { }
|
|
3368
4097
|
async beforeStep(world, step) {
|
|
4098
|
+
if (this.abortedExecution) {
|
|
4099
|
+
throw new Error("Aborted");
|
|
4100
|
+
}
|
|
3369
4101
|
if (!this.beforeScenarioCalled) {
|
|
3370
4102
|
this.beforeScenario(world, step);
|
|
4103
|
+
this.context.loadedRoutes = null;
|
|
3371
4104
|
}
|
|
3372
4105
|
if (this.stepIndex === undefined) {
|
|
3373
4106
|
this.stepIndex = 0;
|
|
@@ -3392,13 +4125,16 @@ class StableBrowser {
|
|
|
3392
4125
|
}
|
|
3393
4126
|
if (this.initSnapshotTaken === false) {
|
|
3394
4127
|
this.initSnapshotTaken = true;
|
|
3395
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4128
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3396
4129
|
const snapshot = await this.getAriaSnapshot();
|
|
3397
4130
|
if (snapshot) {
|
|
3398
4131
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3399
4132
|
}
|
|
3400
4133
|
}
|
|
3401
4134
|
}
|
|
4135
|
+
this.context.routeResults = null;
|
|
4136
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4137
|
+
networkBeforeStep(this.stepName);
|
|
3402
4138
|
}
|
|
3403
4139
|
async getAriaSnapshot() {
|
|
3404
4140
|
try {
|
|
@@ -3414,18 +4150,74 @@ class StableBrowser {
|
|
|
3414
4150
|
const content = [`- path: ${path}`, `- title: ${title}`];
|
|
3415
4151
|
const timeout = this.configuration.ariaSnapshotTimeout ? this.configuration.ariaSnapshotTimeout : 3000;
|
|
3416
4152
|
for (let i = 0; i < frames.length; i++) {
|
|
3417
|
-
content.push(`- frame: ${i}`);
|
|
3418
4153
|
const frame = frames[i];
|
|
3419
|
-
|
|
3420
|
-
|
|
4154
|
+
try {
|
|
4155
|
+
// Ensure frame is attached and has body
|
|
4156
|
+
const body = frame.locator("body");
|
|
4157
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
4158
|
+
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4159
|
+
if (!snapshot) {
|
|
4160
|
+
continue;
|
|
4161
|
+
}
|
|
4162
|
+
content.push(`- frame: ${i}`);
|
|
4163
|
+
content.push(snapshot);
|
|
4164
|
+
}
|
|
4165
|
+
catch (innerErr) {
|
|
4166
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4167
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4168
|
+
}
|
|
3421
4169
|
}
|
|
3422
4170
|
return content.join("\n");
|
|
3423
4171
|
}
|
|
3424
4172
|
catch (e) {
|
|
3425
|
-
console.
|
|
4173
|
+
console.log("Error in getAriaSnapshot");
|
|
4174
|
+
//console.debug(e);
|
|
3426
4175
|
}
|
|
3427
4176
|
return null;
|
|
3428
4177
|
}
|
|
4178
|
+
/**
|
|
4179
|
+
* Sends command with custom payload to report.
|
|
4180
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4181
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4182
|
+
* @param content - Content of the command to be shown in the report.
|
|
4183
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4184
|
+
* @param world - Optional world context.
|
|
4185
|
+
* @public
|
|
4186
|
+
*/
|
|
4187
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4188
|
+
const state = {
|
|
4189
|
+
options,
|
|
4190
|
+
world,
|
|
4191
|
+
locate: false,
|
|
4192
|
+
scroll: false,
|
|
4193
|
+
screenshot: options.screenshot ?? false,
|
|
4194
|
+
highlight: options.highlight ?? false,
|
|
4195
|
+
type: Types.REPORT_COMMAND,
|
|
4196
|
+
text: commandText,
|
|
4197
|
+
_text: commandText,
|
|
4198
|
+
operation: "report_command",
|
|
4199
|
+
log: "***** " + commandText + " *****\n",
|
|
4200
|
+
};
|
|
4201
|
+
try {
|
|
4202
|
+
await _preCommand(state, this);
|
|
4203
|
+
const payload = {
|
|
4204
|
+
type: options.type ?? "text",
|
|
4205
|
+
content: content,
|
|
4206
|
+
screenshotId: null,
|
|
4207
|
+
};
|
|
4208
|
+
state.payload = payload;
|
|
4209
|
+
if (commandStatus === "FAILED") {
|
|
4210
|
+
state.throwError = true;
|
|
4211
|
+
throw new Error("Command failed");
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
catch (e) {
|
|
4215
|
+
await _commandError(state, e, this);
|
|
4216
|
+
}
|
|
4217
|
+
finally {
|
|
4218
|
+
await _commandFinally(state, this);
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
3429
4221
|
async afterStep(world, step) {
|
|
3430
4222
|
this.stepName = null;
|
|
3431
4223
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3433,10 +4225,12 @@ class StableBrowser {
|
|
|
3433
4225
|
await this.context.browserObject.context.tracing.stopChunk({
|
|
3434
4226
|
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
3435
4227
|
});
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
4228
|
+
if (world && world.attach) {
|
|
4229
|
+
await world.attach(JSON.stringify({
|
|
4230
|
+
type: "trace",
|
|
4231
|
+
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4232
|
+
}), "application/json+trace");
|
|
4233
|
+
}
|
|
3440
4234
|
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
3441
4235
|
}
|
|
3442
4236
|
}
|
|
@@ -3450,6 +4244,36 @@ class StableBrowser {
|
|
|
3450
4244
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3451
4245
|
}
|
|
3452
4246
|
}
|
|
4247
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4248
|
+
if (this.context.routeResults) {
|
|
4249
|
+
if (world && world.attach) {
|
|
4250
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
if (!process.env.TEMP_RUN) {
|
|
4254
|
+
const state = {
|
|
4255
|
+
world,
|
|
4256
|
+
locate: false,
|
|
4257
|
+
scroll: false,
|
|
4258
|
+
screenshot: true,
|
|
4259
|
+
highlight: true,
|
|
4260
|
+
type: Types.STEP_COMPLETE,
|
|
4261
|
+
text: "end of scenario",
|
|
4262
|
+
_text: "end of scenario",
|
|
4263
|
+
operation: "step_complete",
|
|
4264
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4265
|
+
};
|
|
4266
|
+
try {
|
|
4267
|
+
await _preCommand(state, this);
|
|
4268
|
+
}
|
|
4269
|
+
catch (e) {
|
|
4270
|
+
await _commandError(state, e, this);
|
|
4271
|
+
}
|
|
4272
|
+
finally {
|
|
4273
|
+
await _commandFinally(state, this);
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
networkAfterStep(this.stepName);
|
|
3453
4277
|
}
|
|
3454
4278
|
}
|
|
3455
4279
|
function createTimedPromise(promise, label) {
|