automation_model 1.0.683-dev → 1.0.683-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/lib/analyze_helper.js.map +1 -1
- package/lib/api.d.ts +0 -1
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +4 -2
- package/lib/auto_page.js +181 -70
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +29 -9
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.d.ts +1 -0
- package/lib/bruno.js +120 -21
- package/lib/bruno.js.map +1 -1
- package/lib/command_common.js +9 -1
- package/lib/command_common.js.map +1 -1
- package/lib/date_time.js.map +1 -1
- package/lib/drawRect.js.map +1 -1
- package/lib/environment.d.ts +1 -0
- package/lib/environment.js +1 -0
- package/lib/environment.js.map +1 -1
- package/lib/error-messages.js.map +1 -1
- package/lib/file_checker.d.ts +1 -0
- package/lib/file_checker.js +61 -0
- package/lib/file_checker.js.map +1 -0
- package/lib/find_function.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/init_browser.js +4 -4
- package/lib/init_browser.js.map +1 -1
- package/lib/locate_element.js.map +1 -1
- package/lib/locator.d.ts +1 -0
- package/lib/locator.js +10 -3
- package/lib/locator.js.map +1 -1
- package/lib/locator_log.js.map +1 -1
- package/lib/network.d.ts +2 -0
- package/lib/network.js +148 -0
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +21 -0
- package/lib/route.js +390 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +3 -3
- package/lib/snapshot_validation.d.ts +37 -0
- package/lib/snapshot_validation.js +357 -0
- package/lib/snapshot_validation.js.map +1 -0
- package/lib/stable_browser.d.ts +62 -25
- package/lib/stable_browser.js +1101 -261
- package/lib/stable_browser.js.map +1 -1
- package/lib/table.d.ts +9 -7
- package/lib/table.js +82 -12
- package/lib/table.js.map +1 -1
- package/lib/table_analyze.js.map +1 -1
- package/lib/table_helper.js.map +1 -1
- package/lib/test_context.d.ts +1 -0
- package/lib/test_context.js +1 -0
- package/lib/test_context.js.map +1 -1
- package/lib/utils.d.ts +3 -2
- package/lib/utils.js +83 -57
- package/lib/utils.js.map +1 -1
- package/package.json +14 -8
package/lib/stable_browser.js
CHANGED
|
@@ -10,35 +10,42 @@ 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";
|
|
21
|
-
import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
22
|
+
import { networkAfterStep, networkBeforeStep, 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,19 @@ 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
|
+
// console.log("Fast mode enabled from environment variable");
|
|
133
|
+
this.fastMode = true;
|
|
134
|
+
}
|
|
135
|
+
if (process.env.FAST_MODE === "false") {
|
|
136
|
+
this.fastMode = false;
|
|
137
|
+
}
|
|
138
|
+
if (this.context) {
|
|
139
|
+
this.context.fastMode = this.fastMode;
|
|
140
|
+
}
|
|
112
141
|
this.registerEventListeners(this.context);
|
|
113
142
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
114
143
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -119,6 +148,9 @@ class StableBrowser {
|
|
|
119
148
|
if (!context.pageLoading) {
|
|
120
149
|
context.pageLoading = { status: false };
|
|
121
150
|
}
|
|
151
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
152
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
153
|
+
}
|
|
122
154
|
context.playContext.on("page", async function (page) {
|
|
123
155
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
124
156
|
console.log("close unexpected popups");
|
|
@@ -127,6 +159,14 @@ class StableBrowser {
|
|
|
127
159
|
}
|
|
128
160
|
context.pageLoading.status = true;
|
|
129
161
|
this.page = page;
|
|
162
|
+
try {
|
|
163
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
164
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error("Error on dialog accept registration", error);
|
|
169
|
+
}
|
|
130
170
|
context.page = page;
|
|
131
171
|
context.pages.push(page);
|
|
132
172
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -178,7 +218,9 @@ class StableBrowser {
|
|
|
178
218
|
if (newContextCreated) {
|
|
179
219
|
this.registerEventListeners(this.context);
|
|
180
220
|
await this.goto(this.context.environment.baseUrl);
|
|
181
|
-
|
|
221
|
+
if (!this.fastMode) {
|
|
222
|
+
await this.waitForPageLoad();
|
|
223
|
+
}
|
|
182
224
|
}
|
|
183
225
|
}
|
|
184
226
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -272,6 +314,7 @@ class StableBrowser {
|
|
|
272
314
|
if (!url) {
|
|
273
315
|
throw new Error("url is null, verify that the environment file is correct");
|
|
274
316
|
}
|
|
317
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
275
318
|
if (!url.startsWith("http")) {
|
|
276
319
|
url = "https://" + url;
|
|
277
320
|
}
|
|
@@ -303,6 +346,64 @@ class StableBrowser {
|
|
|
303
346
|
await _commandFinally(state, this);
|
|
304
347
|
}
|
|
305
348
|
}
|
|
349
|
+
async goBack(options, world = null) {
|
|
350
|
+
const state = {
|
|
351
|
+
value: "",
|
|
352
|
+
world: world,
|
|
353
|
+
type: Types.GO_BACK,
|
|
354
|
+
text: `Browser navigate back`,
|
|
355
|
+
operation: "goBack",
|
|
356
|
+
log: "***** navigate back *****\n",
|
|
357
|
+
info: {},
|
|
358
|
+
locate: false,
|
|
359
|
+
scroll: false,
|
|
360
|
+
screenshot: false,
|
|
361
|
+
highlight: false,
|
|
362
|
+
};
|
|
363
|
+
try {
|
|
364
|
+
await _preCommand(state, this);
|
|
365
|
+
await this.page.goBack({
|
|
366
|
+
waitUntil: "load",
|
|
367
|
+
});
|
|
368
|
+
await _screenshot(state, this);
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
console.error("Error on goBack", error);
|
|
372
|
+
_commandError(state, error, this);
|
|
373
|
+
}
|
|
374
|
+
finally {
|
|
375
|
+
await _commandFinally(state, this);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async goForward(options, world = null) {
|
|
379
|
+
const state = {
|
|
380
|
+
value: "",
|
|
381
|
+
world: world,
|
|
382
|
+
type: Types.GO_FORWARD,
|
|
383
|
+
text: `Browser navigate forward`,
|
|
384
|
+
operation: "goForward",
|
|
385
|
+
log: "***** navigate forward *****\n",
|
|
386
|
+
info: {},
|
|
387
|
+
locate: false,
|
|
388
|
+
scroll: false,
|
|
389
|
+
screenshot: false,
|
|
390
|
+
highlight: false,
|
|
391
|
+
};
|
|
392
|
+
try {
|
|
393
|
+
await _preCommand(state, this);
|
|
394
|
+
await this.page.goForward({
|
|
395
|
+
waitUntil: "load",
|
|
396
|
+
});
|
|
397
|
+
await _screenshot(state, this);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
console.error("Error on goForward", error);
|
|
401
|
+
_commandError(state, error, this);
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
await _commandFinally(state, this);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
306
407
|
async _getLocator(locator, scope, _params) {
|
|
307
408
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
308
409
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -416,7 +517,7 @@ class StableBrowser {
|
|
|
416
517
|
}
|
|
417
518
|
return { elementCount: tagCount, randomToken };
|
|
418
519
|
}
|
|
419
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
520
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
420
521
|
if (!info) {
|
|
421
522
|
info = {};
|
|
422
523
|
}
|
|
@@ -428,14 +529,13 @@ class StableBrowser {
|
|
|
428
529
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
429
530
|
}
|
|
430
531
|
let locatorSearch = selectorHierarchy[index];
|
|
431
|
-
let originalLocatorSearch = "";
|
|
432
532
|
try {
|
|
433
|
-
|
|
434
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
533
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
435
534
|
}
|
|
436
535
|
catch (e) {
|
|
437
536
|
console.error(e);
|
|
438
537
|
}
|
|
538
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
439
539
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
440
540
|
let locator = null;
|
|
441
541
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -483,7 +583,7 @@ class StableBrowser {
|
|
|
483
583
|
}
|
|
484
584
|
return;
|
|
485
585
|
}
|
|
486
|
-
if (info.locatorLog && count === 0) {
|
|
586
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
487
587
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
488
588
|
}
|
|
489
589
|
for (let j = 0; j < count; j++) {
|
|
@@ -498,7 +598,7 @@ class StableBrowser {
|
|
|
498
598
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
499
599
|
}
|
|
500
600
|
}
|
|
501
|
-
else {
|
|
601
|
+
else if (logErrors) {
|
|
502
602
|
info.failCause.visible = visible;
|
|
503
603
|
info.failCause.enabled = enabled;
|
|
504
604
|
if (!info.printMessages) {
|
|
@@ -590,7 +690,7 @@ class StableBrowser {
|
|
|
590
690
|
let element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
591
691
|
if (!element.rerun) {
|
|
592
692
|
const randomToken = Math.random().toString(36).substring(7);
|
|
593
|
-
element.evaluate((el, randomToken) => {
|
|
693
|
+
await element.evaluate((el, randomToken) => {
|
|
594
694
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
595
695
|
}, randomToken);
|
|
596
696
|
// if (element._frame) {
|
|
@@ -643,7 +743,7 @@ class StableBrowser {
|
|
|
643
743
|
break;
|
|
644
744
|
}
|
|
645
745
|
catch (error) {
|
|
646
|
-
console.error("frame not found " + frameLocator.css);
|
|
746
|
+
// console.error("frame not found " + frameLocator.css);
|
|
647
747
|
}
|
|
648
748
|
}
|
|
649
749
|
}
|
|
@@ -839,7 +939,7 @@ class StableBrowser {
|
|
|
839
939
|
}
|
|
840
940
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
841
941
|
}
|
|
842
|
-
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) {
|
|
843
943
|
let foundElements = [];
|
|
844
944
|
const result = {
|
|
845
945
|
foundElements: foundElements,
|
|
@@ -858,7 +958,9 @@ class StableBrowser {
|
|
|
858
958
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
859
959
|
}
|
|
860
960
|
catch (e) {
|
|
861
|
-
|
|
961
|
+
if (logErrors) {
|
|
962
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
963
|
+
}
|
|
862
964
|
}
|
|
863
965
|
}
|
|
864
966
|
if (foundLocators.length === 1) {
|
|
@@ -899,7 +1001,7 @@ class StableBrowser {
|
|
|
899
1001
|
});
|
|
900
1002
|
result.locatorIndex = i;
|
|
901
1003
|
}
|
|
902
|
-
else {
|
|
1004
|
+
else if (logErrors) {
|
|
903
1005
|
info.failCause.foundMultiple = true;
|
|
904
1006
|
if (info.locatorLog) {
|
|
905
1007
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -1022,7 +1124,9 @@ class StableBrowser {
|
|
|
1022
1124
|
try {
|
|
1023
1125
|
await _preCommand(state, this);
|
|
1024
1126
|
await performAction("click", state.element, options, this, state, _params);
|
|
1025
|
-
|
|
1127
|
+
if (!this.fastMode) {
|
|
1128
|
+
await this.waitForPageLoad();
|
|
1129
|
+
}
|
|
1026
1130
|
return state.info;
|
|
1027
1131
|
}
|
|
1028
1132
|
catch (e) {
|
|
@@ -1085,7 +1189,7 @@ class StableBrowser {
|
|
|
1085
1189
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1086
1190
|
// console.log(`Highlighting while running from recorder`);
|
|
1087
1191
|
await this._highlightElements(state.element);
|
|
1088
|
-
await state.element.setChecked(checked);
|
|
1192
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1089
1193
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1090
1194
|
// await this._unHighlightElements(element);
|
|
1091
1195
|
// }
|
|
@@ -1097,11 +1201,28 @@ class StableBrowser {
|
|
|
1097
1201
|
this.logger.info("element did not change its state, ignoring...");
|
|
1098
1202
|
}
|
|
1099
1203
|
else {
|
|
1204
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1100
1205
|
//await this.closeUnexpectedPopups();
|
|
1101
1206
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1102
|
-
state.
|
|
1103
|
-
|
|
1104
|
-
|
|
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
|
+
}
|
|
1105
1226
|
}
|
|
1106
1227
|
}
|
|
1107
1228
|
await this.waitForPageLoad();
|
|
@@ -1397,7 +1518,9 @@ class StableBrowser {
|
|
|
1397
1518
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1398
1519
|
}
|
|
1399
1520
|
}
|
|
1521
|
+
//if (!this.fastMode) {
|
|
1400
1522
|
await _screenshot(state, this);
|
|
1523
|
+
//}
|
|
1401
1524
|
if (enter === true) {
|
|
1402
1525
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1403
1526
|
await this.page.keyboard.press("Enter");
|
|
@@ -1457,6 +1580,41 @@ class StableBrowser {
|
|
|
1457
1580
|
await _commandFinally(state, this);
|
|
1458
1581
|
}
|
|
1459
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);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1460
1618
|
async getText(selectors, _params = null, options = {}, info = {}, world = null) {
|
|
1461
1619
|
return await this._getText(selectors, 0, _params, options, info, world);
|
|
1462
1620
|
}
|
|
@@ -1650,6 +1808,83 @@ class StableBrowser {
|
|
|
1650
1808
|
await _commandFinally(state, this);
|
|
1651
1809
|
}
|
|
1652
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);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1653
1888
|
async waitForUserInput(message, world = null) {
|
|
1654
1889
|
if (!message) {
|
|
1655
1890
|
message = "# Wait for user input. Press any key to continue";
|
|
@@ -1790,12 +2025,7 @@ class StableBrowser {
|
|
|
1790
2025
|
}
|
|
1791
2026
|
}
|
|
1792
2027
|
getTestData(world = null) {
|
|
1793
|
-
|
|
1794
|
-
let data = {};
|
|
1795
|
-
if (fs.existsSync(dataFile)) {
|
|
1796
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1797
|
-
}
|
|
1798
|
-
return data;
|
|
2028
|
+
return _getTestData(world, this.context, this);
|
|
1799
2029
|
}
|
|
1800
2030
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1801
2031
|
// collect url/path/title
|
|
@@ -1984,6 +2214,95 @@ class StableBrowser {
|
|
|
1984
2214
|
state.value = await state.element.getAttribute(attribute);
|
|
1985
2215
|
break;
|
|
1986
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
|
+
}
|
|
1987
2306
|
state.info.value = state.value;
|
|
1988
2307
|
this.setTestData({ [variable]: state.value }, world);
|
|
1989
2308
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
@@ -2049,17 +2368,42 @@ class StableBrowser {
|
|
|
2049
2368
|
let regex;
|
|
2050
2369
|
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2051
2370
|
const patternBody = expectedValue.slice(1, -1);
|
|
2052
|
-
|
|
2371
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2372
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2373
|
+
state.info.regex = true;
|
|
2053
2374
|
}
|
|
2054
2375
|
else {
|
|
2055
2376
|
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2056
2377
|
regex = new RegExp(escapedPattern, "g");
|
|
2057
2378
|
}
|
|
2058
|
-
if (
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
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
|
+
}
|
|
2063
2407
|
}
|
|
2064
2408
|
return state.info;
|
|
2065
2409
|
}
|
|
@@ -2070,61 +2414,308 @@ class StableBrowser {
|
|
|
2070
2414
|
await _commandFinally(state, this);
|
|
2071
2415
|
}
|
|
2072
2416
|
}
|
|
2073
|
-
async
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
timeout = options.timeout;
|
|
2090
|
-
}
|
|
2091
|
-
const serviceUrl = _getServerUrl() + "/api/mail/createLinkOrCodeFromEmail";
|
|
2092
|
-
const request = {
|
|
2093
|
-
method: "POST",
|
|
2094
|
-
url: serviceUrl,
|
|
2095
|
-
headers: {
|
|
2096
|
-
"Content-Type": "application/json",
|
|
2097
|
-
Authorization: `Bearer ${process.env.TOKEN}`,
|
|
2098
|
-
},
|
|
2099
|
-
data: JSON.stringify({
|
|
2100
|
-
email: emailAddress,
|
|
2101
|
-
}),
|
|
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,
|
|
2102
2433
|
};
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
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;
|
|
2492
|
+
}
|
|
2493
|
+
else {
|
|
2494
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2495
|
+
regex = new RegExp(escapedPattern, "g");
|
|
2496
|
+
}
|
|
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
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
return state.info;
|
|
2530
|
+
}
|
|
2531
|
+
catch (e) {
|
|
2532
|
+
await _commandError(state, e, this);
|
|
2533
|
+
}
|
|
2534
|
+
finally {
|
|
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
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2559
|
+
const startTime = Date.now();
|
|
2560
|
+
let conditionMet = false;
|
|
2561
|
+
let currentValue = null;
|
|
2562
|
+
let lastError = null;
|
|
2563
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2564
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2565
|
+
const elapsedTime = Date.now() - startTime;
|
|
2566
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2567
|
+
try {
|
|
2568
|
+
// Try to execute _preCommand (element location)
|
|
2569
|
+
await _preCommand(state, this);
|
|
2570
|
+
// If _preCommand succeeds, start condition checking
|
|
2571
|
+
const checkCondition = async () => {
|
|
2572
|
+
try {
|
|
2573
|
+
switch (condition.toLowerCase()) {
|
|
2574
|
+
case "checked":
|
|
2575
|
+
currentValue = await state.element.isChecked();
|
|
2576
|
+
return currentValue === true;
|
|
2577
|
+
case "unchecked":
|
|
2578
|
+
currentValue = await state.element.isChecked();
|
|
2579
|
+
return currentValue === false;
|
|
2580
|
+
case "visible":
|
|
2581
|
+
currentValue = await state.element.isVisible();
|
|
2582
|
+
return currentValue === true;
|
|
2583
|
+
case "hidden":
|
|
2584
|
+
currentValue = await state.element.isVisible();
|
|
2585
|
+
return currentValue === false;
|
|
2586
|
+
case "enabled":
|
|
2587
|
+
currentValue = await state.element.isDisabled();
|
|
2588
|
+
return currentValue === false;
|
|
2589
|
+
case "disabled":
|
|
2590
|
+
currentValue = await state.element.isDisabled();
|
|
2591
|
+
return currentValue === true;
|
|
2592
|
+
case "editable":
|
|
2593
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2594
|
+
currentValue = await state.element.isContentEditable();
|
|
2595
|
+
return currentValue === true;
|
|
2596
|
+
default:
|
|
2597
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2598
|
+
state.info.success = false;
|
|
2599
|
+
return false;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
catch (error) {
|
|
2603
|
+
// Don't throw here, just return false to continue retrying
|
|
2604
|
+
return false;
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
// Inner loop for condition checking (once element is located)
|
|
2608
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2609
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2610
|
+
conditionMet = await checkCondition();
|
|
2611
|
+
if (conditionMet) {
|
|
2612
|
+
break;
|
|
2613
|
+
}
|
|
2614
|
+
// Check if we still have time for another attempt
|
|
2615
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2616
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2617
|
+
}
|
|
2618
|
+
else {
|
|
2619
|
+
break;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
// If we got here and condition is met, break out of main loop
|
|
2623
|
+
if (conditionMet) {
|
|
2624
|
+
break;
|
|
2625
|
+
}
|
|
2626
|
+
// If condition not met but no exception, we've timed out
|
|
2627
|
+
break;
|
|
2628
|
+
}
|
|
2629
|
+
catch (e) {
|
|
2630
|
+
lastError = e;
|
|
2631
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2632
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2633
|
+
// Check if we have enough time left to retry
|
|
2634
|
+
if (timeLeft > 100) {
|
|
2635
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2636
|
+
}
|
|
2637
|
+
else {
|
|
2638
|
+
break;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2643
|
+
state.info = {
|
|
2644
|
+
success: conditionMet,
|
|
2645
|
+
conditionMet,
|
|
2646
|
+
actualWaitTime,
|
|
2647
|
+
currentValue,
|
|
2648
|
+
lastError: lastError?.message || null,
|
|
2649
|
+
message: conditionMet
|
|
2650
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2651
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2652
|
+
};
|
|
2653
|
+
if (lastError) {
|
|
2654
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2655
|
+
}
|
|
2656
|
+
try {
|
|
2657
|
+
await _commandFinally(state, this);
|
|
2658
|
+
}
|
|
2659
|
+
catch (finallyError) {
|
|
2660
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2661
|
+
}
|
|
2662
|
+
return state.info;
|
|
2663
|
+
}
|
|
2664
|
+
async extractEmailData(emailAddress, options, world) {
|
|
2665
|
+
if (!emailAddress) {
|
|
2666
|
+
throw new Error("email address is null");
|
|
2667
|
+
}
|
|
2668
|
+
// check if address contain @
|
|
2669
|
+
if (emailAddress.indexOf("@") === -1) {
|
|
2670
|
+
emailAddress = emailAddress + "@blinq-mail.io";
|
|
2671
|
+
}
|
|
2672
|
+
else {
|
|
2673
|
+
if (!emailAddress.toLowerCase().endsWith("@blinq-mail.io")) {
|
|
2674
|
+
throw new Error("email address should end with @blinq-mail.io");
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
const startTime = Date.now();
|
|
2678
|
+
let timeout = 60000;
|
|
2679
|
+
if (options && options.timeout) {
|
|
2680
|
+
timeout = options.timeout;
|
|
2681
|
+
}
|
|
2682
|
+
const serviceUrl = _getServerUrl() + "/api/mail/createLinkOrCodeFromEmail";
|
|
2683
|
+
const request = {
|
|
2684
|
+
method: "POST",
|
|
2685
|
+
url: serviceUrl,
|
|
2686
|
+
headers: {
|
|
2687
|
+
"Content-Type": "application/json",
|
|
2688
|
+
Authorization: `Bearer ${process.env.TOKEN}`,
|
|
2689
|
+
},
|
|
2690
|
+
data: JSON.stringify({
|
|
2691
|
+
email: emailAddress,
|
|
2692
|
+
}),
|
|
2693
|
+
};
|
|
2694
|
+
let errorCount = 0;
|
|
2695
|
+
while (true) {
|
|
2696
|
+
try {
|
|
2697
|
+
let result = await this.context.api.request(request);
|
|
2698
|
+
// the response body expected to be the following:
|
|
2699
|
+
// {
|
|
2700
|
+
// "status": true,
|
|
2701
|
+
// "content": {
|
|
2702
|
+
// "url": "",
|
|
2703
|
+
// "code": "112112",
|
|
2704
|
+
// "name": "generate_link_or_code"
|
|
2705
|
+
// }
|
|
2706
|
+
//}
|
|
2707
|
+
if ((result && result.data, result.data.status === true)) {
|
|
2708
|
+
let codeOrUrlFound = false;
|
|
2709
|
+
let emailCode = null;
|
|
2710
|
+
let emailUrl = null;
|
|
2711
|
+
// check if a code is returned
|
|
2712
|
+
if (result.data.content && result.data.content.code) {
|
|
2713
|
+
let code = result.data.content.code;
|
|
2714
|
+
this.setTestData({ emailCode: code }, world);
|
|
2715
|
+
this.logger.info("set test data: emailCode = " + code);
|
|
2716
|
+
emailCode = code;
|
|
2717
|
+
codeOrUrlFound = true;
|
|
2718
|
+
}
|
|
2128
2719
|
// check if a url is returned
|
|
2129
2720
|
if (result.data.content && result.data.content.url) {
|
|
2130
2721
|
let url = result.data.content.url;
|
|
@@ -2227,56 +2818,49 @@ class StableBrowser {
|
|
|
2227
2818
|
console.debug(error);
|
|
2228
2819
|
}
|
|
2229
2820
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
// });
|
|
2273
|
-
// }
|
|
2274
|
-
// } catch (error) {
|
|
2275
|
-
// // console.debug(error);
|
|
2276
|
-
// }
|
|
2277
|
-
// }
|
|
2821
|
+
_matcher(text) {
|
|
2822
|
+
if (!text) {
|
|
2823
|
+
return { matcher: "contains", queryText: "" };
|
|
2824
|
+
}
|
|
2825
|
+
if (text.length < 2) {
|
|
2826
|
+
return { matcher: "contains", queryText: text };
|
|
2827
|
+
}
|
|
2828
|
+
const split = text.split(":");
|
|
2829
|
+
const matcher = split[0].toLowerCase();
|
|
2830
|
+
const queryText = split.slice(1).join(":").trim();
|
|
2831
|
+
return { matcher, queryText };
|
|
2832
|
+
}
|
|
2833
|
+
_getDomain(url) {
|
|
2834
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
2835
|
+
return "";
|
|
2836
|
+
}
|
|
2837
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
2838
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
2839
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
2840
|
+
}
|
|
2841
|
+
let n = hostnameFragments.length;
|
|
2842
|
+
let fragments = [...hostnameFragments];
|
|
2843
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
2844
|
+
hostnameFragments.pop();
|
|
2845
|
+
n = hostnameFragments.length;
|
|
2846
|
+
}
|
|
2847
|
+
if (n == 0) {
|
|
2848
|
+
if (fragments[0] === "www")
|
|
2849
|
+
fragments = fragments.slice(1);
|
|
2850
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
2851
|
+
}
|
|
2852
|
+
if (hostnameFragments[0] === "www")
|
|
2853
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
2854
|
+
return hostnameFragments.join(".");
|
|
2855
|
+
}
|
|
2856
|
+
/**
|
|
2857
|
+
* Verify the page path matches the given path.
|
|
2858
|
+
* @param {string} pathPart - The path to verify.
|
|
2859
|
+
* @param {object} options - Options for verification.
|
|
2860
|
+
* @param {object} world - The world context.
|
|
2861
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2862
|
+
*/
|
|
2278
2863
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2279
|
-
const startTime = Date.now();
|
|
2280
2864
|
let error = null;
|
|
2281
2865
|
let screenshotId = null;
|
|
2282
2866
|
let screenshotPath = null;
|
|
@@ -2290,113 +2874,212 @@ class StableBrowser {
|
|
|
2290
2874
|
pathPart = newValue;
|
|
2291
2875
|
}
|
|
2292
2876
|
info.pathPart = pathPart;
|
|
2877
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
2878
|
+
const state = {
|
|
2879
|
+
text_search: queryText,
|
|
2880
|
+
options,
|
|
2881
|
+
world,
|
|
2882
|
+
locate: false,
|
|
2883
|
+
scroll: false,
|
|
2884
|
+
highlight: false,
|
|
2885
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
2886
|
+
text: `Verify the page url is ${queryText}`,
|
|
2887
|
+
_text: `Verify the page url is ${queryText}`,
|
|
2888
|
+
operation: "verifyPagePath",
|
|
2889
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
2890
|
+
};
|
|
2293
2891
|
try {
|
|
2892
|
+
await _preCommand(state, this);
|
|
2893
|
+
state.info.text = queryText;
|
|
2294
2894
|
for (let i = 0; i < 30; i++) {
|
|
2295
2895
|
const url = await this.page.url();
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2896
|
+
switch (matcher) {
|
|
2897
|
+
case "exact":
|
|
2898
|
+
if (url !== queryText) {
|
|
2899
|
+
if (i === 29) {
|
|
2900
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
2901
|
+
}
|
|
2902
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2903
|
+
continue;
|
|
2904
|
+
}
|
|
2905
|
+
break;
|
|
2906
|
+
case "contains":
|
|
2907
|
+
if (!url.includes(queryText)) {
|
|
2908
|
+
if (i === 29) {
|
|
2909
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
2910
|
+
}
|
|
2911
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2912
|
+
continue;
|
|
2913
|
+
}
|
|
2914
|
+
break;
|
|
2915
|
+
case "starts-with":
|
|
2916
|
+
{
|
|
2917
|
+
const domain = this._getDomain(url);
|
|
2918
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
2919
|
+
if (i === 29) {
|
|
2920
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
2921
|
+
}
|
|
2922
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2923
|
+
continue;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
break;
|
|
2927
|
+
case "ends-with":
|
|
2928
|
+
{
|
|
2929
|
+
const urlObj = new URL(url);
|
|
2930
|
+
let route = "/";
|
|
2931
|
+
if (urlObj.pathname !== "/") {
|
|
2932
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
2933
|
+
}
|
|
2934
|
+
else {
|
|
2935
|
+
route = "/";
|
|
2936
|
+
}
|
|
2937
|
+
if (route !== queryText) {
|
|
2938
|
+
if (i === 29) {
|
|
2939
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
2940
|
+
}
|
|
2941
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2942
|
+
continue;
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
break;
|
|
2946
|
+
case "regex":
|
|
2947
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
2948
|
+
if (!regex.test(url)) {
|
|
2949
|
+
if (i === 29) {
|
|
2950
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
2951
|
+
}
|
|
2952
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2953
|
+
continue;
|
|
2954
|
+
}
|
|
2955
|
+
break;
|
|
2956
|
+
default:
|
|
2957
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
2958
|
+
if (!url.includes(pathPart)) {
|
|
2959
|
+
if (i === 29) {
|
|
2960
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
2961
|
+
}
|
|
2962
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2963
|
+
continue;
|
|
2964
|
+
}
|
|
2302
2965
|
}
|
|
2303
|
-
|
|
2304
|
-
return info;
|
|
2966
|
+
await _screenshot(state, this);
|
|
2967
|
+
return state.info;
|
|
2305
2968
|
}
|
|
2306
2969
|
}
|
|
2307
2970
|
catch (e) {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
info.screenshotPath = screenshotPath;
|
|
2312
|
-
Object.assign(e, { info: info });
|
|
2313
|
-
error = e;
|
|
2314
|
-
// throw e;
|
|
2315
|
-
await _commandError({ text: "verifyPagePath", operation: "verifyPagePath", pathPart, info }, e, this);
|
|
2971
|
+
state.info.failCause.lastError = e.message;
|
|
2972
|
+
state.info.failCause.assertionFailed = true;
|
|
2973
|
+
await _commandError(state, e, this);
|
|
2316
2974
|
}
|
|
2317
2975
|
finally {
|
|
2318
|
-
|
|
2319
|
-
_reportToWorld(world, {
|
|
2320
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2321
|
-
text: "Verify page path",
|
|
2322
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2323
|
-
screenshotId,
|
|
2324
|
-
result: error
|
|
2325
|
-
? {
|
|
2326
|
-
status: "FAILED",
|
|
2327
|
-
startTime,
|
|
2328
|
-
endTime,
|
|
2329
|
-
message: error?.message,
|
|
2330
|
-
}
|
|
2331
|
-
: {
|
|
2332
|
-
status: "PASSED",
|
|
2333
|
-
startTime,
|
|
2334
|
-
endTime,
|
|
2335
|
-
},
|
|
2336
|
-
info: info,
|
|
2337
|
-
});
|
|
2976
|
+
await _commandFinally(state, this);
|
|
2338
2977
|
}
|
|
2339
2978
|
}
|
|
2979
|
+
/**
|
|
2980
|
+
* Verify the page title matches the given title.
|
|
2981
|
+
* @param {string} title - The title to verify.
|
|
2982
|
+
* @param {object} options - Options for verification.
|
|
2983
|
+
* @param {object} world - The world context.
|
|
2984
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2985
|
+
*/
|
|
2340
2986
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2341
|
-
const startTime = Date.now();
|
|
2342
2987
|
let error = null;
|
|
2343
2988
|
let screenshotId = null;
|
|
2344
2989
|
let screenshotPath = null;
|
|
2345
2990
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2346
|
-
const info = {};
|
|
2347
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2348
|
-
info.operation = "verifyPageTitle";
|
|
2349
2991
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2350
2992
|
if (newValue !== title) {
|
|
2351
2993
|
this.logger.info(title + "=" + newValue);
|
|
2352
2994
|
title = newValue;
|
|
2353
2995
|
}
|
|
2354
|
-
|
|
2996
|
+
const { matcher, queryText } = this._matcher(title);
|
|
2997
|
+
const state = {
|
|
2998
|
+
text_search: queryText,
|
|
2999
|
+
options,
|
|
3000
|
+
world,
|
|
3001
|
+
locate: false,
|
|
3002
|
+
scroll: false,
|
|
3003
|
+
highlight: false,
|
|
3004
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
3005
|
+
text: `Verify the page title is ${queryText}`,
|
|
3006
|
+
_text: `Verify the page title is ${queryText}`,
|
|
3007
|
+
operation: "verifyPageTitle",
|
|
3008
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
3009
|
+
};
|
|
2355
3010
|
try {
|
|
3011
|
+
await _preCommand(state, this);
|
|
3012
|
+
state.info.text = queryText;
|
|
2356
3013
|
for (let i = 0; i < 30; i++) {
|
|
2357
3014
|
const foundTitle = await this.page.title();
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
3015
|
+
switch (matcher) {
|
|
3016
|
+
case "exact":
|
|
3017
|
+
if (foundTitle !== queryText) {
|
|
3018
|
+
if (i === 29) {
|
|
3019
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
3020
|
+
}
|
|
3021
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3022
|
+
continue;
|
|
3023
|
+
}
|
|
3024
|
+
break;
|
|
3025
|
+
case "contains":
|
|
3026
|
+
if (!foundTitle.includes(queryText)) {
|
|
3027
|
+
if (i === 29) {
|
|
3028
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
3029
|
+
}
|
|
3030
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3031
|
+
continue;
|
|
3032
|
+
}
|
|
3033
|
+
break;
|
|
3034
|
+
case "starts-with":
|
|
3035
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3036
|
+
if (i === 29) {
|
|
3037
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3038
|
+
}
|
|
3039
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3040
|
+
continue;
|
|
3041
|
+
}
|
|
3042
|
+
break;
|
|
3043
|
+
case "ends-with":
|
|
3044
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3045
|
+
if (i === 29) {
|
|
3046
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3047
|
+
}
|
|
3048
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3049
|
+
continue;
|
|
3050
|
+
}
|
|
3051
|
+
break;
|
|
3052
|
+
case "regex":
|
|
3053
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3054
|
+
if (!regex.test(foundTitle)) {
|
|
3055
|
+
if (i === 29) {
|
|
3056
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3057
|
+
}
|
|
3058
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3059
|
+
continue;
|
|
3060
|
+
}
|
|
3061
|
+
break;
|
|
3062
|
+
default:
|
|
3063
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3064
|
+
if (!foundTitle.includes(title)) {
|
|
3065
|
+
if (i === 29) {
|
|
3066
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3067
|
+
}
|
|
3068
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3069
|
+
continue;
|
|
3070
|
+
}
|
|
2364
3071
|
}
|
|
2365
|
-
|
|
2366
|
-
return info;
|
|
3072
|
+
await _screenshot(state, this);
|
|
3073
|
+
return state.info;
|
|
2367
3074
|
}
|
|
2368
3075
|
}
|
|
2369
3076
|
catch (e) {
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
info.screenshotPath = screenshotPath;
|
|
2374
|
-
Object.assign(e, { info: info });
|
|
2375
|
-
error = e;
|
|
2376
|
-
// throw e;
|
|
2377
|
-
await _commandError({ text: "verifyPageTitle", operation: "verifyPageTitle", title, info, throwError: true }, e, this);
|
|
3077
|
+
state.info.failCause.lastError = e.message;
|
|
3078
|
+
state.info.failCause.assertionFailed = true;
|
|
3079
|
+
await _commandError(state, e, this);
|
|
2378
3080
|
}
|
|
2379
3081
|
finally {
|
|
2380
|
-
|
|
2381
|
-
_reportToWorld(world, {
|
|
2382
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2383
|
-
text: "Verify page title",
|
|
2384
|
-
_text: "Verify the page title contains " + title,
|
|
2385
|
-
screenshotId,
|
|
2386
|
-
result: error
|
|
2387
|
-
? {
|
|
2388
|
-
status: "FAILED",
|
|
2389
|
-
startTime,
|
|
2390
|
-
endTime,
|
|
2391
|
-
message: error?.message,
|
|
2392
|
-
}
|
|
2393
|
-
: {
|
|
2394
|
-
status: "PASSED",
|
|
2395
|
-
startTime,
|
|
2396
|
-
endTime,
|
|
2397
|
-
},
|
|
2398
|
-
info: info,
|
|
2399
|
-
});
|
|
3082
|
+
await _commandFinally(state, this);
|
|
2400
3083
|
}
|
|
2401
3084
|
}
|
|
2402
3085
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2438,7 +3121,7 @@ class StableBrowser {
|
|
|
2438
3121
|
scroll: false,
|
|
2439
3122
|
highlight: false,
|
|
2440
3123
|
type: Types.VERIFY_PAGE_CONTAINS_TEXT,
|
|
2441
|
-
text: `Verify the text '${text}' exists in page`,
|
|
3124
|
+
text: `Verify the text '${maskValue(text)}' exists in page`,
|
|
2442
3125
|
_text: `Verify the text '${text}' exists in page`,
|
|
2443
3126
|
operation: "verifyTextExistInPage",
|
|
2444
3127
|
log: "***** verify text " + text + " exists in page *****\n",
|
|
@@ -2480,27 +3163,10 @@ class StableBrowser {
|
|
|
2480
3163
|
const frame = resultWithElementsFound[0].frame;
|
|
2481
3164
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2482
3165
|
await this._highlightElements(frame, dataAttribute);
|
|
2483
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2484
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2485
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2486
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2487
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2488
|
-
// .then(async () => {
|
|
2489
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2490
|
-
// })
|
|
2491
|
-
// .catch(
|
|
2492
|
-
// (e) => {}
|
|
2493
|
-
// console.error(e)
|
|
2494
|
-
// );
|
|
2495
|
-
// });
|
|
2496
|
-
// }
|
|
2497
3166
|
const element = await frame.locator(dataAttribute).first();
|
|
2498
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2499
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2500
3167
|
if (element) {
|
|
2501
3168
|
await this.scrollIfNeeded(element, state.info);
|
|
2502
3169
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2503
|
-
// await _screenshot(state, this, element);
|
|
2504
3170
|
}
|
|
2505
3171
|
}
|
|
2506
3172
|
await _screenshot(state, this);
|
|
@@ -2510,7 +3176,6 @@ class StableBrowser {
|
|
|
2510
3176
|
console.error(error);
|
|
2511
3177
|
}
|
|
2512
3178
|
}
|
|
2513
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2514
3179
|
}
|
|
2515
3180
|
catch (e) {
|
|
2516
3181
|
await _commandError(state, e, this);
|
|
@@ -2529,7 +3194,7 @@ class StableBrowser {
|
|
|
2529
3194
|
scroll: false,
|
|
2530
3195
|
highlight: false,
|
|
2531
3196
|
type: Types.WAIT_FOR_TEXT_TO_DISAPPEAR,
|
|
2532
|
-
text: `Verify the text '${text}' does not exist in page`,
|
|
3197
|
+
text: `Verify the text '${maskValue(text)}' does not exist in page`,
|
|
2533
3198
|
_text: `Verify the text '${text}' does not exist in page`,
|
|
2534
3199
|
operation: "verifyTextNotExistInPage",
|
|
2535
3200
|
log: "***** verify text " + text + " does not exist in page *****\n",
|
|
@@ -2592,6 +3257,8 @@ class StableBrowser {
|
|
|
2592
3257
|
operation: "verify_text_with_relation",
|
|
2593
3258
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2594
3259
|
};
|
|
3260
|
+
const cmdStartTime = Date.now();
|
|
3261
|
+
let cmdEndTime = null;
|
|
2595
3262
|
const timeout = this._getFindElementTimeout(options);
|
|
2596
3263
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2597
3264
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2627,6 +3294,17 @@ class StableBrowser {
|
|
|
2627
3294
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2628
3295
|
continue;
|
|
2629
3296
|
}
|
|
3297
|
+
else {
|
|
3298
|
+
cmdEndTime = Date.now();
|
|
3299
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3300
|
+
if (foundAncore) {
|
|
3301
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3302
|
+
}
|
|
3303
|
+
else {
|
|
3304
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
2630
3308
|
try {
|
|
2631
3309
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2632
3310
|
foundAncore = true;
|
|
@@ -3026,8 +3704,51 @@ class StableBrowser {
|
|
|
3026
3704
|
});
|
|
3027
3705
|
}
|
|
3028
3706
|
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3709
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3710
|
+
* @param options - Optional configuration object
|
|
3711
|
+
* @param world - Optional world context
|
|
3712
|
+
* @returns Promise that resolves after the specified duration
|
|
3713
|
+
*/
|
|
3714
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3715
|
+
const state = {
|
|
3716
|
+
duration,
|
|
3717
|
+
options,
|
|
3718
|
+
world,
|
|
3719
|
+
locate: false,
|
|
3720
|
+
scroll: false,
|
|
3721
|
+
screenshot: false,
|
|
3722
|
+
highlight: false,
|
|
3723
|
+
type: Types.SLEEP,
|
|
3724
|
+
text: `Sleep for ${duration} ms`,
|
|
3725
|
+
_text: `Sleep for ${duration} ms`,
|
|
3726
|
+
operation: "sleep",
|
|
3727
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3728
|
+
};
|
|
3729
|
+
try {
|
|
3730
|
+
await _preCommand(state, this);
|
|
3731
|
+
if (duration < 0) {
|
|
3732
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3733
|
+
}
|
|
3734
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3735
|
+
return state.info;
|
|
3736
|
+
}
|
|
3737
|
+
catch (e) {
|
|
3738
|
+
await _commandError(state, e, this);
|
|
3739
|
+
}
|
|
3740
|
+
finally {
|
|
3741
|
+
await _commandFinally(state, this);
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3029
3744
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3030
|
-
|
|
3745
|
+
try {
|
|
3746
|
+
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
3747
|
+
}
|
|
3748
|
+
catch (error) {
|
|
3749
|
+
this.logger.debug(error);
|
|
3750
|
+
throw error;
|
|
3751
|
+
}
|
|
3031
3752
|
}
|
|
3032
3753
|
_getLoadTimeout(options) {
|
|
3033
3754
|
let timeout = 15000;
|
|
@@ -3050,6 +3771,7 @@ class StableBrowser {
|
|
|
3050
3771
|
}
|
|
3051
3772
|
async saveStoreState(path = null, world = null) {
|
|
3052
3773
|
const storageState = await this.page.context().storageState();
|
|
3774
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3053
3775
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3054
3776
|
if (path) {
|
|
3055
3777
|
// save { storageState: storageState } into the path
|
|
@@ -3060,10 +3782,14 @@ class StableBrowser {
|
|
|
3060
3782
|
}
|
|
3061
3783
|
}
|
|
3062
3784
|
async restoreSaveState(path = null, world = null) {
|
|
3785
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3063
3786
|
await refreshBrowser(this, path, world);
|
|
3064
3787
|
this.registerEventListeners(this.context);
|
|
3065
3788
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
3066
3789
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
3790
|
+
if (this.onRestoreSaveState) {
|
|
3791
|
+
this.onRestoreSaveState(path);
|
|
3792
|
+
}
|
|
3067
3793
|
}
|
|
3068
3794
|
async waitForPageLoad(options = {}, world = null) {
|
|
3069
3795
|
let timeout = this._getLoadTimeout(options);
|
|
@@ -3098,7 +3824,6 @@ class StableBrowser {
|
|
|
3098
3824
|
else if (e.label === "domcontentloaded") {
|
|
3099
3825
|
console.log("waited for the domcontent loaded timeout");
|
|
3100
3826
|
}
|
|
3101
|
-
console.log(".");
|
|
3102
3827
|
}
|
|
3103
3828
|
finally {
|
|
3104
3829
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -3142,7 +3867,6 @@ class StableBrowser {
|
|
|
3142
3867
|
await this.page.close();
|
|
3143
3868
|
}
|
|
3144
3869
|
catch (e) {
|
|
3145
|
-
console.log(".");
|
|
3146
3870
|
await _commandError(state, e, this);
|
|
3147
3871
|
}
|
|
3148
3872
|
finally {
|
|
@@ -3257,7 +3981,6 @@ class StableBrowser {
|
|
|
3257
3981
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3258
3982
|
}
|
|
3259
3983
|
catch (e) {
|
|
3260
|
-
console.log(".");
|
|
3261
3984
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3262
3985
|
}
|
|
3263
3986
|
finally {
|
|
@@ -3295,7 +4018,6 @@ class StableBrowser {
|
|
|
3295
4018
|
await this.page.reload();
|
|
3296
4019
|
}
|
|
3297
4020
|
catch (e) {
|
|
3298
|
-
console.log(".");
|
|
3299
4021
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3300
4022
|
}
|
|
3301
4023
|
finally {
|
|
@@ -3338,7 +4060,44 @@ class StableBrowser {
|
|
|
3338
4060
|
console.log("#-#");
|
|
3339
4061
|
}
|
|
3340
4062
|
}
|
|
4063
|
+
async beforeScenario(world, scenario) {
|
|
4064
|
+
if (world && world.attach) {
|
|
4065
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4066
|
+
}
|
|
4067
|
+
this.context.loadedRoutes = null;
|
|
4068
|
+
this.beforeScenarioCalled = true;
|
|
4069
|
+
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
4070
|
+
this.scenarioName = scenario.pickle.name;
|
|
4071
|
+
}
|
|
4072
|
+
if (scenario && scenario.gherkinDocument && scenario.gherkinDocument.feature) {
|
|
4073
|
+
this.featureName = scenario.gherkinDocument.feature.name;
|
|
4074
|
+
}
|
|
4075
|
+
if (this.context) {
|
|
4076
|
+
this.context.examplesRow = extractStepExampleParameters(scenario);
|
|
4077
|
+
}
|
|
4078
|
+
if (this.tags === null && scenario && scenario.pickle && scenario.pickle.tags) {
|
|
4079
|
+
this.tags = scenario.pickle.tags.map((tag) => tag.name);
|
|
4080
|
+
// check if @global_test_data tag is present
|
|
4081
|
+
if (this.tags.includes("@global_test_data")) {
|
|
4082
|
+
this.saveTestDataAsGlobal({}, world);
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
// update test data based on feature/scenario
|
|
4086
|
+
let envName = null;
|
|
4087
|
+
if (this.context && this.context.environment) {
|
|
4088
|
+
envName = this.context.environment.name;
|
|
4089
|
+
}
|
|
4090
|
+
if (!process.env.TEMP_RUN) {
|
|
4091
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
4092
|
+
}
|
|
4093
|
+
await loadBrunoParams(this.context, this.context.environment.name);
|
|
4094
|
+
}
|
|
4095
|
+
async afterScenario(world, scenario) { }
|
|
3341
4096
|
async beforeStep(world, step) {
|
|
4097
|
+
if (!this.beforeScenarioCalled) {
|
|
4098
|
+
this.beforeScenario(world, step);
|
|
4099
|
+
this.context.loadedRoutes = null;
|
|
4100
|
+
}
|
|
3342
4101
|
if (this.stepIndex === undefined) {
|
|
3343
4102
|
this.stepIndex = 0;
|
|
3344
4103
|
}
|
|
@@ -3355,30 +4114,23 @@ class StableBrowser {
|
|
|
3355
4114
|
else {
|
|
3356
4115
|
this.stepName = "step " + this.stepIndex;
|
|
3357
4116
|
}
|
|
3358
|
-
if (this.context) {
|
|
3359
|
-
this.context.examplesRow = extractStepExampleParameters(step);
|
|
3360
|
-
}
|
|
3361
4117
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
3362
4118
|
if (this.context.browserObject.context) {
|
|
3363
4119
|
await this.context.browserObject.context.tracing.startChunk({ title: this.stepName });
|
|
3364
4120
|
}
|
|
3365
4121
|
}
|
|
3366
|
-
if (this.tags === null && step && step.pickle && step.pickle.tags) {
|
|
3367
|
-
this.tags = step.pickle.tags.map((tag) => tag.name);
|
|
3368
|
-
// check if @global_test_data tag is present
|
|
3369
|
-
if (this.tags.includes("@global_test_data")) {
|
|
3370
|
-
this.saveTestDataAsGlobal({}, world);
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
4122
|
if (this.initSnapshotTaken === false) {
|
|
3374
4123
|
this.initSnapshotTaken = true;
|
|
3375
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4124
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3376
4125
|
const snapshot = await this.getAriaSnapshot();
|
|
3377
4126
|
if (snapshot) {
|
|
3378
4127
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3379
4128
|
}
|
|
3380
4129
|
}
|
|
3381
4130
|
}
|
|
4131
|
+
this.context.routeResults = null;
|
|
4132
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4133
|
+
networkBeforeStep(this.stepName);
|
|
3382
4134
|
}
|
|
3383
4135
|
async getAriaSnapshot() {
|
|
3384
4136
|
try {
|
|
@@ -3394,18 +4146,74 @@ class StableBrowser {
|
|
|
3394
4146
|
const content = [`- path: ${path}`, `- title: ${title}`];
|
|
3395
4147
|
const timeout = this.configuration.ariaSnapshotTimeout ? this.configuration.ariaSnapshotTimeout : 3000;
|
|
3396
4148
|
for (let i = 0; i < frames.length; i++) {
|
|
3397
|
-
content.push(`- frame: ${i}`);
|
|
3398
4149
|
const frame = frames[i];
|
|
3399
|
-
|
|
3400
|
-
|
|
4150
|
+
try {
|
|
4151
|
+
// Ensure frame is attached and has body
|
|
4152
|
+
const body = frame.locator("body");
|
|
4153
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
4154
|
+
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4155
|
+
if (!snapshot) {
|
|
4156
|
+
continue;
|
|
4157
|
+
}
|
|
4158
|
+
content.push(`- frame: ${i}`);
|
|
4159
|
+
content.push(snapshot);
|
|
4160
|
+
}
|
|
4161
|
+
catch (innerErr) {
|
|
4162
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4163
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4164
|
+
}
|
|
3401
4165
|
}
|
|
3402
4166
|
return content.join("\n");
|
|
3403
4167
|
}
|
|
3404
4168
|
catch (e) {
|
|
3405
|
-
console.
|
|
4169
|
+
console.log("Error in getAriaSnapshot");
|
|
4170
|
+
//console.debug(e);
|
|
3406
4171
|
}
|
|
3407
4172
|
return null;
|
|
3408
4173
|
}
|
|
4174
|
+
/**
|
|
4175
|
+
* Sends command with custom payload to report.
|
|
4176
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4177
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4178
|
+
* @param content - Content of the command to be shown in the report.
|
|
4179
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4180
|
+
* @param world - Optional world context.
|
|
4181
|
+
* @public
|
|
4182
|
+
*/
|
|
4183
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4184
|
+
const state = {
|
|
4185
|
+
options,
|
|
4186
|
+
world,
|
|
4187
|
+
locate: false,
|
|
4188
|
+
scroll: false,
|
|
4189
|
+
screenshot: options.screenshot ?? false,
|
|
4190
|
+
highlight: options.highlight ?? false,
|
|
4191
|
+
type: Types.REPORT_COMMAND,
|
|
4192
|
+
text: commandText,
|
|
4193
|
+
_text: commandText,
|
|
4194
|
+
operation: "report_command",
|
|
4195
|
+
log: "***** " + commandText + " *****\n",
|
|
4196
|
+
};
|
|
4197
|
+
try {
|
|
4198
|
+
await _preCommand(state, this);
|
|
4199
|
+
const payload = {
|
|
4200
|
+
type: options.type ?? "text",
|
|
4201
|
+
content: content,
|
|
4202
|
+
screenshotId: null,
|
|
4203
|
+
};
|
|
4204
|
+
state.payload = payload;
|
|
4205
|
+
if (commandStatus === "FAILED") {
|
|
4206
|
+
state.throwError = true;
|
|
4207
|
+
throw new Error("Command failed");
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
catch (e) {
|
|
4211
|
+
await _commandError(state, e, this);
|
|
4212
|
+
}
|
|
4213
|
+
finally {
|
|
4214
|
+
await _commandFinally(state, this);
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
3409
4217
|
async afterStep(world, step) {
|
|
3410
4218
|
this.stepName = null;
|
|
3411
4219
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3413,10 +4221,12 @@ class StableBrowser {
|
|
|
3413
4221
|
await this.context.browserObject.context.tracing.stopChunk({
|
|
3414
4222
|
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
3415
4223
|
});
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
4224
|
+
if (world && world.attach) {
|
|
4225
|
+
await world.attach(JSON.stringify({
|
|
4226
|
+
type: "trace",
|
|
4227
|
+
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4228
|
+
}), "application/json+trace");
|
|
4229
|
+
}
|
|
3420
4230
|
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
3421
4231
|
}
|
|
3422
4232
|
}
|
|
@@ -3430,6 +4240,36 @@ class StableBrowser {
|
|
|
3430
4240
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3431
4241
|
}
|
|
3432
4242
|
}
|
|
4243
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4244
|
+
if (this.context.routeResults) {
|
|
4245
|
+
if (world && world.attach) {
|
|
4246
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
if (!process.env.TEMP_RUN) {
|
|
4250
|
+
const state = {
|
|
4251
|
+
world,
|
|
4252
|
+
locate: false,
|
|
4253
|
+
scroll: false,
|
|
4254
|
+
screenshot: true,
|
|
4255
|
+
highlight: true,
|
|
4256
|
+
type: Types.STEP_COMPLETE,
|
|
4257
|
+
text: "end of scenario",
|
|
4258
|
+
_text: "end of scenario",
|
|
4259
|
+
operation: "step_complete",
|
|
4260
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4261
|
+
};
|
|
4262
|
+
try {
|
|
4263
|
+
await _preCommand(state, this);
|
|
4264
|
+
}
|
|
4265
|
+
catch (e) {
|
|
4266
|
+
await _commandError(state, e, this);
|
|
4267
|
+
}
|
|
4268
|
+
finally {
|
|
4269
|
+
await _commandFinally(state, this);
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
networkAfterStep(this.stepName);
|
|
3433
4273
|
}
|
|
3434
4274
|
}
|
|
3435
4275
|
function createTimedPromise(promise, label) {
|