automation_model 1.0.665-dev → 1.0.665-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 +2 -2
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +1 -1
- package/lib/auto_page.js +145 -58
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +28 -8
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.d.ts +1 -0
- package/lib/bruno.js +228 -22
- package/lib/bruno.js.map +1 -1
- package/lib/command_common.d.ts +1 -1
- package/lib/command_common.js +24 -4
- 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 +61 -0
- package/lib/file_checker.js.map +1 -0
- package/lib/find_function.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -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.js.map +1 -1
- package/lib/route.d.ts +33 -0
- package/lib/route.js +274 -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 +63 -25
- package/lib/stable_browser.js +1037 -229
- 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 +15 -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 +15 -2
- package/lib/utils.js +92 -58
- package/lib/utils.js.map +1 -1
- package/package.json +13 -7
package/lib/stable_browser.js
CHANGED
|
@@ -10,11 +10,12 @@ 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";
|
|
17
17
|
import { getContext, refreshBrowser } from "./init_browser.js";
|
|
18
|
+
import { getTestData } from "./auto_page.js";
|
|
18
19
|
import { locate_element } from "./locate_element.js";
|
|
19
20
|
import { randomUUID } from "crypto";
|
|
20
21
|
import { _commandError, _commandFinally, _preCommand, _validateSelectors, _screenshot, _reportToWorld, } from "./command_common.js";
|
|
@@ -22,23 +23,29 @@ import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
|
22
23
|
import { LocatorLog } from "./locator_log.js";
|
|
23
24
|
import axios from "axios";
|
|
24
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";
|
|
25
29
|
export const Types = {
|
|
26
30
|
CLICK: "click_element",
|
|
27
31
|
WAIT_ELEMENT: "wait_element",
|
|
28
32
|
NAVIGATE: "navigate",
|
|
33
|
+
GO_BACK: "go_back",
|
|
34
|
+
GO_FORWARD: "go_forward",
|
|
29
35
|
FILL: "fill_element",
|
|
30
|
-
EXECUTE: "execute_page_method",
|
|
31
|
-
OPEN: "open_environment",
|
|
36
|
+
EXECUTE: "execute_page_method", //
|
|
37
|
+
OPEN: "open_environment", //
|
|
32
38
|
COMPLETE: "step_complete",
|
|
33
39
|
ASK: "information_needed",
|
|
34
|
-
GET_PAGE_STATUS: "get_page_status",
|
|
35
|
-
CLICK_ROW_ACTION: "click_row_action",
|
|
40
|
+
GET_PAGE_STATUS: "get_page_status", ///
|
|
41
|
+
CLICK_ROW_ACTION: "click_row_action", //
|
|
36
42
|
VERIFY_ELEMENT_CONTAINS_TEXT: "verify_element_contains_text",
|
|
37
43
|
VERIFY_PAGE_CONTAINS_TEXT: "verify_page_contains_text",
|
|
38
44
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
39
45
|
ANALYZE_TABLE: "analyze_table",
|
|
40
|
-
SELECT: "select_combobox",
|
|
46
|
+
SELECT: "select_combobox", //
|
|
41
47
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
48
|
+
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
42
49
|
TYPE_PRESS: "type_press",
|
|
43
50
|
PRESS: "press_key",
|
|
44
51
|
HOVER: "hover_element",
|
|
@@ -56,6 +63,13 @@ export const Types = {
|
|
|
56
63
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
57
64
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
58
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",
|
|
59
73
|
};
|
|
60
74
|
export const apps = {};
|
|
61
75
|
const formatElementName = (elementName) => {
|
|
@@ -67,6 +81,7 @@ class StableBrowser {
|
|
|
67
81
|
logger;
|
|
68
82
|
context;
|
|
69
83
|
world;
|
|
84
|
+
fastMode;
|
|
70
85
|
project_path = null;
|
|
71
86
|
webLogFile = null;
|
|
72
87
|
networkLogger = null;
|
|
@@ -75,12 +90,13 @@ class StableBrowser {
|
|
|
75
90
|
tags = null;
|
|
76
91
|
isRecording = false;
|
|
77
92
|
initSnapshotTaken = false;
|
|
78
|
-
constructor(browser, page, logger = null, context = null, world = null) {
|
|
93
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
79
94
|
this.browser = browser;
|
|
80
95
|
this.page = page;
|
|
81
96
|
this.logger = logger;
|
|
82
97
|
this.context = context;
|
|
83
98
|
this.world = world;
|
|
99
|
+
this.fastMode = fastMode;
|
|
84
100
|
if (!this.logger) {
|
|
85
101
|
this.logger = console;
|
|
86
102
|
}
|
|
@@ -109,6 +125,18 @@ class StableBrowser {
|
|
|
109
125
|
context.pages = [this.page];
|
|
110
126
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
111
127
|
this.world = world;
|
|
128
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
129
|
+
this.fastMode = true;
|
|
130
|
+
}
|
|
131
|
+
if (process.env.FAST_MODE === "true") {
|
|
132
|
+
this.fastMode = true;
|
|
133
|
+
}
|
|
134
|
+
if (process.env.FAST_MODE === "false") {
|
|
135
|
+
this.fastMode = false;
|
|
136
|
+
}
|
|
137
|
+
if (this.context) {
|
|
138
|
+
this.context.fastMode = this.fastMode;
|
|
139
|
+
}
|
|
112
140
|
this.registerEventListeners(this.context);
|
|
113
141
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
114
142
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -119,6 +147,9 @@ class StableBrowser {
|
|
|
119
147
|
if (!context.pageLoading) {
|
|
120
148
|
context.pageLoading = { status: false };
|
|
121
149
|
}
|
|
150
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
151
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
152
|
+
}
|
|
122
153
|
context.playContext.on("page", async function (page) {
|
|
123
154
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
124
155
|
console.log("close unexpected popups");
|
|
@@ -127,6 +158,14 @@ class StableBrowser {
|
|
|
127
158
|
}
|
|
128
159
|
context.pageLoading.status = true;
|
|
129
160
|
this.page = page;
|
|
161
|
+
try {
|
|
162
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
163
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error("Error on dialog accept registration", error);
|
|
168
|
+
}
|
|
130
169
|
context.page = page;
|
|
131
170
|
context.pages.push(page);
|
|
132
171
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -178,9 +217,35 @@ class StableBrowser {
|
|
|
178
217
|
if (newContextCreated) {
|
|
179
218
|
this.registerEventListeners(this.context);
|
|
180
219
|
await this.goto(this.context.environment.baseUrl);
|
|
181
|
-
|
|
220
|
+
if (!this.fastMode) {
|
|
221
|
+
await this.waitForPageLoad();
|
|
222
|
+
}
|
|
182
223
|
}
|
|
183
224
|
}
|
|
225
|
+
async switchTab(tabTitleOrIndex) {
|
|
226
|
+
// first check if the tabNameOrIndex is a number
|
|
227
|
+
let index = parseInt(tabTitleOrIndex);
|
|
228
|
+
if (!isNaN(index)) {
|
|
229
|
+
if (index >= 0 && index < this.context.pages.length) {
|
|
230
|
+
this.page = this.context.pages[index];
|
|
231
|
+
this.context.page = this.page;
|
|
232
|
+
await this.page.bringToFront();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// if the tabNameOrIndex is a string, find the tab by name
|
|
237
|
+
for (let i = 0; i < this.context.pages.length; i++) {
|
|
238
|
+
let page = this.context.pages[i];
|
|
239
|
+
let title = await page.title();
|
|
240
|
+
if (title.includes(tabTitleOrIndex)) {
|
|
241
|
+
this.page = page;
|
|
242
|
+
this.context.page = this.page;
|
|
243
|
+
await this.page.bringToFront();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
throw new Error("Tab not found: " + tabTitleOrIndex);
|
|
248
|
+
}
|
|
184
249
|
registerConsoleLogListener(page, context) {
|
|
185
250
|
if (!this.context.webLogger) {
|
|
186
251
|
this.context.webLogger = [];
|
|
@@ -248,6 +313,7 @@ class StableBrowser {
|
|
|
248
313
|
if (!url) {
|
|
249
314
|
throw new Error("url is null, verify that the environment file is correct");
|
|
250
315
|
}
|
|
316
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
251
317
|
if (!url.startsWith("http")) {
|
|
252
318
|
url = "https://" + url;
|
|
253
319
|
}
|
|
@@ -276,7 +342,65 @@ class StableBrowser {
|
|
|
276
342
|
_commandError(state, error, this);
|
|
277
343
|
}
|
|
278
344
|
finally {
|
|
279
|
-
_commandFinally(state, this);
|
|
345
|
+
await _commandFinally(state, this);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async goBack(options, world = null) {
|
|
349
|
+
const state = {
|
|
350
|
+
value: "",
|
|
351
|
+
world: world,
|
|
352
|
+
type: Types.GO_BACK,
|
|
353
|
+
text: `Browser navigate back`,
|
|
354
|
+
operation: "goBack",
|
|
355
|
+
log: "***** navigate back *****\n",
|
|
356
|
+
info: {},
|
|
357
|
+
locate: false,
|
|
358
|
+
scroll: false,
|
|
359
|
+
screenshot: false,
|
|
360
|
+
highlight: false,
|
|
361
|
+
};
|
|
362
|
+
try {
|
|
363
|
+
await _preCommand(state, this);
|
|
364
|
+
await this.page.goBack({
|
|
365
|
+
waitUntil: "load",
|
|
366
|
+
});
|
|
367
|
+
await _screenshot(state, this);
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
console.error("Error on goBack", error);
|
|
371
|
+
_commandError(state, error, this);
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
await _commandFinally(state, this);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async goForward(options, world = null) {
|
|
378
|
+
const state = {
|
|
379
|
+
value: "",
|
|
380
|
+
world: world,
|
|
381
|
+
type: Types.GO_FORWARD,
|
|
382
|
+
text: `Browser navigate forward`,
|
|
383
|
+
operation: "goForward",
|
|
384
|
+
log: "***** navigate forward *****\n",
|
|
385
|
+
info: {},
|
|
386
|
+
locate: false,
|
|
387
|
+
scroll: false,
|
|
388
|
+
screenshot: false,
|
|
389
|
+
highlight: false,
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
await _preCommand(state, this);
|
|
393
|
+
await this.page.goForward({
|
|
394
|
+
waitUntil: "load",
|
|
395
|
+
});
|
|
396
|
+
await _screenshot(state, this);
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
console.error("Error on goForward", error);
|
|
400
|
+
_commandError(state, error, this);
|
|
401
|
+
}
|
|
402
|
+
finally {
|
|
403
|
+
await _commandFinally(state, this);
|
|
280
404
|
}
|
|
281
405
|
}
|
|
282
406
|
async _getLocator(locator, scope, _params) {
|
|
@@ -392,7 +516,7 @@ class StableBrowser {
|
|
|
392
516
|
}
|
|
393
517
|
return { elementCount: tagCount, randomToken };
|
|
394
518
|
}
|
|
395
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
519
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
396
520
|
if (!info) {
|
|
397
521
|
info = {};
|
|
398
522
|
}
|
|
@@ -404,14 +528,13 @@ class StableBrowser {
|
|
|
404
528
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
405
529
|
}
|
|
406
530
|
let locatorSearch = selectorHierarchy[index];
|
|
407
|
-
let originalLocatorSearch = "";
|
|
408
531
|
try {
|
|
409
|
-
|
|
410
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
532
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
411
533
|
}
|
|
412
534
|
catch (e) {
|
|
413
535
|
console.error(e);
|
|
414
536
|
}
|
|
537
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
415
538
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
416
539
|
let locator = null;
|
|
417
540
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -459,7 +582,7 @@ class StableBrowser {
|
|
|
459
582
|
}
|
|
460
583
|
return;
|
|
461
584
|
}
|
|
462
|
-
if (info.locatorLog && count === 0) {
|
|
585
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
463
586
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
464
587
|
}
|
|
465
588
|
for (let j = 0; j < count; j++) {
|
|
@@ -474,7 +597,7 @@ class StableBrowser {
|
|
|
474
597
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
475
598
|
}
|
|
476
599
|
}
|
|
477
|
-
else {
|
|
600
|
+
else if (logErrors) {
|
|
478
601
|
info.failCause.visible = visible;
|
|
479
602
|
info.failCause.enabled = enabled;
|
|
480
603
|
if (!info.printMessages) {
|
|
@@ -566,7 +689,7 @@ class StableBrowser {
|
|
|
566
689
|
let element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
567
690
|
if (!element.rerun) {
|
|
568
691
|
const randomToken = Math.random().toString(36).substring(7);
|
|
569
|
-
element.evaluate((el, randomToken) => {
|
|
692
|
+
await element.evaluate((el, randomToken) => {
|
|
570
693
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
571
694
|
}, randomToken);
|
|
572
695
|
// if (element._frame) {
|
|
@@ -815,7 +938,7 @@ class StableBrowser {
|
|
|
815
938
|
}
|
|
816
939
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
817
940
|
}
|
|
818
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
941
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
819
942
|
let foundElements = [];
|
|
820
943
|
const result = {
|
|
821
944
|
foundElements: foundElements,
|
|
@@ -834,7 +957,9 @@ class StableBrowser {
|
|
|
834
957
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
835
958
|
}
|
|
836
959
|
catch (e) {
|
|
837
|
-
|
|
960
|
+
if (logErrors) {
|
|
961
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
962
|
+
}
|
|
838
963
|
}
|
|
839
964
|
}
|
|
840
965
|
if (foundLocators.length === 1) {
|
|
@@ -875,7 +1000,7 @@ class StableBrowser {
|
|
|
875
1000
|
});
|
|
876
1001
|
result.locatorIndex = i;
|
|
877
1002
|
}
|
|
878
|
-
else {
|
|
1003
|
+
else if (logErrors) {
|
|
879
1004
|
info.failCause.foundMultiple = true;
|
|
880
1005
|
if (info.locatorLog) {
|
|
881
1006
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -927,7 +1052,7 @@ class StableBrowser {
|
|
|
927
1052
|
await _commandError(state, "timeout looking for " + elementDescription, this);
|
|
928
1053
|
}
|
|
929
1054
|
finally {
|
|
930
|
-
_commandFinally(state, this);
|
|
1055
|
+
await _commandFinally(state, this);
|
|
931
1056
|
}
|
|
932
1057
|
}
|
|
933
1058
|
}
|
|
@@ -976,7 +1101,7 @@ class StableBrowser {
|
|
|
976
1101
|
await _commandError(state, "timeout looking for " + elementDescription, this);
|
|
977
1102
|
}
|
|
978
1103
|
finally {
|
|
979
|
-
_commandFinally(state, this);
|
|
1104
|
+
await _commandFinally(state, this);
|
|
980
1105
|
}
|
|
981
1106
|
}
|
|
982
1107
|
}
|
|
@@ -998,14 +1123,16 @@ class StableBrowser {
|
|
|
998
1123
|
try {
|
|
999
1124
|
await _preCommand(state, this);
|
|
1000
1125
|
await performAction("click", state.element, options, this, state, _params);
|
|
1001
|
-
|
|
1126
|
+
if (!this.fastMode) {
|
|
1127
|
+
await this.waitForPageLoad();
|
|
1128
|
+
}
|
|
1002
1129
|
return state.info;
|
|
1003
1130
|
}
|
|
1004
1131
|
catch (e) {
|
|
1005
1132
|
await _commandError(state, e, this);
|
|
1006
1133
|
}
|
|
1007
1134
|
finally {
|
|
1008
|
-
_commandFinally(state, this);
|
|
1135
|
+
await _commandFinally(state, this);
|
|
1009
1136
|
}
|
|
1010
1137
|
}
|
|
1011
1138
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1036,7 +1163,7 @@ class StableBrowser {
|
|
|
1036
1163
|
// await _commandError(state, e, this);
|
|
1037
1164
|
}
|
|
1038
1165
|
finally {
|
|
1039
|
-
_commandFinally(state, this);
|
|
1166
|
+
await _commandFinally(state, this);
|
|
1040
1167
|
}
|
|
1041
1168
|
return found;
|
|
1042
1169
|
}
|
|
@@ -1061,7 +1188,7 @@ class StableBrowser {
|
|
|
1061
1188
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1062
1189
|
// console.log(`Highlighting while running from recorder`);
|
|
1063
1190
|
await this._highlightElements(state.element);
|
|
1064
|
-
await state.element.setChecked(checked);
|
|
1191
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1065
1192
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1066
1193
|
// await this._unHighlightElements(element);
|
|
1067
1194
|
// }
|
|
@@ -1073,11 +1200,28 @@ class StableBrowser {
|
|
|
1073
1200
|
this.logger.info("element did not change its state, ignoring...");
|
|
1074
1201
|
}
|
|
1075
1202
|
else {
|
|
1203
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1076
1204
|
//await this.closeUnexpectedPopups();
|
|
1077
1205
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1078
|
-
state.
|
|
1079
|
-
|
|
1080
|
-
|
|
1206
|
+
state.element_found = false;
|
|
1207
|
+
try {
|
|
1208
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1209
|
+
state.element_found = true;
|
|
1210
|
+
// check the check state
|
|
1211
|
+
}
|
|
1212
|
+
catch (error) {
|
|
1213
|
+
// element dismissed
|
|
1214
|
+
}
|
|
1215
|
+
if (state.element_found) {
|
|
1216
|
+
const isChecked = await state.element.isChecked();
|
|
1217
|
+
if (isChecked !== checked) {
|
|
1218
|
+
// perform click
|
|
1219
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1220
|
+
}
|
|
1221
|
+
else {
|
|
1222
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1081
1225
|
}
|
|
1082
1226
|
}
|
|
1083
1227
|
await this.waitForPageLoad();
|
|
@@ -1087,7 +1231,7 @@ class StableBrowser {
|
|
|
1087
1231
|
await _commandError(state, e, this);
|
|
1088
1232
|
}
|
|
1089
1233
|
finally {
|
|
1090
|
-
_commandFinally(state, this);
|
|
1234
|
+
await _commandFinally(state, this);
|
|
1091
1235
|
}
|
|
1092
1236
|
}
|
|
1093
1237
|
async hover(selectors, _params, options = {}, world = null) {
|
|
@@ -1113,7 +1257,7 @@ class StableBrowser {
|
|
|
1113
1257
|
await _commandError(state, e, this);
|
|
1114
1258
|
}
|
|
1115
1259
|
finally {
|
|
1116
|
-
_commandFinally(state, this);
|
|
1260
|
+
await _commandFinally(state, this);
|
|
1117
1261
|
}
|
|
1118
1262
|
}
|
|
1119
1263
|
async selectOption(selectors, values, _params = null, options = {}, world = null) {
|
|
@@ -1149,7 +1293,7 @@ class StableBrowser {
|
|
|
1149
1293
|
await _commandError(state, e, this);
|
|
1150
1294
|
}
|
|
1151
1295
|
finally {
|
|
1152
|
-
_commandFinally(state, this);
|
|
1296
|
+
await _commandFinally(state, this);
|
|
1153
1297
|
}
|
|
1154
1298
|
}
|
|
1155
1299
|
async type(_value, _params = null, options = {}, world = null) {
|
|
@@ -1195,7 +1339,7 @@ class StableBrowser {
|
|
|
1195
1339
|
await _commandError(state, e, this);
|
|
1196
1340
|
}
|
|
1197
1341
|
finally {
|
|
1198
|
-
_commandFinally(state, this);
|
|
1342
|
+
await _commandFinally(state, this);
|
|
1199
1343
|
}
|
|
1200
1344
|
}
|
|
1201
1345
|
async setInputValue(selectors, value, _params = null, options = {}, world = null) {
|
|
@@ -1231,7 +1375,7 @@ class StableBrowser {
|
|
|
1231
1375
|
await _commandError(state, e, this);
|
|
1232
1376
|
}
|
|
1233
1377
|
finally {
|
|
1234
|
-
_commandFinally(state, this);
|
|
1378
|
+
await _commandFinally(state, this);
|
|
1235
1379
|
}
|
|
1236
1380
|
}
|
|
1237
1381
|
async setDateTime(selectors, value, format = null, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1300,7 +1444,7 @@ class StableBrowser {
|
|
|
1300
1444
|
await _commandError(state, e, this);
|
|
1301
1445
|
}
|
|
1302
1446
|
finally {
|
|
1303
|
-
_commandFinally(state, this);
|
|
1447
|
+
await _commandFinally(state, this);
|
|
1304
1448
|
}
|
|
1305
1449
|
}
|
|
1306
1450
|
async clickType(selectors, _value, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1373,7 +1517,9 @@ class StableBrowser {
|
|
|
1373
1517
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1374
1518
|
}
|
|
1375
1519
|
}
|
|
1520
|
+
//if (!this.fastMode) {
|
|
1376
1521
|
await _screenshot(state, this);
|
|
1522
|
+
//}
|
|
1377
1523
|
if (enter === true) {
|
|
1378
1524
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1379
1525
|
await this.page.keyboard.press("Enter");
|
|
@@ -1400,7 +1546,7 @@ class StableBrowser {
|
|
|
1400
1546
|
await _commandError(state, e, this);
|
|
1401
1547
|
}
|
|
1402
1548
|
finally {
|
|
1403
|
-
_commandFinally(state, this);
|
|
1549
|
+
await _commandFinally(state, this);
|
|
1404
1550
|
}
|
|
1405
1551
|
}
|
|
1406
1552
|
async fill(selectors, value, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1430,7 +1576,42 @@ class StableBrowser {
|
|
|
1430
1576
|
await _commandError(state, e, this);
|
|
1431
1577
|
}
|
|
1432
1578
|
finally {
|
|
1433
|
-
_commandFinally(state, this);
|
|
1579
|
+
await _commandFinally(state, this);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
async setInputFiles(selectors, files, _params = null, options = {}, world = null) {
|
|
1583
|
+
const state = {
|
|
1584
|
+
selectors,
|
|
1585
|
+
_params,
|
|
1586
|
+
files,
|
|
1587
|
+
value: '"' + files.join('", "') + '"',
|
|
1588
|
+
options,
|
|
1589
|
+
world,
|
|
1590
|
+
type: Types.SET_INPUT_FILES,
|
|
1591
|
+
text: `Set input files`,
|
|
1592
|
+
_text: `Set input files on ${selectors.element_name}`,
|
|
1593
|
+
operation: "setInputFiles",
|
|
1594
|
+
log: "***** set input files " + selectors.element_name + " *****\n",
|
|
1595
|
+
};
|
|
1596
|
+
const uploadsFolder = this.configuration.uploadsFolder ?? "data/uploads";
|
|
1597
|
+
try {
|
|
1598
|
+
await _preCommand(state, this);
|
|
1599
|
+
for (let i = 0; i < files.length; i++) {
|
|
1600
|
+
const file = files[i];
|
|
1601
|
+
const filePath = path.join(uploadsFolder, file);
|
|
1602
|
+
if (!fs.existsSync(filePath)) {
|
|
1603
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1604
|
+
}
|
|
1605
|
+
state.files[i] = filePath;
|
|
1606
|
+
}
|
|
1607
|
+
await state.element.setInputFiles(files);
|
|
1608
|
+
return state.info;
|
|
1609
|
+
}
|
|
1610
|
+
catch (e) {
|
|
1611
|
+
await _commandError(state, e, this);
|
|
1612
|
+
}
|
|
1613
|
+
finally {
|
|
1614
|
+
await _commandFinally(state, this);
|
|
1434
1615
|
}
|
|
1435
1616
|
}
|
|
1436
1617
|
async getText(selectors, _params = null, options = {}, info = {}, world = null) {
|
|
@@ -1546,7 +1727,7 @@ class StableBrowser {
|
|
|
1546
1727
|
await _commandError(state, e, this);
|
|
1547
1728
|
}
|
|
1548
1729
|
finally {
|
|
1549
|
-
_commandFinally(state, this);
|
|
1730
|
+
await _commandFinally(state, this);
|
|
1550
1731
|
}
|
|
1551
1732
|
}
|
|
1552
1733
|
async containsText(selectors, text, climb, _params = null, options = {}, world = null) {
|
|
@@ -1623,7 +1804,84 @@ class StableBrowser {
|
|
|
1623
1804
|
throw e;
|
|
1624
1805
|
}
|
|
1625
1806
|
finally {
|
|
1626
|
-
_commandFinally(state, this);
|
|
1807
|
+
await _commandFinally(state, this);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
async snapshotValidation(frameSelectors, referanceSnapshot, _params = null, options = {}, world = null) {
|
|
1811
|
+
const timeout = this._getFindElementTimeout(options);
|
|
1812
|
+
const startTime = Date.now();
|
|
1813
|
+
const state = {
|
|
1814
|
+
_params,
|
|
1815
|
+
value: referanceSnapshot,
|
|
1816
|
+
options,
|
|
1817
|
+
world,
|
|
1818
|
+
locate: false,
|
|
1819
|
+
scroll: false,
|
|
1820
|
+
screenshot: true,
|
|
1821
|
+
highlight: false,
|
|
1822
|
+
type: Types.SNAPSHOT_VALIDATION,
|
|
1823
|
+
text: `verify snapshot: ${referanceSnapshot}`,
|
|
1824
|
+
operation: "snapshotValidation",
|
|
1825
|
+
log: "***** verify snapshot *****\n",
|
|
1826
|
+
};
|
|
1827
|
+
if (!referanceSnapshot) {
|
|
1828
|
+
throw new Error("referanceSnapshot is null");
|
|
1829
|
+
}
|
|
1830
|
+
let text = null;
|
|
1831
|
+
if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"))) {
|
|
1832
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"), "utf8");
|
|
1833
|
+
}
|
|
1834
|
+
else if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"))) {
|
|
1835
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"), "utf8");
|
|
1836
|
+
}
|
|
1837
|
+
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1838
|
+
text = referanceSnapshot.substring(5);
|
|
1839
|
+
}
|
|
1840
|
+
else {
|
|
1841
|
+
throw new Error("referenceSnapshot file not found: " + referanceSnapshot);
|
|
1842
|
+
}
|
|
1843
|
+
state.text = text;
|
|
1844
|
+
const newValue = await this._replaceWithLocalData(text, world);
|
|
1845
|
+
await _preCommand(state, this);
|
|
1846
|
+
let foundObj = null;
|
|
1847
|
+
try {
|
|
1848
|
+
let matchResult = null;
|
|
1849
|
+
while (Date.now() - startTime < timeout) {
|
|
1850
|
+
try {
|
|
1851
|
+
let scope = null;
|
|
1852
|
+
if (!frameSelectors) {
|
|
1853
|
+
scope = this.page;
|
|
1854
|
+
}
|
|
1855
|
+
else {
|
|
1856
|
+
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1857
|
+
}
|
|
1858
|
+
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
1859
|
+
matchResult = snapshotValidation(snapshot, newValue, referanceSnapshot);
|
|
1860
|
+
if (matchResult.errorLine !== -1) {
|
|
1861
|
+
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1862
|
+
}
|
|
1863
|
+
// highlight and screenshot
|
|
1864
|
+
try {
|
|
1865
|
+
await await highlightSnapshot(newValue, scope);
|
|
1866
|
+
await _screenshot(state, this);
|
|
1867
|
+
}
|
|
1868
|
+
catch (e) { }
|
|
1869
|
+
return state.info;
|
|
1870
|
+
}
|
|
1871
|
+
catch (e) {
|
|
1872
|
+
// Log error but continue retrying until timeout is reached
|
|
1873
|
+
//this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
1874
|
+
}
|
|
1875
|
+
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 1 second before retrying
|
|
1876
|
+
}
|
|
1877
|
+
throw new Error("No snapshot match " + matchResult?.errorLineText);
|
|
1878
|
+
}
|
|
1879
|
+
catch (e) {
|
|
1880
|
+
await _commandError(state, e, this);
|
|
1881
|
+
throw e;
|
|
1882
|
+
}
|
|
1883
|
+
finally {
|
|
1884
|
+
await _commandFinally(state, this);
|
|
1627
1885
|
}
|
|
1628
1886
|
}
|
|
1629
1887
|
async waitForUserInput(message, world = null) {
|
|
@@ -1766,12 +2024,7 @@ class StableBrowser {
|
|
|
1766
2024
|
}
|
|
1767
2025
|
}
|
|
1768
2026
|
getTestData(world = null) {
|
|
1769
|
-
|
|
1770
|
-
let data = {};
|
|
1771
|
-
if (fs.existsSync(dataFile)) {
|
|
1772
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1773
|
-
}
|
|
1774
|
-
return data;
|
|
2027
|
+
return _getTestData(world, this.context, this);
|
|
1775
2028
|
}
|
|
1776
2029
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1777
2030
|
// collect url/path/title
|
|
@@ -1922,7 +2175,7 @@ class StableBrowser {
|
|
|
1922
2175
|
await _commandError(state, e, this);
|
|
1923
2176
|
}
|
|
1924
2177
|
finally {
|
|
1925
|
-
_commandFinally(state, this);
|
|
2178
|
+
await _commandFinally(state, this);
|
|
1926
2179
|
}
|
|
1927
2180
|
}
|
|
1928
2181
|
async extractAttribute(selectors, attribute, variable, _params = null, options = {}, world = null) {
|
|
@@ -1953,10 +2206,102 @@ class StableBrowser {
|
|
|
1953
2206
|
case "value":
|
|
1954
2207
|
state.value = await state.element.inputValue();
|
|
1955
2208
|
break;
|
|
2209
|
+
case "text":
|
|
2210
|
+
state.value = await state.element.textContent();
|
|
2211
|
+
break;
|
|
1956
2212
|
default:
|
|
1957
2213
|
state.value = await state.element.getAttribute(attribute);
|
|
1958
2214
|
break;
|
|
1959
2215
|
}
|
|
2216
|
+
if (options !== null) {
|
|
2217
|
+
if (options.regex && options.regex !== "") {
|
|
2218
|
+
// Construct a regex pattern from the provided string
|
|
2219
|
+
const regex = options.regex.slice(1, -1);
|
|
2220
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2221
|
+
const matches = state.value.match(regexPattern);
|
|
2222
|
+
if (matches) {
|
|
2223
|
+
let newValue = "";
|
|
2224
|
+
for (const match of matches) {
|
|
2225
|
+
newValue += match;
|
|
2226
|
+
}
|
|
2227
|
+
state.value = newValue;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2231
|
+
state.value = state.value.trim();
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
state.info.value = state.value;
|
|
2235
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2236
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2237
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2238
|
+
return state.info;
|
|
2239
|
+
}
|
|
2240
|
+
catch (e) {
|
|
2241
|
+
await _commandError(state, e, this);
|
|
2242
|
+
}
|
|
2243
|
+
finally {
|
|
2244
|
+
await _commandFinally(state, this);
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2248
|
+
const state = {
|
|
2249
|
+
selectors,
|
|
2250
|
+
_params,
|
|
2251
|
+
property,
|
|
2252
|
+
variable,
|
|
2253
|
+
options,
|
|
2254
|
+
world,
|
|
2255
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2256
|
+
text: `Extract property from element`,
|
|
2257
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2258
|
+
operation: "extractProperty",
|
|
2259
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2260
|
+
allowDisabled: true,
|
|
2261
|
+
};
|
|
2262
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2263
|
+
try {
|
|
2264
|
+
await _preCommand(state, this);
|
|
2265
|
+
switch (property) {
|
|
2266
|
+
case "inner_text":
|
|
2267
|
+
state.value = await state.element.innerText();
|
|
2268
|
+
break;
|
|
2269
|
+
case "href":
|
|
2270
|
+
state.value = await state.element.getAttribute("href");
|
|
2271
|
+
break;
|
|
2272
|
+
case "value":
|
|
2273
|
+
state.value = await state.element.inputValue();
|
|
2274
|
+
break;
|
|
2275
|
+
case "text":
|
|
2276
|
+
state.value = await state.element.textContent();
|
|
2277
|
+
break;
|
|
2278
|
+
default:
|
|
2279
|
+
if (property.startsWith("dataset.")) {
|
|
2280
|
+
const dataAttribute = property.substring(8);
|
|
2281
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2282
|
+
}
|
|
2283
|
+
else {
|
|
2284
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
if (options !== null) {
|
|
2288
|
+
if (options.regex && options.regex !== "") {
|
|
2289
|
+
// Construct a regex pattern from the provided string
|
|
2290
|
+
const regex = options.regex.slice(1, -1);
|
|
2291
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2292
|
+
const matches = state.value.match(regexPattern);
|
|
2293
|
+
if (matches) {
|
|
2294
|
+
let newValue = "";
|
|
2295
|
+
for (const match of matches) {
|
|
2296
|
+
newValue += match;
|
|
2297
|
+
}
|
|
2298
|
+
state.value = newValue;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2302
|
+
state.value = state.value.trim();
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
1960
2305
|
state.info.value = state.value;
|
|
1961
2306
|
this.setTestData({ [variable]: state.value }, world);
|
|
1962
2307
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
@@ -1967,7 +2312,7 @@ class StableBrowser {
|
|
|
1967
2312
|
await _commandError(state, e, this);
|
|
1968
2313
|
}
|
|
1969
2314
|
finally {
|
|
1970
|
-
_commandFinally(state, this);
|
|
2315
|
+
await _commandFinally(state, this);
|
|
1971
2316
|
}
|
|
1972
2317
|
}
|
|
1973
2318
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
@@ -1992,12 +2337,15 @@ class StableBrowser {
|
|
|
1992
2337
|
let expectedValue;
|
|
1993
2338
|
try {
|
|
1994
2339
|
await _preCommand(state, this);
|
|
1995
|
-
expectedValue = state.value;
|
|
2340
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
1996
2341
|
state.info.expectedValue = expectedValue;
|
|
1997
2342
|
switch (attribute) {
|
|
1998
2343
|
case "innerText":
|
|
1999
2344
|
val = String(await state.element.innerText());
|
|
2000
2345
|
break;
|
|
2346
|
+
case "text":
|
|
2347
|
+
val = String(await state.element.textContent());
|
|
2348
|
+
break;
|
|
2001
2349
|
case "value":
|
|
2002
2350
|
val = String(await state.element.inputValue());
|
|
2003
2351
|
break;
|
|
@@ -2019,17 +2367,42 @@ class StableBrowser {
|
|
|
2019
2367
|
let regex;
|
|
2020
2368
|
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2021
2369
|
const patternBody = expectedValue.slice(1, -1);
|
|
2022
|
-
|
|
2370
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2371
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2372
|
+
state.info.regex = true;
|
|
2023
2373
|
}
|
|
2024
2374
|
else {
|
|
2025
2375
|
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2026
2376
|
regex = new RegExp(escapedPattern, "g");
|
|
2027
2377
|
}
|
|
2028
|
-
if (
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2378
|
+
if (attribute === "innerText") {
|
|
2379
|
+
if (state.info.regex) {
|
|
2380
|
+
if (!regex.test(val)) {
|
|
2381
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2382
|
+
state.info.failCause.assertionFailed = true;
|
|
2383
|
+
state.info.failCause.lastError = errorMessage;
|
|
2384
|
+
throw new Error(errorMessage);
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
else {
|
|
2388
|
+
const valLines = val.split("\n");
|
|
2389
|
+
const expectedLines = expectedValue.split("\n");
|
|
2390
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine === expectedLine));
|
|
2391
|
+
if (!isPart) {
|
|
2392
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2393
|
+
state.info.failCause.assertionFailed = true;
|
|
2394
|
+
state.info.failCause.lastError = errorMessage;
|
|
2395
|
+
throw new Error(errorMessage);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
else {
|
|
2400
|
+
if (!val.match(regex)) {
|
|
2401
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2402
|
+
state.info.failCause.assertionFailed = true;
|
|
2403
|
+
state.info.failCause.lastError = errorMessage;
|
|
2404
|
+
throw new Error(errorMessage);
|
|
2405
|
+
}
|
|
2033
2406
|
}
|
|
2034
2407
|
return state.info;
|
|
2035
2408
|
}
|
|
@@ -2037,7 +2410,224 @@ class StableBrowser {
|
|
|
2037
2410
|
await _commandError(state, e, this);
|
|
2038
2411
|
}
|
|
2039
2412
|
finally {
|
|
2040
|
-
_commandFinally(state, this);
|
|
2413
|
+
await _commandFinally(state, this);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2417
|
+
const state = {
|
|
2418
|
+
selectors,
|
|
2419
|
+
_params,
|
|
2420
|
+
property,
|
|
2421
|
+
value,
|
|
2422
|
+
options,
|
|
2423
|
+
world,
|
|
2424
|
+
type: Types.VERIFY_PROPERTY,
|
|
2425
|
+
highlight: true,
|
|
2426
|
+
screenshot: true,
|
|
2427
|
+
text: `Verify element property`,
|
|
2428
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2429
|
+
operation: "verifyProperty",
|
|
2430
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2431
|
+
allowDisabled: true,
|
|
2432
|
+
};
|
|
2433
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2434
|
+
let val;
|
|
2435
|
+
let expectedValue;
|
|
2436
|
+
try {
|
|
2437
|
+
await _preCommand(state, this);
|
|
2438
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2439
|
+
state.info.expectedValue = expectedValue;
|
|
2440
|
+
switch (property) {
|
|
2441
|
+
case "innerText":
|
|
2442
|
+
val = String(await state.element.innerText());
|
|
2443
|
+
break;
|
|
2444
|
+
case "text":
|
|
2445
|
+
val = String(await state.element.textContent());
|
|
2446
|
+
break;
|
|
2447
|
+
case "value":
|
|
2448
|
+
val = String(await state.element.inputValue());
|
|
2449
|
+
break;
|
|
2450
|
+
case "checked":
|
|
2451
|
+
val = String(await state.element.isChecked());
|
|
2452
|
+
break;
|
|
2453
|
+
case "disabled":
|
|
2454
|
+
val = String(await state.element.isDisabled());
|
|
2455
|
+
break;
|
|
2456
|
+
case "readOnly":
|
|
2457
|
+
const isEditable = await state.element.isEditable();
|
|
2458
|
+
val = String(!isEditable);
|
|
2459
|
+
break;
|
|
2460
|
+
case "innerHTML":
|
|
2461
|
+
val = String(await state.element.innerHTML());
|
|
2462
|
+
break;
|
|
2463
|
+
case "outerHTML":
|
|
2464
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2465
|
+
break;
|
|
2466
|
+
default:
|
|
2467
|
+
if (property.startsWith("dataset.")) {
|
|
2468
|
+
const dataAttribute = property.substring(8);
|
|
2469
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2470
|
+
}
|
|
2471
|
+
else {
|
|
2472
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
// Helper function to remove all style="" attributes
|
|
2476
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2477
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2478
|
+
};
|
|
2479
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2480
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2481
|
+
val = removeStyleAttributes(val);
|
|
2482
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2483
|
+
}
|
|
2484
|
+
state.info.value = val;
|
|
2485
|
+
let regex;
|
|
2486
|
+
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2487
|
+
const patternBody = expectedValue.slice(1, -1);
|
|
2488
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2489
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2490
|
+
state.info.regex = true;
|
|
2491
|
+
}
|
|
2492
|
+
else {
|
|
2493
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2494
|
+
regex = new RegExp(escapedPattern, "g");
|
|
2495
|
+
}
|
|
2496
|
+
if (property === "innerText") {
|
|
2497
|
+
if (state.info.regex) {
|
|
2498
|
+
if (!regex.test(val)) {
|
|
2499
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2500
|
+
state.info.failCause.assertionFailed = true;
|
|
2501
|
+
state.info.failCause.lastError = errorMessage;
|
|
2502
|
+
throw new Error(errorMessage);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
else {
|
|
2506
|
+
// Fix: Replace escaped newlines with actual newlines before splitting
|
|
2507
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2508
|
+
const valLines = val.split("\n");
|
|
2509
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2510
|
+
// Check if all expected lines are present in the actual lines
|
|
2511
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2512
|
+
if (!isPart) {
|
|
2513
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2514
|
+
state.info.failCause.assertionFailed = true;
|
|
2515
|
+
state.info.failCause.lastError = errorMessage;
|
|
2516
|
+
throw new Error(errorMessage);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
else {
|
|
2521
|
+
if (!val.match(regex)) {
|
|
2522
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2523
|
+
state.info.failCause.assertionFailed = true;
|
|
2524
|
+
state.info.failCause.lastError = errorMessage;
|
|
2525
|
+
throw new Error(errorMessage);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
return state.info;
|
|
2529
|
+
}
|
|
2530
|
+
catch (e) {
|
|
2531
|
+
await _commandError(state, e, this);
|
|
2532
|
+
}
|
|
2533
|
+
finally {
|
|
2534
|
+
await _commandFinally(state, this);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2538
|
+
// Convert timeout from seconds to milliseconds
|
|
2539
|
+
const timeoutMs = timeout * 1000;
|
|
2540
|
+
const state = {
|
|
2541
|
+
selectors,
|
|
2542
|
+
_params,
|
|
2543
|
+
condition,
|
|
2544
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2545
|
+
options,
|
|
2546
|
+
world,
|
|
2547
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2548
|
+
highlight: true,
|
|
2549
|
+
screenshot: true,
|
|
2550
|
+
text: `Conditional wait for element`,
|
|
2551
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2552
|
+
operation: "conditionalWait",
|
|
2553
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2554
|
+
allowDisabled: true,
|
|
2555
|
+
info: {},
|
|
2556
|
+
};
|
|
2557
|
+
try {
|
|
2558
|
+
await _preCommand(state, this);
|
|
2559
|
+
const startTime = Date.now();
|
|
2560
|
+
let conditionMet = false;
|
|
2561
|
+
let currentValue = null;
|
|
2562
|
+
const checkCondition = async () => {
|
|
2563
|
+
try {
|
|
2564
|
+
switch (condition.toLowerCase()) {
|
|
2565
|
+
case "checked":
|
|
2566
|
+
currentValue = await state.element.isChecked();
|
|
2567
|
+
return currentValue === true;
|
|
2568
|
+
case "unchecked":
|
|
2569
|
+
currentValue = await state.element.isChecked();
|
|
2570
|
+
return currentValue === false;
|
|
2571
|
+
case "visible":
|
|
2572
|
+
currentValue = await state.element.isVisible();
|
|
2573
|
+
return currentValue === true;
|
|
2574
|
+
case "hidden":
|
|
2575
|
+
currentValue = await state.element.isVisible();
|
|
2576
|
+
return currentValue === false;
|
|
2577
|
+
case "enabled":
|
|
2578
|
+
currentValue = await state.element.isDisabled();
|
|
2579
|
+
return currentValue === false;
|
|
2580
|
+
case "disabled":
|
|
2581
|
+
currentValue = await state.element.isDisabled();
|
|
2582
|
+
return currentValue === true;
|
|
2583
|
+
case "editable":
|
|
2584
|
+
currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2585
|
+
return currentValue === true;
|
|
2586
|
+
default:
|
|
2587
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2588
|
+
state.info.success = false;
|
|
2589
|
+
return false;
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
catch {
|
|
2593
|
+
return false;
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2597
|
+
// Use milliseconds for comparison
|
|
2598
|
+
conditionMet = await checkCondition();
|
|
2599
|
+
if (conditionMet)
|
|
2600
|
+
break;
|
|
2601
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2602
|
+
}
|
|
2603
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2604
|
+
state.info = {
|
|
2605
|
+
success: conditionMet,
|
|
2606
|
+
conditionMet,
|
|
2607
|
+
actualWaitTime,
|
|
2608
|
+
currentValue,
|
|
2609
|
+
message: conditionMet
|
|
2610
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2611
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`, // Use original seconds value
|
|
2612
|
+
};
|
|
2613
|
+
state.log += state.info.message + "\n";
|
|
2614
|
+
return state.info;
|
|
2615
|
+
}
|
|
2616
|
+
catch (e) {
|
|
2617
|
+
state.info = {
|
|
2618
|
+
success: false,
|
|
2619
|
+
conditionMet: false,
|
|
2620
|
+
actualWaitTime: timeoutMs, // Store as milliseconds
|
|
2621
|
+
currentValue: null,
|
|
2622
|
+
error: e.message,
|
|
2623
|
+
message: `Error during conditional wait: ${e.message}`,
|
|
2624
|
+
};
|
|
2625
|
+
state.log += `Error during conditional wait: ${e.message}\n`;
|
|
2626
|
+
await new Promise((resolve) => setTimeout(resolve, timeoutMs)); // Use milliseconds
|
|
2627
|
+
return state.info;
|
|
2628
|
+
}
|
|
2629
|
+
finally {
|
|
2630
|
+
await _commandFinally(state, this);
|
|
2041
2631
|
}
|
|
2042
2632
|
}
|
|
2043
2633
|
async extractEmailData(emailAddress, options, world) {
|
|
@@ -2197,56 +2787,49 @@ class StableBrowser {
|
|
|
2197
2787
|
console.debug(error);
|
|
2198
2788
|
}
|
|
2199
2789
|
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
// });
|
|
2243
|
-
// }
|
|
2244
|
-
// } catch (error) {
|
|
2245
|
-
// // console.debug(error);
|
|
2246
|
-
// }
|
|
2247
|
-
// }
|
|
2790
|
+
_matcher(text) {
|
|
2791
|
+
if (!text) {
|
|
2792
|
+
return { matcher: "contains", queryText: "" };
|
|
2793
|
+
}
|
|
2794
|
+
if (text.length < 2) {
|
|
2795
|
+
return { matcher: "contains", queryText: text };
|
|
2796
|
+
}
|
|
2797
|
+
const split = text.split(":");
|
|
2798
|
+
const matcher = split[0].toLowerCase();
|
|
2799
|
+
const queryText = split.slice(1).join(":").trim();
|
|
2800
|
+
return { matcher, queryText };
|
|
2801
|
+
}
|
|
2802
|
+
_getDomain(url) {
|
|
2803
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
2804
|
+
return "";
|
|
2805
|
+
}
|
|
2806
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
2807
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
2808
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
2809
|
+
}
|
|
2810
|
+
let n = hostnameFragments.length;
|
|
2811
|
+
let fragments = [...hostnameFragments];
|
|
2812
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
2813
|
+
hostnameFragments.pop();
|
|
2814
|
+
n = hostnameFragments.length;
|
|
2815
|
+
}
|
|
2816
|
+
if (n == 0) {
|
|
2817
|
+
if (fragments[0] === "www")
|
|
2818
|
+
fragments = fragments.slice(1);
|
|
2819
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
2820
|
+
}
|
|
2821
|
+
if (hostnameFragments[0] === "www")
|
|
2822
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
2823
|
+
return hostnameFragments.join(".");
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
* Verify the page path matches the given path.
|
|
2827
|
+
* @param {string} pathPart - The path to verify.
|
|
2828
|
+
* @param {object} options - Options for verification.
|
|
2829
|
+
* @param {object} world - The world context.
|
|
2830
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2831
|
+
*/
|
|
2248
2832
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2249
|
-
const startTime = Date.now();
|
|
2250
2833
|
let error = null;
|
|
2251
2834
|
let screenshotId = null;
|
|
2252
2835
|
let screenshotPath = null;
|
|
@@ -2260,113 +2843,212 @@ class StableBrowser {
|
|
|
2260
2843
|
pathPart = newValue;
|
|
2261
2844
|
}
|
|
2262
2845
|
info.pathPart = pathPart;
|
|
2846
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
2847
|
+
const state = {
|
|
2848
|
+
text_search: queryText,
|
|
2849
|
+
options,
|
|
2850
|
+
world,
|
|
2851
|
+
locate: false,
|
|
2852
|
+
scroll: false,
|
|
2853
|
+
highlight: false,
|
|
2854
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
2855
|
+
text: `Verify the page url is ${queryText}`,
|
|
2856
|
+
_text: `Verify the page url is ${queryText}`,
|
|
2857
|
+
operation: "verifyPagePath",
|
|
2858
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
2859
|
+
};
|
|
2263
2860
|
try {
|
|
2861
|
+
await _preCommand(state, this);
|
|
2862
|
+
state.info.text = queryText;
|
|
2264
2863
|
for (let i = 0; i < 30; i++) {
|
|
2265
2864
|
const url = await this.page.url();
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2865
|
+
switch (matcher) {
|
|
2866
|
+
case "exact":
|
|
2867
|
+
if (url !== queryText) {
|
|
2868
|
+
if (i === 29) {
|
|
2869
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
2870
|
+
}
|
|
2871
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2872
|
+
continue;
|
|
2873
|
+
}
|
|
2874
|
+
break;
|
|
2875
|
+
case "contains":
|
|
2876
|
+
if (!url.includes(queryText)) {
|
|
2877
|
+
if (i === 29) {
|
|
2878
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
2879
|
+
}
|
|
2880
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2881
|
+
continue;
|
|
2882
|
+
}
|
|
2883
|
+
break;
|
|
2884
|
+
case "starts-with":
|
|
2885
|
+
{
|
|
2886
|
+
const domain = this._getDomain(url);
|
|
2887
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
2888
|
+
if (i === 29) {
|
|
2889
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
2890
|
+
}
|
|
2891
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2892
|
+
continue;
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
break;
|
|
2896
|
+
case "ends-with":
|
|
2897
|
+
{
|
|
2898
|
+
const urlObj = new URL(url);
|
|
2899
|
+
let route = "/";
|
|
2900
|
+
if (urlObj.pathname !== "/") {
|
|
2901
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
2902
|
+
}
|
|
2903
|
+
else {
|
|
2904
|
+
route = "/";
|
|
2905
|
+
}
|
|
2906
|
+
if (route !== queryText) {
|
|
2907
|
+
if (i === 29) {
|
|
2908
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
2909
|
+
}
|
|
2910
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2911
|
+
continue;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
break;
|
|
2915
|
+
case "regex":
|
|
2916
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
2917
|
+
if (!regex.test(url)) {
|
|
2918
|
+
if (i === 29) {
|
|
2919
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
2920
|
+
}
|
|
2921
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
break;
|
|
2925
|
+
default:
|
|
2926
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
2927
|
+
if (!url.includes(pathPart)) {
|
|
2928
|
+
if (i === 29) {
|
|
2929
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
2930
|
+
}
|
|
2931
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2932
|
+
continue;
|
|
2933
|
+
}
|
|
2272
2934
|
}
|
|
2273
|
-
|
|
2274
|
-
return info;
|
|
2935
|
+
await _screenshot(state, this);
|
|
2936
|
+
return state.info;
|
|
2275
2937
|
}
|
|
2276
2938
|
}
|
|
2277
2939
|
catch (e) {
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
info.screenshotPath = screenshotPath;
|
|
2282
|
-
Object.assign(e, { info: info });
|
|
2283
|
-
error = e;
|
|
2284
|
-
// throw e;
|
|
2285
|
-
await _commandError({ text: "verifyPagePath", operation: "verifyPagePath", pathPart, info }, e, this);
|
|
2940
|
+
state.info.failCause.lastError = e.message;
|
|
2941
|
+
state.info.failCause.assertionFailed = true;
|
|
2942
|
+
await _commandError(state, e, this);
|
|
2286
2943
|
}
|
|
2287
2944
|
finally {
|
|
2288
|
-
|
|
2289
|
-
_reportToWorld(world, {
|
|
2290
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2291
|
-
text: "Verify page path",
|
|
2292
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2293
|
-
screenshotId,
|
|
2294
|
-
result: error
|
|
2295
|
-
? {
|
|
2296
|
-
status: "FAILED",
|
|
2297
|
-
startTime,
|
|
2298
|
-
endTime,
|
|
2299
|
-
message: error?.message,
|
|
2300
|
-
}
|
|
2301
|
-
: {
|
|
2302
|
-
status: "PASSED",
|
|
2303
|
-
startTime,
|
|
2304
|
-
endTime,
|
|
2305
|
-
},
|
|
2306
|
-
info: info,
|
|
2307
|
-
});
|
|
2945
|
+
await _commandFinally(state, this);
|
|
2308
2946
|
}
|
|
2309
2947
|
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Verify the page title matches the given title.
|
|
2950
|
+
* @param {string} title - The title to verify.
|
|
2951
|
+
* @param {object} options - Options for verification.
|
|
2952
|
+
* @param {object} world - The world context.
|
|
2953
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2954
|
+
*/
|
|
2310
2955
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2311
|
-
const startTime = Date.now();
|
|
2312
2956
|
let error = null;
|
|
2313
2957
|
let screenshotId = null;
|
|
2314
2958
|
let screenshotPath = null;
|
|
2315
2959
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2316
|
-
const info = {};
|
|
2317
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2318
|
-
info.operation = "verifyPageTitle";
|
|
2319
2960
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2320
2961
|
if (newValue !== title) {
|
|
2321
2962
|
this.logger.info(title + "=" + newValue);
|
|
2322
2963
|
title = newValue;
|
|
2323
2964
|
}
|
|
2324
|
-
|
|
2965
|
+
const { matcher, queryText } = this._matcher(title);
|
|
2966
|
+
const state = {
|
|
2967
|
+
text_search: queryText,
|
|
2968
|
+
options,
|
|
2969
|
+
world,
|
|
2970
|
+
locate: false,
|
|
2971
|
+
scroll: false,
|
|
2972
|
+
highlight: false,
|
|
2973
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
2974
|
+
text: `Verify the page title is ${queryText}`,
|
|
2975
|
+
_text: `Verify the page title is ${queryText}`,
|
|
2976
|
+
operation: "verifyPageTitle",
|
|
2977
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
2978
|
+
};
|
|
2325
2979
|
try {
|
|
2980
|
+
await _preCommand(state, this);
|
|
2981
|
+
state.info.text = queryText;
|
|
2326
2982
|
for (let i = 0; i < 30; i++) {
|
|
2327
2983
|
const foundTitle = await this.page.title();
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2984
|
+
switch (matcher) {
|
|
2985
|
+
case "exact":
|
|
2986
|
+
if (foundTitle !== queryText) {
|
|
2987
|
+
if (i === 29) {
|
|
2988
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
2989
|
+
}
|
|
2990
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2991
|
+
continue;
|
|
2992
|
+
}
|
|
2993
|
+
break;
|
|
2994
|
+
case "contains":
|
|
2995
|
+
if (!foundTitle.includes(queryText)) {
|
|
2996
|
+
if (i === 29) {
|
|
2997
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
2998
|
+
}
|
|
2999
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3000
|
+
continue;
|
|
3001
|
+
}
|
|
3002
|
+
break;
|
|
3003
|
+
case "starts-with":
|
|
3004
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3005
|
+
if (i === 29) {
|
|
3006
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3007
|
+
}
|
|
3008
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3009
|
+
continue;
|
|
3010
|
+
}
|
|
3011
|
+
break;
|
|
3012
|
+
case "ends-with":
|
|
3013
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3014
|
+
if (i === 29) {
|
|
3015
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3016
|
+
}
|
|
3017
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3018
|
+
continue;
|
|
3019
|
+
}
|
|
3020
|
+
break;
|
|
3021
|
+
case "regex":
|
|
3022
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3023
|
+
if (!regex.test(foundTitle)) {
|
|
3024
|
+
if (i === 29) {
|
|
3025
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3026
|
+
}
|
|
3027
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3028
|
+
continue;
|
|
3029
|
+
}
|
|
3030
|
+
break;
|
|
3031
|
+
default:
|
|
3032
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3033
|
+
if (!foundTitle.includes(title)) {
|
|
3034
|
+
if (i === 29) {
|
|
3035
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3036
|
+
}
|
|
3037
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3038
|
+
continue;
|
|
3039
|
+
}
|
|
2334
3040
|
}
|
|
2335
|
-
|
|
2336
|
-
return info;
|
|
3041
|
+
await _screenshot(state, this);
|
|
3042
|
+
return state.info;
|
|
2337
3043
|
}
|
|
2338
3044
|
}
|
|
2339
3045
|
catch (e) {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
info.screenshotPath = screenshotPath;
|
|
2344
|
-
Object.assign(e, { info: info });
|
|
2345
|
-
error = e;
|
|
2346
|
-
// throw e;
|
|
2347
|
-
await _commandError({ text: "verifyPageTitle", operation: "verifyPageTitle", title, info, throwError: true }, e, this);
|
|
3046
|
+
state.info.failCause.lastError = e.message;
|
|
3047
|
+
state.info.failCause.assertionFailed = true;
|
|
3048
|
+
await _commandError(state, e, this);
|
|
2348
3049
|
}
|
|
2349
3050
|
finally {
|
|
2350
|
-
|
|
2351
|
-
_reportToWorld(world, {
|
|
2352
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2353
|
-
text: "Verify page title",
|
|
2354
|
-
_text: "Verify the page title contains " + title,
|
|
2355
|
-
screenshotId,
|
|
2356
|
-
result: error
|
|
2357
|
-
? {
|
|
2358
|
-
status: "FAILED",
|
|
2359
|
-
startTime,
|
|
2360
|
-
endTime,
|
|
2361
|
-
message: error?.message,
|
|
2362
|
-
}
|
|
2363
|
-
: {
|
|
2364
|
-
status: "PASSED",
|
|
2365
|
-
startTime,
|
|
2366
|
-
endTime,
|
|
2367
|
-
},
|
|
2368
|
-
info: info,
|
|
2369
|
-
});
|
|
3051
|
+
await _commandFinally(state, this);
|
|
2370
3052
|
}
|
|
2371
3053
|
}
|
|
2372
3054
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2408,7 +3090,7 @@ class StableBrowser {
|
|
|
2408
3090
|
scroll: false,
|
|
2409
3091
|
highlight: false,
|
|
2410
3092
|
type: Types.VERIFY_PAGE_CONTAINS_TEXT,
|
|
2411
|
-
text: `Verify the text '${text}' exists in page`,
|
|
3093
|
+
text: `Verify the text '${maskValue(text)}' exists in page`,
|
|
2412
3094
|
_text: `Verify the text '${text}' exists in page`,
|
|
2413
3095
|
operation: "verifyTextExistInPage",
|
|
2414
3096
|
log: "***** verify text " + text + " exists in page *****\n",
|
|
@@ -2450,27 +3132,10 @@ class StableBrowser {
|
|
|
2450
3132
|
const frame = resultWithElementsFound[0].frame;
|
|
2451
3133
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2452
3134
|
await this._highlightElements(frame, dataAttribute);
|
|
2453
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2454
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2455
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2456
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2457
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2458
|
-
// .then(async () => {
|
|
2459
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2460
|
-
// })
|
|
2461
|
-
// .catch(
|
|
2462
|
-
// (e) => {}
|
|
2463
|
-
// console.error(e)
|
|
2464
|
-
// );
|
|
2465
|
-
// });
|
|
2466
|
-
// }
|
|
2467
3135
|
const element = await frame.locator(dataAttribute).first();
|
|
2468
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2469
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2470
3136
|
if (element) {
|
|
2471
3137
|
await this.scrollIfNeeded(element, state.info);
|
|
2472
3138
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2473
|
-
// await _screenshot(state, this, element);
|
|
2474
3139
|
}
|
|
2475
3140
|
}
|
|
2476
3141
|
await _screenshot(state, this);
|
|
@@ -2480,13 +3145,12 @@ class StableBrowser {
|
|
|
2480
3145
|
console.error(error);
|
|
2481
3146
|
}
|
|
2482
3147
|
}
|
|
2483
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2484
3148
|
}
|
|
2485
3149
|
catch (e) {
|
|
2486
3150
|
await _commandError(state, e, this);
|
|
2487
3151
|
}
|
|
2488
3152
|
finally {
|
|
2489
|
-
_commandFinally(state, this);
|
|
3153
|
+
await _commandFinally(state, this);
|
|
2490
3154
|
}
|
|
2491
3155
|
}
|
|
2492
3156
|
async waitForTextToDisappear(text, options = {}, world = null) {
|
|
@@ -2499,7 +3163,7 @@ class StableBrowser {
|
|
|
2499
3163
|
scroll: false,
|
|
2500
3164
|
highlight: false,
|
|
2501
3165
|
type: Types.WAIT_FOR_TEXT_TO_DISAPPEAR,
|
|
2502
|
-
text: `Verify the text '${text}' does not exist in page`,
|
|
3166
|
+
text: `Verify the text '${maskValue(text)}' does not exist in page`,
|
|
2503
3167
|
_text: `Verify the text '${text}' does not exist in page`,
|
|
2504
3168
|
operation: "verifyTextNotExistInPage",
|
|
2505
3169
|
log: "***** verify text " + text + " does not exist in page *****\n",
|
|
@@ -2543,7 +3207,7 @@ class StableBrowser {
|
|
|
2543
3207
|
await _commandError(state, e, this);
|
|
2544
3208
|
}
|
|
2545
3209
|
finally {
|
|
2546
|
-
_commandFinally(state, this);
|
|
3210
|
+
await _commandFinally(state, this);
|
|
2547
3211
|
}
|
|
2548
3212
|
}
|
|
2549
3213
|
async verifyTextRelatedToText(textAnchor, climb, textToVerify, options = {}, world = null) {
|
|
@@ -2654,7 +3318,7 @@ class StableBrowser {
|
|
|
2654
3318
|
await _commandError(state, e, this);
|
|
2655
3319
|
}
|
|
2656
3320
|
finally {
|
|
2657
|
-
_commandFinally(state, this);
|
|
3321
|
+
await _commandFinally(state, this);
|
|
2658
3322
|
}
|
|
2659
3323
|
}
|
|
2660
3324
|
async findRelatedTextInAllFrames(textAnchor, climb, textToVerify, params = {}, options = {}, world = null) {
|
|
@@ -2996,8 +3660,51 @@ class StableBrowser {
|
|
|
2996
3660
|
});
|
|
2997
3661
|
}
|
|
2998
3662
|
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3665
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3666
|
+
* @param options - Optional configuration object
|
|
3667
|
+
* @param world - Optional world context
|
|
3668
|
+
* @returns Promise that resolves after the specified duration
|
|
3669
|
+
*/
|
|
3670
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3671
|
+
const state = {
|
|
3672
|
+
duration,
|
|
3673
|
+
options,
|
|
3674
|
+
world,
|
|
3675
|
+
locate: false,
|
|
3676
|
+
scroll: false,
|
|
3677
|
+
screenshot: false,
|
|
3678
|
+
highlight: false,
|
|
3679
|
+
type: Types.SLEEP,
|
|
3680
|
+
text: `Sleep for ${duration} ms`,
|
|
3681
|
+
_text: `Sleep for ${duration} ms`,
|
|
3682
|
+
operation: "sleep",
|
|
3683
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3684
|
+
};
|
|
3685
|
+
try {
|
|
3686
|
+
await _preCommand(state, this);
|
|
3687
|
+
if (duration < 0) {
|
|
3688
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3689
|
+
}
|
|
3690
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3691
|
+
return state.info;
|
|
3692
|
+
}
|
|
3693
|
+
catch (e) {
|
|
3694
|
+
await _commandError(state, e, this);
|
|
3695
|
+
}
|
|
3696
|
+
finally {
|
|
3697
|
+
await _commandFinally(state, this);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
2999
3700
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3000
|
-
|
|
3701
|
+
try {
|
|
3702
|
+
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
3703
|
+
}
|
|
3704
|
+
catch (error) {
|
|
3705
|
+
this.logger.debug(error);
|
|
3706
|
+
throw error;
|
|
3707
|
+
}
|
|
3001
3708
|
}
|
|
3002
3709
|
_getLoadTimeout(options) {
|
|
3003
3710
|
let timeout = 15000;
|
|
@@ -3020,6 +3727,7 @@ class StableBrowser {
|
|
|
3020
3727
|
}
|
|
3021
3728
|
async saveStoreState(path = null, world = null) {
|
|
3022
3729
|
const storageState = await this.page.context().storageState();
|
|
3730
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3023
3731
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3024
3732
|
if (path) {
|
|
3025
3733
|
// save { storageState: storageState } into the path
|
|
@@ -3030,10 +3738,14 @@ class StableBrowser {
|
|
|
3030
3738
|
}
|
|
3031
3739
|
}
|
|
3032
3740
|
async restoreSaveState(path = null, world = null) {
|
|
3741
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3033
3742
|
await refreshBrowser(this, path, world);
|
|
3034
3743
|
this.registerEventListeners(this.context);
|
|
3035
3744
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
3036
3745
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
3746
|
+
if (this.onRestoreSaveState) {
|
|
3747
|
+
this.onRestoreSaveState(path);
|
|
3748
|
+
}
|
|
3037
3749
|
}
|
|
3038
3750
|
async waitForPageLoad(options = {}, world = null) {
|
|
3039
3751
|
let timeout = this._getLoadTimeout(options);
|
|
@@ -3068,7 +3780,6 @@ class StableBrowser {
|
|
|
3068
3780
|
else if (e.label === "domcontentloaded") {
|
|
3069
3781
|
console.log("waited for the domcontent loaded timeout");
|
|
3070
3782
|
}
|
|
3071
|
-
console.log(".");
|
|
3072
3783
|
}
|
|
3073
3784
|
finally {
|
|
3074
3785
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -3112,11 +3823,10 @@ class StableBrowser {
|
|
|
3112
3823
|
await this.page.close();
|
|
3113
3824
|
}
|
|
3114
3825
|
catch (e) {
|
|
3115
|
-
console.log(".");
|
|
3116
3826
|
await _commandError(state, e, this);
|
|
3117
3827
|
}
|
|
3118
3828
|
finally {
|
|
3119
|
-
_commandFinally(state, this);
|
|
3829
|
+
await _commandFinally(state, this);
|
|
3120
3830
|
}
|
|
3121
3831
|
}
|
|
3122
3832
|
async tableCellOperation(headerText, rowText, options, _params, world = null) {
|
|
@@ -3203,7 +3913,7 @@ class StableBrowser {
|
|
|
3203
3913
|
await _commandError(state, e, this);
|
|
3204
3914
|
}
|
|
3205
3915
|
finally {
|
|
3206
|
-
_commandFinally(state, this);
|
|
3916
|
+
await _commandFinally(state, this);
|
|
3207
3917
|
}
|
|
3208
3918
|
}
|
|
3209
3919
|
saveTestDataAsGlobal(options, world) {
|
|
@@ -3227,7 +3937,6 @@ class StableBrowser {
|
|
|
3227
3937
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3228
3938
|
}
|
|
3229
3939
|
catch (e) {
|
|
3230
|
-
console.log(".");
|
|
3231
3940
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3232
3941
|
}
|
|
3233
3942
|
finally {
|
|
@@ -3265,7 +3974,6 @@ class StableBrowser {
|
|
|
3265
3974
|
await this.page.reload();
|
|
3266
3975
|
}
|
|
3267
3976
|
catch (e) {
|
|
3268
|
-
console.log(".");
|
|
3269
3977
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3270
3978
|
}
|
|
3271
3979
|
finally {
|
|
@@ -3308,7 +4016,39 @@ class StableBrowser {
|
|
|
3308
4016
|
console.log("#-#");
|
|
3309
4017
|
}
|
|
3310
4018
|
}
|
|
4019
|
+
async beforeScenario(world, scenario) {
|
|
4020
|
+
this.beforeScenarioCalled = true;
|
|
4021
|
+
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
4022
|
+
this.scenarioName = scenario.pickle.name;
|
|
4023
|
+
}
|
|
4024
|
+
if (scenario && scenario.gherkinDocument && scenario.gherkinDocument.feature) {
|
|
4025
|
+
this.featureName = scenario.gherkinDocument.feature.name;
|
|
4026
|
+
}
|
|
4027
|
+
if (this.context) {
|
|
4028
|
+
this.context.examplesRow = extractStepExampleParameters(scenario);
|
|
4029
|
+
}
|
|
4030
|
+
if (this.tags === null && scenario && scenario.pickle && scenario.pickle.tags) {
|
|
4031
|
+
this.tags = scenario.pickle.tags.map((tag) => tag.name);
|
|
4032
|
+
// check if @global_test_data tag is present
|
|
4033
|
+
if (this.tags.includes("@global_test_data")) {
|
|
4034
|
+
this.saveTestDataAsGlobal({}, world);
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
// update test data based on feature/scenario
|
|
4038
|
+
let envName = null;
|
|
4039
|
+
if (this.context && this.context.environment) {
|
|
4040
|
+
envName = this.context.environment.name;
|
|
4041
|
+
}
|
|
4042
|
+
if (!process.env.TEMP_RUN) {
|
|
4043
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
4044
|
+
}
|
|
4045
|
+
await loadBrunoParams(this.context, this.context.environment.name);
|
|
4046
|
+
}
|
|
4047
|
+
async afterScenario(world, scenario) { }
|
|
3311
4048
|
async beforeStep(world, step) {
|
|
4049
|
+
if (!this.beforeScenarioCalled) {
|
|
4050
|
+
this.beforeScenario(world, step);
|
|
4051
|
+
}
|
|
3312
4052
|
if (this.stepIndex === undefined) {
|
|
3313
4053
|
this.stepIndex = 0;
|
|
3314
4054
|
}
|
|
@@ -3325,30 +4065,22 @@ class StableBrowser {
|
|
|
3325
4065
|
else {
|
|
3326
4066
|
this.stepName = "step " + this.stepIndex;
|
|
3327
4067
|
}
|
|
3328
|
-
if (this.context) {
|
|
3329
|
-
this.context.examplesRow = extractStepExampleParameters(step);
|
|
3330
|
-
}
|
|
3331
4068
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
3332
4069
|
if (this.context.browserObject.context) {
|
|
3333
4070
|
await this.context.browserObject.context.tracing.startChunk({ title: this.stepName });
|
|
3334
4071
|
}
|
|
3335
4072
|
}
|
|
3336
|
-
if (this.tags === null && step && step.pickle && step.pickle.tags) {
|
|
3337
|
-
this.tags = step.pickle.tags.map((tag) => tag.name);
|
|
3338
|
-
// check if @global_test_data tag is present
|
|
3339
|
-
if (this.tags.includes("@global_test_data")) {
|
|
3340
|
-
this.saveTestDataAsGlobal({}, world);
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
4073
|
if (this.initSnapshotTaken === false) {
|
|
3344
4074
|
this.initSnapshotTaken = true;
|
|
3345
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4075
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3346
4076
|
const snapshot = await this.getAriaSnapshot();
|
|
3347
4077
|
if (snapshot) {
|
|
3348
4078
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3349
4079
|
}
|
|
3350
4080
|
}
|
|
3351
4081
|
}
|
|
4082
|
+
this.context.routeResults = null;
|
|
4083
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
3352
4084
|
}
|
|
3353
4085
|
async getAriaSnapshot() {
|
|
3354
4086
|
try {
|
|
@@ -3364,18 +4096,68 @@ class StableBrowser {
|
|
|
3364
4096
|
const content = [`- path: ${path}`, `- title: ${title}`];
|
|
3365
4097
|
const timeout = this.configuration.ariaSnapshotTimeout ? this.configuration.ariaSnapshotTimeout : 3000;
|
|
3366
4098
|
for (let i = 0; i < frames.length; i++) {
|
|
3367
|
-
content.push(`- frame: ${i}`);
|
|
3368
4099
|
const frame = frames[i];
|
|
3369
|
-
|
|
3370
|
-
|
|
4100
|
+
try {
|
|
4101
|
+
// Ensure frame is attached and has body
|
|
4102
|
+
const body = frame.locator("body");
|
|
4103
|
+
await body.waitFor({ timeout: 200 }); // wait explicitly
|
|
4104
|
+
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4105
|
+
content.push(`- frame: ${i}`);
|
|
4106
|
+
content.push(snapshot);
|
|
4107
|
+
}
|
|
4108
|
+
catch (innerErr) { }
|
|
3371
4109
|
}
|
|
3372
4110
|
return content.join("\n");
|
|
3373
4111
|
}
|
|
3374
4112
|
catch (e) {
|
|
3375
|
-
console.
|
|
4113
|
+
console.log("Error in getAriaSnapshot");
|
|
4114
|
+
//console.debug(e);
|
|
3376
4115
|
}
|
|
3377
4116
|
return null;
|
|
3378
4117
|
}
|
|
4118
|
+
/**
|
|
4119
|
+
* Sends command with custom payload to report.
|
|
4120
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4121
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4122
|
+
* @param content - Content of the command to be shown in the report.
|
|
4123
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4124
|
+
* @param world - Optional world context.
|
|
4125
|
+
* @public
|
|
4126
|
+
*/
|
|
4127
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4128
|
+
const state = {
|
|
4129
|
+
options,
|
|
4130
|
+
world,
|
|
4131
|
+
locate: false,
|
|
4132
|
+
scroll: false,
|
|
4133
|
+
screenshot: options.screenshot ?? false,
|
|
4134
|
+
highlight: options.highlight ?? false,
|
|
4135
|
+
type: Types.REPORT_COMMAND,
|
|
4136
|
+
text: commandText,
|
|
4137
|
+
_text: commandText,
|
|
4138
|
+
operation: "report_command",
|
|
4139
|
+
log: "***** " + commandText + " *****\n",
|
|
4140
|
+
};
|
|
4141
|
+
try {
|
|
4142
|
+
await _preCommand(state, this);
|
|
4143
|
+
const payload = {
|
|
4144
|
+
type: options.type ?? "text",
|
|
4145
|
+
content: content,
|
|
4146
|
+
screenshotId: null,
|
|
4147
|
+
};
|
|
4148
|
+
state.payload = payload;
|
|
4149
|
+
if (commandStatus === "FAILED") {
|
|
4150
|
+
state.throwError = true;
|
|
4151
|
+
throw new Error("Command failed");
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
catch (e) {
|
|
4155
|
+
await _commandError(state, e, this);
|
|
4156
|
+
}
|
|
4157
|
+
finally {
|
|
4158
|
+
await _commandFinally(state, this);
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
3379
4161
|
async afterStep(world, step) {
|
|
3380
4162
|
this.stepName = null;
|
|
3381
4163
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3383,10 +4165,12 @@ class StableBrowser {
|
|
|
3383
4165
|
await this.context.browserObject.context.tracing.stopChunk({
|
|
3384
4166
|
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
3385
4167
|
});
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
4168
|
+
if (world && world.attach) {
|
|
4169
|
+
await world.attach(JSON.stringify({
|
|
4170
|
+
type: "trace",
|
|
4171
|
+
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4172
|
+
}), "application/json+trace");
|
|
4173
|
+
}
|
|
3390
4174
|
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
3391
4175
|
}
|
|
3392
4176
|
}
|
|
@@ -3400,6 +4184,30 @@ class StableBrowser {
|
|
|
3400
4184
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3401
4185
|
}
|
|
3402
4186
|
}
|
|
4187
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4188
|
+
if (!process.env.TEMP_RUN) {
|
|
4189
|
+
const state = {
|
|
4190
|
+
world,
|
|
4191
|
+
locate: false,
|
|
4192
|
+
scroll: false,
|
|
4193
|
+
screenshot: true,
|
|
4194
|
+
highlight: true,
|
|
4195
|
+
type: Types.STEP_COMPLETE,
|
|
4196
|
+
text: "end of scenario",
|
|
4197
|
+
_text: "end of scenario",
|
|
4198
|
+
operation: "step_complete",
|
|
4199
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4200
|
+
};
|
|
4201
|
+
try {
|
|
4202
|
+
await _preCommand(state, this);
|
|
4203
|
+
}
|
|
4204
|
+
catch (e) {
|
|
4205
|
+
await _commandError(state, e, this);
|
|
4206
|
+
}
|
|
4207
|
+
finally {
|
|
4208
|
+
await _commandFinally(state, this);
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
3403
4211
|
}
|
|
3404
4212
|
}
|
|
3405
4213
|
function createTimedPromise(promise, label) {
|