automation_model 1.0.660-dev → 1.0.660-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 +3 -1
- package/lib/analyze_helper.js.map +1 -1
- package/lib/api.d.ts +0 -1
- package/lib/api.js +6 -3
- 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 +2 -0
- package/lib/bruno.js +381 -0
- package/lib/bruno.js.map +1 -0
- 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 +268 -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 +64 -25
- package/lib/stable_browser.js +1036 -223
- 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 +16 -2
- package/lib/utils.js +104 -58
- package/lib/utils.js.map +1 -1
- package/package.json +13 -6
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",
|
|
@@ -55,6 +62,14 @@ export const Types = {
|
|
|
55
62
|
WAIT_FOR_TEXT_TO_DISAPPEAR: "wait_for_text_to_disappear",
|
|
56
63
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
57
64
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
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",
|
|
58
73
|
};
|
|
59
74
|
export const apps = {};
|
|
60
75
|
const formatElementName = (elementName) => {
|
|
@@ -66,6 +81,7 @@ class StableBrowser {
|
|
|
66
81
|
logger;
|
|
67
82
|
context;
|
|
68
83
|
world;
|
|
84
|
+
fastMode;
|
|
69
85
|
project_path = null;
|
|
70
86
|
webLogFile = null;
|
|
71
87
|
networkLogger = null;
|
|
@@ -74,12 +90,13 @@ class StableBrowser {
|
|
|
74
90
|
tags = null;
|
|
75
91
|
isRecording = false;
|
|
76
92
|
initSnapshotTaken = false;
|
|
77
|
-
constructor(browser, page, logger = null, context = null, world = null) {
|
|
93
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
78
94
|
this.browser = browser;
|
|
79
95
|
this.page = page;
|
|
80
96
|
this.logger = logger;
|
|
81
97
|
this.context = context;
|
|
82
98
|
this.world = world;
|
|
99
|
+
this.fastMode = fastMode;
|
|
83
100
|
if (!this.logger) {
|
|
84
101
|
this.logger = console;
|
|
85
102
|
}
|
|
@@ -108,6 +125,18 @@ class StableBrowser {
|
|
|
108
125
|
context.pages = [this.page];
|
|
109
126
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
110
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
|
+
}
|
|
111
140
|
this.registerEventListeners(this.context);
|
|
112
141
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
113
142
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -118,6 +147,9 @@ class StableBrowser {
|
|
|
118
147
|
if (!context.pageLoading) {
|
|
119
148
|
context.pageLoading = { status: false };
|
|
120
149
|
}
|
|
150
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
151
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
152
|
+
}
|
|
121
153
|
context.playContext.on("page", async function (page) {
|
|
122
154
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
123
155
|
console.log("close unexpected popups");
|
|
@@ -126,6 +158,14 @@ class StableBrowser {
|
|
|
126
158
|
}
|
|
127
159
|
context.pageLoading.status = true;
|
|
128
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
|
+
}
|
|
129
169
|
context.page = page;
|
|
130
170
|
context.pages.push(page);
|
|
131
171
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -177,9 +217,35 @@ class StableBrowser {
|
|
|
177
217
|
if (newContextCreated) {
|
|
178
218
|
this.registerEventListeners(this.context);
|
|
179
219
|
await this.goto(this.context.environment.baseUrl);
|
|
180
|
-
|
|
220
|
+
if (!this.fastMode) {
|
|
221
|
+
await this.waitForPageLoad();
|
|
222
|
+
}
|
|
181
223
|
}
|
|
182
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
|
+
}
|
|
183
249
|
registerConsoleLogListener(page, context) {
|
|
184
250
|
if (!this.context.webLogger) {
|
|
185
251
|
this.context.webLogger = [];
|
|
@@ -247,6 +313,7 @@ class StableBrowser {
|
|
|
247
313
|
if (!url) {
|
|
248
314
|
throw new Error("url is null, verify that the environment file is correct");
|
|
249
315
|
}
|
|
316
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
250
317
|
if (!url.startsWith("http")) {
|
|
251
318
|
url = "https://" + url;
|
|
252
319
|
}
|
|
@@ -275,7 +342,65 @@ class StableBrowser {
|
|
|
275
342
|
_commandError(state, error, this);
|
|
276
343
|
}
|
|
277
344
|
finally {
|
|
278
|
-
_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);
|
|
279
404
|
}
|
|
280
405
|
}
|
|
281
406
|
async _getLocator(locator, scope, _params) {
|
|
@@ -391,7 +516,7 @@ class StableBrowser {
|
|
|
391
516
|
}
|
|
392
517
|
return { elementCount: tagCount, randomToken };
|
|
393
518
|
}
|
|
394
|
-
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) {
|
|
395
520
|
if (!info) {
|
|
396
521
|
info = {};
|
|
397
522
|
}
|
|
@@ -458,7 +583,7 @@ class StableBrowser {
|
|
|
458
583
|
}
|
|
459
584
|
return;
|
|
460
585
|
}
|
|
461
|
-
if (info.locatorLog && count === 0) {
|
|
586
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
462
587
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
463
588
|
}
|
|
464
589
|
for (let j = 0; j < count; j++) {
|
|
@@ -473,7 +598,7 @@ class StableBrowser {
|
|
|
473
598
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
474
599
|
}
|
|
475
600
|
}
|
|
476
|
-
else {
|
|
601
|
+
else if (logErrors) {
|
|
477
602
|
info.failCause.visible = visible;
|
|
478
603
|
info.failCause.enabled = enabled;
|
|
479
604
|
if (!info.printMessages) {
|
|
@@ -565,7 +690,7 @@ class StableBrowser {
|
|
|
565
690
|
let element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
566
691
|
if (!element.rerun) {
|
|
567
692
|
const randomToken = Math.random().toString(36).substring(7);
|
|
568
|
-
element.evaluate((el, randomToken) => {
|
|
693
|
+
await element.evaluate((el, randomToken) => {
|
|
569
694
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
570
695
|
}, randomToken);
|
|
571
696
|
// if (element._frame) {
|
|
@@ -579,7 +704,7 @@ class StableBrowser {
|
|
|
579
704
|
if (frameSelectorIndex !== -1) {
|
|
580
705
|
// remove everything after the >> internal:control=enter-frame
|
|
581
706
|
const frameSelector = element._selector.substring(0, frameSelectorIndex);
|
|
582
|
-
prefixSelector = frameSelector + " >> internal:control=enter-frame";
|
|
707
|
+
prefixSelector = frameSelector + " >> internal:control=enter-frame >>";
|
|
583
708
|
}
|
|
584
709
|
// if (element?._frame?._selector) {
|
|
585
710
|
// prefixSelector = element._frame._selector + " >> " + prefixSelector;
|
|
@@ -814,7 +939,7 @@ class StableBrowser {
|
|
|
814
939
|
}
|
|
815
940
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
816
941
|
}
|
|
817
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
942
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
818
943
|
let foundElements = [];
|
|
819
944
|
const result = {
|
|
820
945
|
foundElements: foundElements,
|
|
@@ -833,7 +958,9 @@ class StableBrowser {
|
|
|
833
958
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
834
959
|
}
|
|
835
960
|
catch (e) {
|
|
836
|
-
|
|
961
|
+
if (logErrors) {
|
|
962
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
963
|
+
}
|
|
837
964
|
}
|
|
838
965
|
}
|
|
839
966
|
if (foundLocators.length === 1) {
|
|
@@ -874,7 +1001,7 @@ class StableBrowser {
|
|
|
874
1001
|
});
|
|
875
1002
|
result.locatorIndex = i;
|
|
876
1003
|
}
|
|
877
|
-
else {
|
|
1004
|
+
else if (logErrors) {
|
|
878
1005
|
info.failCause.foundMultiple = true;
|
|
879
1006
|
if (info.locatorLog) {
|
|
880
1007
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -926,7 +1053,7 @@ class StableBrowser {
|
|
|
926
1053
|
await _commandError(state, "timeout looking for " + elementDescription, this);
|
|
927
1054
|
}
|
|
928
1055
|
finally {
|
|
929
|
-
_commandFinally(state, this);
|
|
1056
|
+
await _commandFinally(state, this);
|
|
930
1057
|
}
|
|
931
1058
|
}
|
|
932
1059
|
}
|
|
@@ -975,7 +1102,7 @@ class StableBrowser {
|
|
|
975
1102
|
await _commandError(state, "timeout looking for " + elementDescription, this);
|
|
976
1103
|
}
|
|
977
1104
|
finally {
|
|
978
|
-
_commandFinally(state, this);
|
|
1105
|
+
await _commandFinally(state, this);
|
|
979
1106
|
}
|
|
980
1107
|
}
|
|
981
1108
|
}
|
|
@@ -997,14 +1124,16 @@ class StableBrowser {
|
|
|
997
1124
|
try {
|
|
998
1125
|
await _preCommand(state, this);
|
|
999
1126
|
await performAction("click", state.element, options, this, state, _params);
|
|
1000
|
-
|
|
1127
|
+
if (!this.fastMode) {
|
|
1128
|
+
await this.waitForPageLoad();
|
|
1129
|
+
}
|
|
1001
1130
|
return state.info;
|
|
1002
1131
|
}
|
|
1003
1132
|
catch (e) {
|
|
1004
1133
|
await _commandError(state, e, this);
|
|
1005
1134
|
}
|
|
1006
1135
|
finally {
|
|
1007
|
-
_commandFinally(state, this);
|
|
1136
|
+
await _commandFinally(state, this);
|
|
1008
1137
|
}
|
|
1009
1138
|
}
|
|
1010
1139
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1035,7 +1164,7 @@ class StableBrowser {
|
|
|
1035
1164
|
// await _commandError(state, e, this);
|
|
1036
1165
|
}
|
|
1037
1166
|
finally {
|
|
1038
|
-
_commandFinally(state, this);
|
|
1167
|
+
await _commandFinally(state, this);
|
|
1039
1168
|
}
|
|
1040
1169
|
return found;
|
|
1041
1170
|
}
|
|
@@ -1060,7 +1189,7 @@ class StableBrowser {
|
|
|
1060
1189
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1061
1190
|
// console.log(`Highlighting while running from recorder`);
|
|
1062
1191
|
await this._highlightElements(state.element);
|
|
1063
|
-
await state.element.setChecked(checked);
|
|
1192
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1064
1193
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1065
1194
|
// await this._unHighlightElements(element);
|
|
1066
1195
|
// }
|
|
@@ -1072,11 +1201,28 @@ class StableBrowser {
|
|
|
1072
1201
|
this.logger.info("element did not change its state, ignoring...");
|
|
1073
1202
|
}
|
|
1074
1203
|
else {
|
|
1204
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1075
1205
|
//await this.closeUnexpectedPopups();
|
|
1076
1206
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1077
|
-
state.
|
|
1078
|
-
|
|
1079
|
-
|
|
1207
|
+
state.element_found = false;
|
|
1208
|
+
try {
|
|
1209
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1210
|
+
state.element_found = true;
|
|
1211
|
+
// check the check state
|
|
1212
|
+
}
|
|
1213
|
+
catch (error) {
|
|
1214
|
+
// element dismissed
|
|
1215
|
+
}
|
|
1216
|
+
if (state.element_found) {
|
|
1217
|
+
const isChecked = await state.element.isChecked();
|
|
1218
|
+
if (isChecked !== checked) {
|
|
1219
|
+
// perform click
|
|
1220
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1080
1226
|
}
|
|
1081
1227
|
}
|
|
1082
1228
|
await this.waitForPageLoad();
|
|
@@ -1086,7 +1232,7 @@ class StableBrowser {
|
|
|
1086
1232
|
await _commandError(state, e, this);
|
|
1087
1233
|
}
|
|
1088
1234
|
finally {
|
|
1089
|
-
_commandFinally(state, this);
|
|
1235
|
+
await _commandFinally(state, this);
|
|
1090
1236
|
}
|
|
1091
1237
|
}
|
|
1092
1238
|
async hover(selectors, _params, options = {}, world = null) {
|
|
@@ -1112,7 +1258,7 @@ class StableBrowser {
|
|
|
1112
1258
|
await _commandError(state, e, this);
|
|
1113
1259
|
}
|
|
1114
1260
|
finally {
|
|
1115
|
-
_commandFinally(state, this);
|
|
1261
|
+
await _commandFinally(state, this);
|
|
1116
1262
|
}
|
|
1117
1263
|
}
|
|
1118
1264
|
async selectOption(selectors, values, _params = null, options = {}, world = null) {
|
|
@@ -1148,7 +1294,7 @@ class StableBrowser {
|
|
|
1148
1294
|
await _commandError(state, e, this);
|
|
1149
1295
|
}
|
|
1150
1296
|
finally {
|
|
1151
|
-
_commandFinally(state, this);
|
|
1297
|
+
await _commandFinally(state, this);
|
|
1152
1298
|
}
|
|
1153
1299
|
}
|
|
1154
1300
|
async type(_value, _params = null, options = {}, world = null) {
|
|
@@ -1194,7 +1340,7 @@ class StableBrowser {
|
|
|
1194
1340
|
await _commandError(state, e, this);
|
|
1195
1341
|
}
|
|
1196
1342
|
finally {
|
|
1197
|
-
_commandFinally(state, this);
|
|
1343
|
+
await _commandFinally(state, this);
|
|
1198
1344
|
}
|
|
1199
1345
|
}
|
|
1200
1346
|
async setInputValue(selectors, value, _params = null, options = {}, world = null) {
|
|
@@ -1230,7 +1376,7 @@ class StableBrowser {
|
|
|
1230
1376
|
await _commandError(state, e, this);
|
|
1231
1377
|
}
|
|
1232
1378
|
finally {
|
|
1233
|
-
_commandFinally(state, this);
|
|
1379
|
+
await _commandFinally(state, this);
|
|
1234
1380
|
}
|
|
1235
1381
|
}
|
|
1236
1382
|
async setDateTime(selectors, value, format = null, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1299,7 +1445,7 @@ class StableBrowser {
|
|
|
1299
1445
|
await _commandError(state, e, this);
|
|
1300
1446
|
}
|
|
1301
1447
|
finally {
|
|
1302
|
-
_commandFinally(state, this);
|
|
1448
|
+
await _commandFinally(state, this);
|
|
1303
1449
|
}
|
|
1304
1450
|
}
|
|
1305
1451
|
async clickType(selectors, _value, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1372,7 +1518,9 @@ class StableBrowser {
|
|
|
1372
1518
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1373
1519
|
}
|
|
1374
1520
|
}
|
|
1521
|
+
//if (!this.fastMode) {
|
|
1375
1522
|
await _screenshot(state, this);
|
|
1523
|
+
//}
|
|
1376
1524
|
if (enter === true) {
|
|
1377
1525
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1378
1526
|
await this.page.keyboard.press("Enter");
|
|
@@ -1399,7 +1547,7 @@ class StableBrowser {
|
|
|
1399
1547
|
await _commandError(state, e, this);
|
|
1400
1548
|
}
|
|
1401
1549
|
finally {
|
|
1402
|
-
_commandFinally(state, this);
|
|
1550
|
+
await _commandFinally(state, this);
|
|
1403
1551
|
}
|
|
1404
1552
|
}
|
|
1405
1553
|
async fill(selectors, value, enter = false, _params = null, options = {}, world = null) {
|
|
@@ -1429,7 +1577,42 @@ class StableBrowser {
|
|
|
1429
1577
|
await _commandError(state, e, this);
|
|
1430
1578
|
}
|
|
1431
1579
|
finally {
|
|
1432
|
-
_commandFinally(state, this);
|
|
1580
|
+
await _commandFinally(state, this);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
async setInputFiles(selectors, files, _params = null, options = {}, world = null) {
|
|
1584
|
+
const state = {
|
|
1585
|
+
selectors,
|
|
1586
|
+
_params,
|
|
1587
|
+
files,
|
|
1588
|
+
value: '"' + files.join('", "') + '"',
|
|
1589
|
+
options,
|
|
1590
|
+
world,
|
|
1591
|
+
type: Types.SET_INPUT_FILES,
|
|
1592
|
+
text: `Set input files`,
|
|
1593
|
+
_text: `Set input files on ${selectors.element_name}`,
|
|
1594
|
+
operation: "setInputFiles",
|
|
1595
|
+
log: "***** set input files " + selectors.element_name + " *****\n",
|
|
1596
|
+
};
|
|
1597
|
+
const uploadsFolder = this.configuration.uploadsFolder ?? "data/uploads";
|
|
1598
|
+
try {
|
|
1599
|
+
await _preCommand(state, this);
|
|
1600
|
+
for (let i = 0; i < files.length; i++) {
|
|
1601
|
+
const file = files[i];
|
|
1602
|
+
const filePath = path.join(uploadsFolder, file);
|
|
1603
|
+
if (!fs.existsSync(filePath)) {
|
|
1604
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1605
|
+
}
|
|
1606
|
+
state.files[i] = filePath;
|
|
1607
|
+
}
|
|
1608
|
+
await state.element.setInputFiles(files);
|
|
1609
|
+
return state.info;
|
|
1610
|
+
}
|
|
1611
|
+
catch (e) {
|
|
1612
|
+
await _commandError(state, e, this);
|
|
1613
|
+
}
|
|
1614
|
+
finally {
|
|
1615
|
+
await _commandFinally(state, this);
|
|
1433
1616
|
}
|
|
1434
1617
|
}
|
|
1435
1618
|
async getText(selectors, _params = null, options = {}, info = {}, world = null) {
|
|
@@ -1545,7 +1728,7 @@ class StableBrowser {
|
|
|
1545
1728
|
await _commandError(state, e, this);
|
|
1546
1729
|
}
|
|
1547
1730
|
finally {
|
|
1548
|
-
_commandFinally(state, this);
|
|
1731
|
+
await _commandFinally(state, this);
|
|
1549
1732
|
}
|
|
1550
1733
|
}
|
|
1551
1734
|
async containsText(selectors, text, climb, _params = null, options = {}, world = null) {
|
|
@@ -1622,7 +1805,84 @@ class StableBrowser {
|
|
|
1622
1805
|
throw e;
|
|
1623
1806
|
}
|
|
1624
1807
|
finally {
|
|
1625
|
-
_commandFinally(state, this);
|
|
1808
|
+
await _commandFinally(state, this);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
async snapshotValidation(frameSelectors, referanceSnapshot, _params = null, options = {}, world = null) {
|
|
1812
|
+
const timeout = this._getFindElementTimeout(options);
|
|
1813
|
+
const startTime = Date.now();
|
|
1814
|
+
const state = {
|
|
1815
|
+
_params,
|
|
1816
|
+
value: referanceSnapshot,
|
|
1817
|
+
options,
|
|
1818
|
+
world,
|
|
1819
|
+
locate: false,
|
|
1820
|
+
scroll: false,
|
|
1821
|
+
screenshot: true,
|
|
1822
|
+
highlight: false,
|
|
1823
|
+
type: Types.SNAPSHOT_VALIDATION,
|
|
1824
|
+
text: `verify snapshot: ${referanceSnapshot}`,
|
|
1825
|
+
operation: "snapshotValidation",
|
|
1826
|
+
log: "***** verify snapshot *****\n",
|
|
1827
|
+
};
|
|
1828
|
+
if (!referanceSnapshot) {
|
|
1829
|
+
throw new Error("referanceSnapshot is null");
|
|
1830
|
+
}
|
|
1831
|
+
let text = null;
|
|
1832
|
+
if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"))) {
|
|
1833
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"), "utf8");
|
|
1834
|
+
}
|
|
1835
|
+
else if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"))) {
|
|
1836
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"), "utf8");
|
|
1837
|
+
}
|
|
1838
|
+
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1839
|
+
text = referanceSnapshot.substring(5);
|
|
1840
|
+
}
|
|
1841
|
+
else {
|
|
1842
|
+
throw new Error("referenceSnapshot file not found: " + referanceSnapshot);
|
|
1843
|
+
}
|
|
1844
|
+
state.text = text;
|
|
1845
|
+
const newValue = await this._replaceWithLocalData(text, world);
|
|
1846
|
+
await _preCommand(state, this);
|
|
1847
|
+
let foundObj = null;
|
|
1848
|
+
try {
|
|
1849
|
+
let matchResult = null;
|
|
1850
|
+
while (Date.now() - startTime < timeout) {
|
|
1851
|
+
try {
|
|
1852
|
+
let scope = null;
|
|
1853
|
+
if (!frameSelectors) {
|
|
1854
|
+
scope = this.page;
|
|
1855
|
+
}
|
|
1856
|
+
else {
|
|
1857
|
+
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1858
|
+
}
|
|
1859
|
+
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
1860
|
+
matchResult = snapshotValidation(snapshot, newValue, referanceSnapshot);
|
|
1861
|
+
if (matchResult.errorLine !== -1) {
|
|
1862
|
+
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1863
|
+
}
|
|
1864
|
+
// highlight and screenshot
|
|
1865
|
+
try {
|
|
1866
|
+
await await highlightSnapshot(newValue, scope);
|
|
1867
|
+
await _screenshot(state, this);
|
|
1868
|
+
}
|
|
1869
|
+
catch (e) { }
|
|
1870
|
+
return state.info;
|
|
1871
|
+
}
|
|
1872
|
+
catch (e) {
|
|
1873
|
+
// Log error but continue retrying until timeout is reached
|
|
1874
|
+
//this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
1875
|
+
}
|
|
1876
|
+
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 1 second before retrying
|
|
1877
|
+
}
|
|
1878
|
+
throw new Error("No snapshot match " + matchResult?.errorLineText);
|
|
1879
|
+
}
|
|
1880
|
+
catch (e) {
|
|
1881
|
+
await _commandError(state, e, this);
|
|
1882
|
+
throw e;
|
|
1883
|
+
}
|
|
1884
|
+
finally {
|
|
1885
|
+
await _commandFinally(state, this);
|
|
1626
1886
|
}
|
|
1627
1887
|
}
|
|
1628
1888
|
async waitForUserInput(message, world = null) {
|
|
@@ -1765,12 +2025,7 @@ class StableBrowser {
|
|
|
1765
2025
|
}
|
|
1766
2026
|
}
|
|
1767
2027
|
getTestData(world = null) {
|
|
1768
|
-
|
|
1769
|
-
let data = {};
|
|
1770
|
-
if (fs.existsSync(dataFile)) {
|
|
1771
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1772
|
-
}
|
|
1773
|
-
return data;
|
|
2028
|
+
return _getTestData(world, this.context, this);
|
|
1774
2029
|
}
|
|
1775
2030
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1776
2031
|
// collect url/path/title
|
|
@@ -1921,7 +2176,7 @@ class StableBrowser {
|
|
|
1921
2176
|
await _commandError(state, e, this);
|
|
1922
2177
|
}
|
|
1923
2178
|
finally {
|
|
1924
|
-
_commandFinally(state, this);
|
|
2179
|
+
await _commandFinally(state, this);
|
|
1925
2180
|
}
|
|
1926
2181
|
}
|
|
1927
2182
|
async extractAttribute(selectors, attribute, variable, _params = null, options = {}, world = null) {
|
|
@@ -1952,10 +2207,102 @@ class StableBrowser {
|
|
|
1952
2207
|
case "value":
|
|
1953
2208
|
state.value = await state.element.inputValue();
|
|
1954
2209
|
break;
|
|
2210
|
+
case "text":
|
|
2211
|
+
state.value = await state.element.textContent();
|
|
2212
|
+
break;
|
|
1955
2213
|
default:
|
|
1956
2214
|
state.value = await state.element.getAttribute(attribute);
|
|
1957
2215
|
break;
|
|
1958
2216
|
}
|
|
2217
|
+
if (options !== null) {
|
|
2218
|
+
if (options.regex && options.regex !== "") {
|
|
2219
|
+
// Construct a regex pattern from the provided string
|
|
2220
|
+
const regex = options.regex.slice(1, -1);
|
|
2221
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2222
|
+
const matches = state.value.match(regexPattern);
|
|
2223
|
+
if (matches) {
|
|
2224
|
+
let newValue = "";
|
|
2225
|
+
for (const match of matches) {
|
|
2226
|
+
newValue += match;
|
|
2227
|
+
}
|
|
2228
|
+
state.value = newValue;
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2232
|
+
state.value = state.value.trim();
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
state.info.value = state.value;
|
|
2236
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2237
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2238
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2239
|
+
return state.info;
|
|
2240
|
+
}
|
|
2241
|
+
catch (e) {
|
|
2242
|
+
await _commandError(state, e, this);
|
|
2243
|
+
}
|
|
2244
|
+
finally {
|
|
2245
|
+
await _commandFinally(state, this);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2249
|
+
const state = {
|
|
2250
|
+
selectors,
|
|
2251
|
+
_params,
|
|
2252
|
+
property,
|
|
2253
|
+
variable,
|
|
2254
|
+
options,
|
|
2255
|
+
world,
|
|
2256
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2257
|
+
text: `Extract property from element`,
|
|
2258
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2259
|
+
operation: "extractProperty",
|
|
2260
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2261
|
+
allowDisabled: true,
|
|
2262
|
+
};
|
|
2263
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2264
|
+
try {
|
|
2265
|
+
await _preCommand(state, this);
|
|
2266
|
+
switch (property) {
|
|
2267
|
+
case "inner_text":
|
|
2268
|
+
state.value = await state.element.innerText();
|
|
2269
|
+
break;
|
|
2270
|
+
case "href":
|
|
2271
|
+
state.value = await state.element.getAttribute("href");
|
|
2272
|
+
break;
|
|
2273
|
+
case "value":
|
|
2274
|
+
state.value = await state.element.inputValue();
|
|
2275
|
+
break;
|
|
2276
|
+
case "text":
|
|
2277
|
+
state.value = await state.element.textContent();
|
|
2278
|
+
break;
|
|
2279
|
+
default:
|
|
2280
|
+
if (property.startsWith("dataset.")) {
|
|
2281
|
+
const dataAttribute = property.substring(8);
|
|
2282
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2283
|
+
}
|
|
2284
|
+
else {
|
|
2285
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
if (options !== null) {
|
|
2289
|
+
if (options.regex && options.regex !== "") {
|
|
2290
|
+
// Construct a regex pattern from the provided string
|
|
2291
|
+
const regex = options.regex.slice(1, -1);
|
|
2292
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2293
|
+
const matches = state.value.match(regexPattern);
|
|
2294
|
+
if (matches) {
|
|
2295
|
+
let newValue = "";
|
|
2296
|
+
for (const match of matches) {
|
|
2297
|
+
newValue += match;
|
|
2298
|
+
}
|
|
2299
|
+
state.value = newValue;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2303
|
+
state.value = state.value.trim();
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
1959
2306
|
state.info.value = state.value;
|
|
1960
2307
|
this.setTestData({ [variable]: state.value }, world);
|
|
1961
2308
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
@@ -1966,7 +2313,7 @@ class StableBrowser {
|
|
|
1966
2313
|
await _commandError(state, e, this);
|
|
1967
2314
|
}
|
|
1968
2315
|
finally {
|
|
1969
|
-
_commandFinally(state, this);
|
|
2316
|
+
await _commandFinally(state, this);
|
|
1970
2317
|
}
|
|
1971
2318
|
}
|
|
1972
2319
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
@@ -1991,12 +2338,15 @@ class StableBrowser {
|
|
|
1991
2338
|
let expectedValue;
|
|
1992
2339
|
try {
|
|
1993
2340
|
await _preCommand(state, this);
|
|
1994
|
-
expectedValue = state.value;
|
|
2341
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
1995
2342
|
state.info.expectedValue = expectedValue;
|
|
1996
2343
|
switch (attribute) {
|
|
1997
2344
|
case "innerText":
|
|
1998
2345
|
val = String(await state.element.innerText());
|
|
1999
2346
|
break;
|
|
2347
|
+
case "text":
|
|
2348
|
+
val = String(await state.element.textContent());
|
|
2349
|
+
break;
|
|
2000
2350
|
case "value":
|
|
2001
2351
|
val = String(await state.element.inputValue());
|
|
2002
2352
|
break;
|
|
@@ -2018,17 +2368,163 @@ class StableBrowser {
|
|
|
2018
2368
|
let regex;
|
|
2019
2369
|
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2020
2370
|
const patternBody = expectedValue.slice(1, -1);
|
|
2021
|
-
|
|
2371
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2372
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2373
|
+
state.info.regex = true;
|
|
2374
|
+
}
|
|
2375
|
+
else {
|
|
2376
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2377
|
+
regex = new RegExp(escapedPattern, "g");
|
|
2378
|
+
}
|
|
2379
|
+
if (attribute === "innerText") {
|
|
2380
|
+
if (state.info.regex) {
|
|
2381
|
+
if (!regex.test(val)) {
|
|
2382
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2383
|
+
state.info.failCause.assertionFailed = true;
|
|
2384
|
+
state.info.failCause.lastError = errorMessage;
|
|
2385
|
+
throw new Error(errorMessage);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
else {
|
|
2389
|
+
const valLines = val.split("\n");
|
|
2390
|
+
const expectedLines = expectedValue.split("\n");
|
|
2391
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine === expectedLine));
|
|
2392
|
+
if (!isPart) {
|
|
2393
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2394
|
+
state.info.failCause.assertionFailed = true;
|
|
2395
|
+
state.info.failCause.lastError = errorMessage;
|
|
2396
|
+
throw new Error(errorMessage);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
else {
|
|
2401
|
+
if (!val.match(regex)) {
|
|
2402
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2403
|
+
state.info.failCause.assertionFailed = true;
|
|
2404
|
+
state.info.failCause.lastError = errorMessage;
|
|
2405
|
+
throw new Error(errorMessage);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
return state.info;
|
|
2409
|
+
}
|
|
2410
|
+
catch (e) {
|
|
2411
|
+
await _commandError(state, e, this);
|
|
2412
|
+
}
|
|
2413
|
+
finally {
|
|
2414
|
+
await _commandFinally(state, this);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2418
|
+
const state = {
|
|
2419
|
+
selectors,
|
|
2420
|
+
_params,
|
|
2421
|
+
property,
|
|
2422
|
+
value,
|
|
2423
|
+
options,
|
|
2424
|
+
world,
|
|
2425
|
+
type: Types.VERIFY_PROPERTY,
|
|
2426
|
+
highlight: true,
|
|
2427
|
+
screenshot: true,
|
|
2428
|
+
text: `Verify element property`,
|
|
2429
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2430
|
+
operation: "verifyProperty",
|
|
2431
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2432
|
+
allowDisabled: true,
|
|
2433
|
+
};
|
|
2434
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2435
|
+
let val;
|
|
2436
|
+
let expectedValue;
|
|
2437
|
+
try {
|
|
2438
|
+
await _preCommand(state, this);
|
|
2439
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2440
|
+
state.info.expectedValue = expectedValue;
|
|
2441
|
+
switch (property) {
|
|
2442
|
+
case "innerText":
|
|
2443
|
+
val = String(await state.element.innerText());
|
|
2444
|
+
break;
|
|
2445
|
+
case "text":
|
|
2446
|
+
val = String(await state.element.textContent());
|
|
2447
|
+
break;
|
|
2448
|
+
case "value":
|
|
2449
|
+
val = String(await state.element.inputValue());
|
|
2450
|
+
break;
|
|
2451
|
+
case "checked":
|
|
2452
|
+
val = String(await state.element.isChecked());
|
|
2453
|
+
break;
|
|
2454
|
+
case "disabled":
|
|
2455
|
+
val = String(await state.element.isDisabled());
|
|
2456
|
+
break;
|
|
2457
|
+
case "readOnly":
|
|
2458
|
+
const isEditable = await state.element.isEditable();
|
|
2459
|
+
val = String(!isEditable);
|
|
2460
|
+
break;
|
|
2461
|
+
case "innerHTML":
|
|
2462
|
+
val = String(await state.element.innerHTML());
|
|
2463
|
+
break;
|
|
2464
|
+
case "outerHTML":
|
|
2465
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2466
|
+
break;
|
|
2467
|
+
default:
|
|
2468
|
+
if (property.startsWith("dataset.")) {
|
|
2469
|
+
const dataAttribute = property.substring(8);
|
|
2470
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2471
|
+
}
|
|
2472
|
+
else {
|
|
2473
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
// Helper function to remove all style="" attributes
|
|
2477
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2478
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2479
|
+
};
|
|
2480
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2481
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2482
|
+
val = removeStyleAttributes(val);
|
|
2483
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2484
|
+
}
|
|
2485
|
+
state.info.value = val;
|
|
2486
|
+
let regex;
|
|
2487
|
+
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2488
|
+
const patternBody = expectedValue.slice(1, -1);
|
|
2489
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2490
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2491
|
+
state.info.regex = true;
|
|
2022
2492
|
}
|
|
2023
2493
|
else {
|
|
2024
2494
|
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2025
2495
|
regex = new RegExp(escapedPattern, "g");
|
|
2026
2496
|
}
|
|
2027
|
-
if (
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2497
|
+
if (property === "innerText") {
|
|
2498
|
+
if (state.info.regex) {
|
|
2499
|
+
if (!regex.test(val)) {
|
|
2500
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2501
|
+
state.info.failCause.assertionFailed = true;
|
|
2502
|
+
state.info.failCause.lastError = errorMessage;
|
|
2503
|
+
throw new Error(errorMessage);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
else {
|
|
2507
|
+
// Fix: Replace escaped newlines with actual newlines before splitting
|
|
2508
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2509
|
+
const valLines = val.split("\n");
|
|
2510
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2511
|
+
// Check if all expected lines are present in the actual lines
|
|
2512
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2513
|
+
if (!isPart) {
|
|
2514
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2515
|
+
state.info.failCause.assertionFailed = true;
|
|
2516
|
+
state.info.failCause.lastError = errorMessage;
|
|
2517
|
+
throw new Error(errorMessage);
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
else {
|
|
2522
|
+
if (!val.match(regex)) {
|
|
2523
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2524
|
+
state.info.failCause.assertionFailed = true;
|
|
2525
|
+
state.info.failCause.lastError = errorMessage;
|
|
2526
|
+
throw new Error(errorMessage);
|
|
2527
|
+
}
|
|
2032
2528
|
}
|
|
2033
2529
|
return state.info;
|
|
2034
2530
|
}
|
|
@@ -2036,7 +2532,102 @@ class StableBrowser {
|
|
|
2036
2532
|
await _commandError(state, e, this);
|
|
2037
2533
|
}
|
|
2038
2534
|
finally {
|
|
2039
|
-
_commandFinally(state, this);
|
|
2535
|
+
await _commandFinally(state, this);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2539
|
+
// Convert timeout from seconds to milliseconds
|
|
2540
|
+
const timeoutMs = timeout * 1000;
|
|
2541
|
+
const state = {
|
|
2542
|
+
selectors,
|
|
2543
|
+
_params,
|
|
2544
|
+
condition,
|
|
2545
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2546
|
+
options,
|
|
2547
|
+
world,
|
|
2548
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2549
|
+
highlight: true,
|
|
2550
|
+
screenshot: true,
|
|
2551
|
+
text: `Conditional wait for element`,
|
|
2552
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2553
|
+
operation: "conditionalWait",
|
|
2554
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2555
|
+
allowDisabled: true,
|
|
2556
|
+
info: {}
|
|
2557
|
+
};
|
|
2558
|
+
try {
|
|
2559
|
+
await _preCommand(state, this);
|
|
2560
|
+
const startTime = Date.now();
|
|
2561
|
+
let conditionMet = false;
|
|
2562
|
+
let currentValue = null;
|
|
2563
|
+
const checkCondition = async () => {
|
|
2564
|
+
try {
|
|
2565
|
+
switch (condition.toLowerCase()) {
|
|
2566
|
+
case "checked":
|
|
2567
|
+
currentValue = await state.element.isChecked();
|
|
2568
|
+
return currentValue === true;
|
|
2569
|
+
case "unchecked":
|
|
2570
|
+
currentValue = await state.element.isChecked();
|
|
2571
|
+
return currentValue === false;
|
|
2572
|
+
case "visible":
|
|
2573
|
+
currentValue = await state.element.isVisible();
|
|
2574
|
+
return currentValue === true;
|
|
2575
|
+
case "hidden":
|
|
2576
|
+
currentValue = await state.element.isVisible();
|
|
2577
|
+
return currentValue === false;
|
|
2578
|
+
case "enabled":
|
|
2579
|
+
currentValue = await state.element.isDisabled();
|
|
2580
|
+
return currentValue === false;
|
|
2581
|
+
case "disabled":
|
|
2582
|
+
currentValue = await state.element.isDisabled();
|
|
2583
|
+
return currentValue === true;
|
|
2584
|
+
case "editable":
|
|
2585
|
+
currentValue = await state.element.isEditable();
|
|
2586
|
+
return currentValue === true;
|
|
2587
|
+
default:
|
|
2588
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2589
|
+
state.info.success = false;
|
|
2590
|
+
return false;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
catch {
|
|
2594
|
+
return false;
|
|
2595
|
+
}
|
|
2596
|
+
};
|
|
2597
|
+
while (Date.now() - startTime < timeoutMs) { // 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);
|
|
2040
2631
|
}
|
|
2041
2632
|
}
|
|
2042
2633
|
async extractEmailData(emailAddress, options, world) {
|
|
@@ -2196,56 +2787,49 @@ class StableBrowser {
|
|
|
2196
2787
|
console.debug(error);
|
|
2197
2788
|
}
|
|
2198
2789
|
}
|
|
2199
|
-
|
|
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
|
-
// } catch (error) {
|
|
2244
|
-
// // console.debug(error);
|
|
2245
|
-
// }
|
|
2246
|
-
// }
|
|
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
|
+
*/
|
|
2247
2832
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2248
|
-
const startTime = Date.now();
|
|
2249
2833
|
let error = null;
|
|
2250
2834
|
let screenshotId = null;
|
|
2251
2835
|
let screenshotPath = null;
|
|
@@ -2259,113 +2843,212 @@ class StableBrowser {
|
|
|
2259
2843
|
pathPart = newValue;
|
|
2260
2844
|
}
|
|
2261
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
|
+
};
|
|
2262
2860
|
try {
|
|
2861
|
+
await _preCommand(state, this);
|
|
2862
|
+
state.info.text = queryText;
|
|
2263
2863
|
for (let i = 0; i < 30; i++) {
|
|
2264
2864
|
const url = await this.page.url();
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
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
|
+
}
|
|
2271
2934
|
}
|
|
2272
|
-
|
|
2273
|
-
return info;
|
|
2935
|
+
await _screenshot(state, this);
|
|
2936
|
+
return state.info;
|
|
2274
2937
|
}
|
|
2275
2938
|
}
|
|
2276
2939
|
catch (e) {
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
info.screenshotPath = screenshotPath;
|
|
2281
|
-
Object.assign(e, { info: info });
|
|
2282
|
-
error = e;
|
|
2283
|
-
// throw e;
|
|
2284
|
-
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);
|
|
2285
2943
|
}
|
|
2286
2944
|
finally {
|
|
2287
|
-
|
|
2288
|
-
_reportToWorld(world, {
|
|
2289
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2290
|
-
text: "Verify page path",
|
|
2291
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2292
|
-
screenshotId,
|
|
2293
|
-
result: error
|
|
2294
|
-
? {
|
|
2295
|
-
status: "FAILED",
|
|
2296
|
-
startTime,
|
|
2297
|
-
endTime,
|
|
2298
|
-
message: error?.message,
|
|
2299
|
-
}
|
|
2300
|
-
: {
|
|
2301
|
-
status: "PASSED",
|
|
2302
|
-
startTime,
|
|
2303
|
-
endTime,
|
|
2304
|
-
},
|
|
2305
|
-
info: info,
|
|
2306
|
-
});
|
|
2945
|
+
await _commandFinally(state, this);
|
|
2307
2946
|
}
|
|
2308
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
|
+
*/
|
|
2309
2955
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2310
|
-
const startTime = Date.now();
|
|
2311
2956
|
let error = null;
|
|
2312
2957
|
let screenshotId = null;
|
|
2313
2958
|
let screenshotPath = null;
|
|
2314
2959
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2315
|
-
const info = {};
|
|
2316
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2317
|
-
info.operation = "verifyPageTitle";
|
|
2318
2960
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2319
2961
|
if (newValue !== title) {
|
|
2320
2962
|
this.logger.info(title + "=" + newValue);
|
|
2321
2963
|
title = newValue;
|
|
2322
2964
|
}
|
|
2323
|
-
|
|
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
|
+
};
|
|
2324
2979
|
try {
|
|
2980
|
+
await _preCommand(state, this);
|
|
2981
|
+
state.info.text = queryText;
|
|
2325
2982
|
for (let i = 0; i < 30; i++) {
|
|
2326
2983
|
const foundTitle = await this.page.title();
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
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
|
+
}
|
|
2333
3040
|
}
|
|
2334
|
-
|
|
2335
|
-
return info;
|
|
3041
|
+
await _screenshot(state, this);
|
|
3042
|
+
return state.info;
|
|
2336
3043
|
}
|
|
2337
3044
|
}
|
|
2338
3045
|
catch (e) {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
info.screenshotPath = screenshotPath;
|
|
2343
|
-
Object.assign(e, { info: info });
|
|
2344
|
-
error = e;
|
|
2345
|
-
// throw e;
|
|
2346
|
-
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);
|
|
2347
3049
|
}
|
|
2348
3050
|
finally {
|
|
2349
|
-
|
|
2350
|
-
_reportToWorld(world, {
|
|
2351
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2352
|
-
text: "Verify page title",
|
|
2353
|
-
_text: "Verify the page title contains " + title,
|
|
2354
|
-
screenshotId,
|
|
2355
|
-
result: error
|
|
2356
|
-
? {
|
|
2357
|
-
status: "FAILED",
|
|
2358
|
-
startTime,
|
|
2359
|
-
endTime,
|
|
2360
|
-
message: error?.message,
|
|
2361
|
-
}
|
|
2362
|
-
: {
|
|
2363
|
-
status: "PASSED",
|
|
2364
|
-
startTime,
|
|
2365
|
-
endTime,
|
|
2366
|
-
},
|
|
2367
|
-
info: info,
|
|
2368
|
-
});
|
|
3051
|
+
await _commandFinally(state, this);
|
|
2369
3052
|
}
|
|
2370
3053
|
}
|
|
2371
3054
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2407,7 +3090,7 @@ class StableBrowser {
|
|
|
2407
3090
|
scroll: false,
|
|
2408
3091
|
highlight: false,
|
|
2409
3092
|
type: Types.VERIFY_PAGE_CONTAINS_TEXT,
|
|
2410
|
-
text: `Verify the text '${text}' exists in page`,
|
|
3093
|
+
text: `Verify the text '${maskValue(text)}' exists in page`,
|
|
2411
3094
|
_text: `Verify the text '${text}' exists in page`,
|
|
2412
3095
|
operation: "verifyTextExistInPage",
|
|
2413
3096
|
log: "***** verify text " + text + " exists in page *****\n",
|
|
@@ -2449,27 +3132,10 @@ class StableBrowser {
|
|
|
2449
3132
|
const frame = resultWithElementsFound[0].frame;
|
|
2450
3133
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2451
3134
|
await this._highlightElements(frame, dataAttribute);
|
|
2452
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2453
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2454
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2455
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2456
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2457
|
-
// .then(async () => {
|
|
2458
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2459
|
-
// })
|
|
2460
|
-
// .catch(
|
|
2461
|
-
// (e) => {}
|
|
2462
|
-
// console.error(e)
|
|
2463
|
-
// );
|
|
2464
|
-
// });
|
|
2465
|
-
// }
|
|
2466
3135
|
const element = await frame.locator(dataAttribute).first();
|
|
2467
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2468
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2469
3136
|
if (element) {
|
|
2470
3137
|
await this.scrollIfNeeded(element, state.info);
|
|
2471
3138
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2472
|
-
// await _screenshot(state, this, element);
|
|
2473
3139
|
}
|
|
2474
3140
|
}
|
|
2475
3141
|
await _screenshot(state, this);
|
|
@@ -2479,13 +3145,12 @@ class StableBrowser {
|
|
|
2479
3145
|
console.error(error);
|
|
2480
3146
|
}
|
|
2481
3147
|
}
|
|
2482
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2483
3148
|
}
|
|
2484
3149
|
catch (e) {
|
|
2485
3150
|
await _commandError(state, e, this);
|
|
2486
3151
|
}
|
|
2487
3152
|
finally {
|
|
2488
|
-
_commandFinally(state, this);
|
|
3153
|
+
await _commandFinally(state, this);
|
|
2489
3154
|
}
|
|
2490
3155
|
}
|
|
2491
3156
|
async waitForTextToDisappear(text, options = {}, world = null) {
|
|
@@ -2498,7 +3163,7 @@ class StableBrowser {
|
|
|
2498
3163
|
scroll: false,
|
|
2499
3164
|
highlight: false,
|
|
2500
3165
|
type: Types.WAIT_FOR_TEXT_TO_DISAPPEAR,
|
|
2501
|
-
text: `Verify the text '${text}' does not exist in page`,
|
|
3166
|
+
text: `Verify the text '${maskValue(text)}' does not exist in page`,
|
|
2502
3167
|
_text: `Verify the text '${text}' does not exist in page`,
|
|
2503
3168
|
operation: "verifyTextNotExistInPage",
|
|
2504
3169
|
log: "***** verify text " + text + " does not exist in page *****\n",
|
|
@@ -2542,7 +3207,7 @@ class StableBrowser {
|
|
|
2542
3207
|
await _commandError(state, e, this);
|
|
2543
3208
|
}
|
|
2544
3209
|
finally {
|
|
2545
|
-
_commandFinally(state, this);
|
|
3210
|
+
await _commandFinally(state, this);
|
|
2546
3211
|
}
|
|
2547
3212
|
}
|
|
2548
3213
|
async verifyTextRelatedToText(textAnchor, climb, textToVerify, options = {}, world = null) {
|
|
@@ -2653,7 +3318,7 @@ class StableBrowser {
|
|
|
2653
3318
|
await _commandError(state, e, this);
|
|
2654
3319
|
}
|
|
2655
3320
|
finally {
|
|
2656
|
-
_commandFinally(state, this);
|
|
3321
|
+
await _commandFinally(state, this);
|
|
2657
3322
|
}
|
|
2658
3323
|
}
|
|
2659
3324
|
async findRelatedTextInAllFrames(textAnchor, climb, textToVerify, params = {}, options = {}, world = null) {
|
|
@@ -2995,8 +3660,51 @@ class StableBrowser {
|
|
|
2995
3660
|
});
|
|
2996
3661
|
}
|
|
2997
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
|
+
}
|
|
2998
3700
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
2999
|
-
|
|
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
|
+
}
|
|
3000
3708
|
}
|
|
3001
3709
|
_getLoadTimeout(options) {
|
|
3002
3710
|
let timeout = 15000;
|
|
@@ -3019,6 +3727,7 @@ class StableBrowser {
|
|
|
3019
3727
|
}
|
|
3020
3728
|
async saveStoreState(path = null, world = null) {
|
|
3021
3729
|
const storageState = await this.page.context().storageState();
|
|
3730
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3022
3731
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3023
3732
|
if (path) {
|
|
3024
3733
|
// save { storageState: storageState } into the path
|
|
@@ -3029,10 +3738,14 @@ class StableBrowser {
|
|
|
3029
3738
|
}
|
|
3030
3739
|
}
|
|
3031
3740
|
async restoreSaveState(path = null, world = null) {
|
|
3741
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3032
3742
|
await refreshBrowser(this, path, world);
|
|
3033
3743
|
this.registerEventListeners(this.context);
|
|
3034
3744
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
3035
3745
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
3746
|
+
if (this.onRestoreSaveState) {
|
|
3747
|
+
this.onRestoreSaveState(path);
|
|
3748
|
+
}
|
|
3036
3749
|
}
|
|
3037
3750
|
async waitForPageLoad(options = {}, world = null) {
|
|
3038
3751
|
let timeout = this._getLoadTimeout(options);
|
|
@@ -3115,7 +3828,7 @@ class StableBrowser {
|
|
|
3115
3828
|
await _commandError(state, e, this);
|
|
3116
3829
|
}
|
|
3117
3830
|
finally {
|
|
3118
|
-
_commandFinally(state, this);
|
|
3831
|
+
await _commandFinally(state, this);
|
|
3119
3832
|
}
|
|
3120
3833
|
}
|
|
3121
3834
|
async tableCellOperation(headerText, rowText, options, _params, world = null) {
|
|
@@ -3202,7 +3915,7 @@ class StableBrowser {
|
|
|
3202
3915
|
await _commandError(state, e, this);
|
|
3203
3916
|
}
|
|
3204
3917
|
finally {
|
|
3205
|
-
_commandFinally(state, this);
|
|
3918
|
+
await _commandFinally(state, this);
|
|
3206
3919
|
}
|
|
3207
3920
|
}
|
|
3208
3921
|
saveTestDataAsGlobal(options, world) {
|
|
@@ -3307,7 +4020,39 @@ class StableBrowser {
|
|
|
3307
4020
|
console.log("#-#");
|
|
3308
4021
|
}
|
|
3309
4022
|
}
|
|
4023
|
+
async beforeScenario(world, scenario) {
|
|
4024
|
+
this.beforeScenarioCalled = true;
|
|
4025
|
+
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
4026
|
+
this.scenarioName = scenario.pickle.name;
|
|
4027
|
+
}
|
|
4028
|
+
if (scenario && scenario.gherkinDocument && scenario.gherkinDocument.feature) {
|
|
4029
|
+
this.featureName = scenario.gherkinDocument.feature.name;
|
|
4030
|
+
}
|
|
4031
|
+
if (this.context) {
|
|
4032
|
+
this.context.examplesRow = extractStepExampleParameters(scenario);
|
|
4033
|
+
}
|
|
4034
|
+
if (this.tags === null && scenario && scenario.pickle && scenario.pickle.tags) {
|
|
4035
|
+
this.tags = scenario.pickle.tags.map((tag) => tag.name);
|
|
4036
|
+
// check if @global_test_data tag is present
|
|
4037
|
+
if (this.tags.includes("@global_test_data")) {
|
|
4038
|
+
this.saveTestDataAsGlobal({}, world);
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
// update test data based on feature/scenario
|
|
4042
|
+
let envName = null;
|
|
4043
|
+
if (this.context && this.context.environment) {
|
|
4044
|
+
envName = this.context.environment.name;
|
|
4045
|
+
}
|
|
4046
|
+
if (!process.env.TEMP_RUN) {
|
|
4047
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
4048
|
+
}
|
|
4049
|
+
await loadBrunoParams(this.context, this.context.environment.name);
|
|
4050
|
+
}
|
|
4051
|
+
async afterScenario(world, scenario) { }
|
|
3310
4052
|
async beforeStep(world, step) {
|
|
4053
|
+
if (!this.beforeScenarioCalled) {
|
|
4054
|
+
this.beforeScenario(world, step);
|
|
4055
|
+
}
|
|
3311
4056
|
if (this.stepIndex === undefined) {
|
|
3312
4057
|
this.stepIndex = 0;
|
|
3313
4058
|
}
|
|
@@ -3324,30 +4069,22 @@ class StableBrowser {
|
|
|
3324
4069
|
else {
|
|
3325
4070
|
this.stepName = "step " + this.stepIndex;
|
|
3326
4071
|
}
|
|
3327
|
-
if (this.context) {
|
|
3328
|
-
this.context.examplesRow = extractStepExampleParameters(step);
|
|
3329
|
-
}
|
|
3330
4072
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
3331
4073
|
if (this.context.browserObject.context) {
|
|
3332
4074
|
await this.context.browserObject.context.tracing.startChunk({ title: this.stepName });
|
|
3333
4075
|
}
|
|
3334
4076
|
}
|
|
3335
|
-
if (this.tags === null && step && step.pickle && step.pickle.tags) {
|
|
3336
|
-
this.tags = step.pickle.tags.map((tag) => tag.name);
|
|
3337
|
-
// check if @global_test_data tag is present
|
|
3338
|
-
if (this.tags.includes("@global_test_data")) {
|
|
3339
|
-
this.saveTestDataAsGlobal({}, world);
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
4077
|
if (this.initSnapshotTaken === false) {
|
|
3343
4078
|
this.initSnapshotTaken = true;
|
|
3344
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4079
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3345
4080
|
const snapshot = await this.getAriaSnapshot();
|
|
3346
4081
|
if (snapshot) {
|
|
3347
4082
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3348
4083
|
}
|
|
3349
4084
|
}
|
|
3350
4085
|
}
|
|
4086
|
+
this.context.routeResults = null;
|
|
4087
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
3351
4088
|
}
|
|
3352
4089
|
async getAriaSnapshot() {
|
|
3353
4090
|
try {
|
|
@@ -3363,18 +4100,68 @@ class StableBrowser {
|
|
|
3363
4100
|
const content = [`- path: ${path}`, `- title: ${title}`];
|
|
3364
4101
|
const timeout = this.configuration.ariaSnapshotTimeout ? this.configuration.ariaSnapshotTimeout : 3000;
|
|
3365
4102
|
for (let i = 0; i < frames.length; i++) {
|
|
3366
|
-
content.push(`- frame: ${i}`);
|
|
3367
4103
|
const frame = frames[i];
|
|
3368
|
-
|
|
3369
|
-
|
|
4104
|
+
try {
|
|
4105
|
+
// Ensure frame is attached and has body
|
|
4106
|
+
const body = frame.locator("body");
|
|
4107
|
+
await body.waitFor({ timeout: 200 }); // wait explicitly
|
|
4108
|
+
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4109
|
+
content.push(`- frame: ${i}`);
|
|
4110
|
+
content.push(snapshot);
|
|
4111
|
+
}
|
|
4112
|
+
catch (innerErr) { }
|
|
3370
4113
|
}
|
|
3371
4114
|
return content.join("\n");
|
|
3372
4115
|
}
|
|
3373
4116
|
catch (e) {
|
|
3374
|
-
console.
|
|
4117
|
+
console.log("Error in getAriaSnapshot");
|
|
4118
|
+
//console.debug(e);
|
|
3375
4119
|
}
|
|
3376
4120
|
return null;
|
|
3377
4121
|
}
|
|
4122
|
+
/**
|
|
4123
|
+
* Sends command with custom payload to report.
|
|
4124
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4125
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4126
|
+
* @param content - Content of the command to be shown in the report.
|
|
4127
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4128
|
+
* @param world - Optional world context.
|
|
4129
|
+
* @public
|
|
4130
|
+
*/
|
|
4131
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4132
|
+
const state = {
|
|
4133
|
+
options,
|
|
4134
|
+
world,
|
|
4135
|
+
locate: false,
|
|
4136
|
+
scroll: false,
|
|
4137
|
+
screenshot: options.screenshot ?? false,
|
|
4138
|
+
highlight: options.highlight ?? false,
|
|
4139
|
+
type: Types.REPORT_COMMAND,
|
|
4140
|
+
text: commandText,
|
|
4141
|
+
_text: commandText,
|
|
4142
|
+
operation: "report_command",
|
|
4143
|
+
log: "***** " + commandText + " *****\n",
|
|
4144
|
+
};
|
|
4145
|
+
try {
|
|
4146
|
+
await _preCommand(state, this);
|
|
4147
|
+
const payload = {
|
|
4148
|
+
type: options.type ?? "text",
|
|
4149
|
+
content: content,
|
|
4150
|
+
screenshotId: null,
|
|
4151
|
+
};
|
|
4152
|
+
state.payload = payload;
|
|
4153
|
+
if (commandStatus === "FAILED") {
|
|
4154
|
+
state.throwError = true;
|
|
4155
|
+
throw new Error("Command failed");
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
catch (e) {
|
|
4159
|
+
await _commandError(state, e, this);
|
|
4160
|
+
}
|
|
4161
|
+
finally {
|
|
4162
|
+
await _commandFinally(state, this);
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
3378
4165
|
async afterStep(world, step) {
|
|
3379
4166
|
this.stepName = null;
|
|
3380
4167
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3382,10 +4169,12 @@ class StableBrowser {
|
|
|
3382
4169
|
await this.context.browserObject.context.tracing.stopChunk({
|
|
3383
4170
|
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
3384
4171
|
});
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
4172
|
+
if (world && world.attach) {
|
|
4173
|
+
await world.attach(JSON.stringify({
|
|
4174
|
+
type: "trace",
|
|
4175
|
+
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4176
|
+
}), "application/json+trace");
|
|
4177
|
+
}
|
|
3389
4178
|
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
3390
4179
|
}
|
|
3391
4180
|
}
|
|
@@ -3399,6 +4188,30 @@ class StableBrowser {
|
|
|
3399
4188
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3400
4189
|
}
|
|
3401
4190
|
}
|
|
4191
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4192
|
+
if (!process.env.TEMP_RUN) {
|
|
4193
|
+
const state = {
|
|
4194
|
+
world,
|
|
4195
|
+
locate: false,
|
|
4196
|
+
scroll: false,
|
|
4197
|
+
screenshot: true,
|
|
4198
|
+
highlight: true,
|
|
4199
|
+
type: Types.STEP_COMPLETE,
|
|
4200
|
+
text: "end of scenario",
|
|
4201
|
+
_text: "end of scenario",
|
|
4202
|
+
operation: "step_complete",
|
|
4203
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4204
|
+
};
|
|
4205
|
+
try {
|
|
4206
|
+
await _preCommand(state, this);
|
|
4207
|
+
}
|
|
4208
|
+
catch (e) {
|
|
4209
|
+
await _commandError(state, e, this);
|
|
4210
|
+
}
|
|
4211
|
+
finally {
|
|
4212
|
+
await _commandFinally(state, this);
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
3402
4215
|
}
|
|
3403
4216
|
}
|
|
3404
4217
|
function createTimedPromise(promise, label) {
|