automation_model 1.0.702-dev → 1.0.702-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 +210 -126
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.d.ts +1 -0
- package/lib/browser_manager.js +54 -9
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.js.map +1 -1
- package/lib/command_common.d.ts +1 -1
- package/lib/command_common.js +18 -1
- package/lib/command_common.js.map +1 -1
- package/lib/date_time.js.map +1 -1
- package/lib/drawRect.js.map +1 -1
- package/lib/environment.d.ts +1 -0
- package/lib/environment.js +1 -0
- package/lib/environment.js.map +1 -1
- package/lib/error-messages.js.map +1 -1
- package/lib/file_checker.js +129 -25
- package/lib/file_checker.js.map +1 -1
- package/lib/find_function.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 +334 -86
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +21 -0
- package/lib/route.js +450 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +3 -3
- package/lib/snapshot_validation.d.ts +4 -2
- package/lib/snapshot_validation.js +160 -42
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +61 -26
- package/lib/stable_browser.js +1006 -201
- 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 -1
- package/lib/utils.js +88 -63
- package/lib/utils.js.map +1 -1
- package/package.json +13 -7
package/lib/stable_browser.js
CHANGED
|
@@ -10,7 +10,8 @@ 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
|
|
13
|
+
import errorStackParser from "error-stack-parser";
|
|
14
|
+
import { _convertToRegexQuery, _copyContext, _fixLocatorUsingParams, _fixUsingParams, _getServerUrl, extractStepExampleParameters, KEYBOARD_EVENTS, maskValue, replaceWithLocalTestData, scrollPageToLoadLazyElements, unEscapeString, _getDataFile, testForRegex, performAction, _getTestData, } from "./utils.js";
|
|
14
15
|
import csv from "csv-parser";
|
|
15
16
|
import { Readable } from "node:stream";
|
|
16
17
|
import readline from "readline";
|
|
@@ -19,35 +20,42 @@ import { getTestData } from "./auto_page.js";
|
|
|
19
20
|
import { locate_element } from "./locate_element.js";
|
|
20
21
|
import { randomUUID } from "crypto";
|
|
21
22
|
import { _commandError, _commandFinally, _preCommand, _validateSelectors, _screenshot, _reportToWorld, } from "./command_common.js";
|
|
22
|
-
import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
23
|
+
import { networkAfterStep, networkBeforeStep, registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
23
24
|
import { LocatorLog } from "./locator_log.js";
|
|
24
25
|
import axios from "axios";
|
|
25
26
|
import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
26
|
-
import { snapshotValidation } from "./snapshot_validation.js";
|
|
27
|
+
import { highlightSnapshot, snapshotValidation } from "./snapshot_validation.js";
|
|
27
28
|
import { loadBrunoParams } from "./bruno.js";
|
|
29
|
+
import { registerAfterStepRoutes, registerBeforeStepRoutes } from "./route.js";
|
|
30
|
+
import { existsSync } from "node:fs";
|
|
28
31
|
export const Types = {
|
|
29
32
|
CLICK: "click_element",
|
|
30
33
|
WAIT_ELEMENT: "wait_element",
|
|
31
34
|
NAVIGATE: "navigate",
|
|
35
|
+
GO_BACK: "go_back",
|
|
36
|
+
GO_FORWARD: "go_forward",
|
|
32
37
|
FILL: "fill_element",
|
|
33
|
-
EXECUTE: "execute_page_method",
|
|
34
|
-
OPEN: "open_environment",
|
|
38
|
+
EXECUTE: "execute_page_method", //
|
|
39
|
+
OPEN: "open_environment", //
|
|
35
40
|
COMPLETE: "step_complete",
|
|
36
41
|
ASK: "information_needed",
|
|
37
|
-
GET_PAGE_STATUS: "get_page_status",
|
|
38
|
-
CLICK_ROW_ACTION: "click_row_action",
|
|
42
|
+
GET_PAGE_STATUS: "get_page_status", ///
|
|
43
|
+
CLICK_ROW_ACTION: "click_row_action", //
|
|
39
44
|
VERIFY_ELEMENT_CONTAINS_TEXT: "verify_element_contains_text",
|
|
40
45
|
VERIFY_PAGE_CONTAINS_TEXT: "verify_page_contains_text",
|
|
41
46
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
42
47
|
ANALYZE_TABLE: "analyze_table",
|
|
43
|
-
SELECT: "select_combobox",
|
|
48
|
+
SELECT: "select_combobox", //
|
|
49
|
+
VERIFY_PROPERTY: "verify_element_property",
|
|
44
50
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
51
|
+
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
45
52
|
TYPE_PRESS: "type_press",
|
|
46
53
|
PRESS: "press_key",
|
|
47
54
|
HOVER: "hover_element",
|
|
48
55
|
CHECK: "check_element",
|
|
49
56
|
UNCHECK: "uncheck_element",
|
|
50
57
|
EXTRACT: "extract_attribute",
|
|
58
|
+
EXTRACT_PROPERTY: "extract_property",
|
|
51
59
|
CLOSE_PAGE: "close_page",
|
|
52
60
|
TABLE_OPERATION: "table_operation",
|
|
53
61
|
SET_DATE_TIME: "set_date_time",
|
|
@@ -59,9 +67,13 @@ export const Types = {
|
|
|
59
67
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
60
68
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
61
69
|
BRUNO: "bruno",
|
|
62
|
-
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
63
70
|
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
64
71
|
SET_INPUT_FILES: "set_input_files",
|
|
72
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
73
|
+
REPORT_COMMAND: "report_command",
|
|
74
|
+
STEP_COMPLETE: "step_complete",
|
|
75
|
+
SLEEP: "sleep",
|
|
76
|
+
CONDITIONAL_WAIT: "conditional_wait",
|
|
65
77
|
};
|
|
66
78
|
export const apps = {};
|
|
67
79
|
const formatElementName = (elementName) => {
|
|
@@ -73,6 +85,7 @@ class StableBrowser {
|
|
|
73
85
|
logger;
|
|
74
86
|
context;
|
|
75
87
|
world;
|
|
88
|
+
fastMode;
|
|
76
89
|
project_path = null;
|
|
77
90
|
webLogFile = null;
|
|
78
91
|
networkLogger = null;
|
|
@@ -81,12 +94,14 @@ class StableBrowser {
|
|
|
81
94
|
tags = null;
|
|
82
95
|
isRecording = false;
|
|
83
96
|
initSnapshotTaken = false;
|
|
84
|
-
|
|
97
|
+
abortedExecution = false;
|
|
98
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
85
99
|
this.browser = browser;
|
|
86
100
|
this.page = page;
|
|
87
101
|
this.logger = logger;
|
|
88
102
|
this.context = context;
|
|
89
103
|
this.world = world;
|
|
104
|
+
this.fastMode = fastMode;
|
|
90
105
|
if (!this.logger) {
|
|
91
106
|
this.logger = console;
|
|
92
107
|
}
|
|
@@ -115,6 +130,19 @@ class StableBrowser {
|
|
|
115
130
|
context.pages = [this.page];
|
|
116
131
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
117
132
|
this.world = world;
|
|
133
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
134
|
+
this.fastMode = true;
|
|
135
|
+
}
|
|
136
|
+
if (process.env.FAST_MODE === "true") {
|
|
137
|
+
// console.log("Fast mode enabled from environment variable");
|
|
138
|
+
this.fastMode = true;
|
|
139
|
+
}
|
|
140
|
+
if (process.env.FAST_MODE === "false") {
|
|
141
|
+
this.fastMode = false;
|
|
142
|
+
}
|
|
143
|
+
if (this.context) {
|
|
144
|
+
this.context.fastMode = this.fastMode;
|
|
145
|
+
}
|
|
118
146
|
this.registerEventListeners(this.context);
|
|
119
147
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
120
148
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -125,6 +153,9 @@ class StableBrowser {
|
|
|
125
153
|
if (!context.pageLoading) {
|
|
126
154
|
context.pageLoading = { status: false };
|
|
127
155
|
}
|
|
156
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
157
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
158
|
+
}
|
|
128
159
|
context.playContext.on("page", async function (page) {
|
|
129
160
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
130
161
|
console.log("close unexpected popups");
|
|
@@ -133,6 +164,14 @@ class StableBrowser {
|
|
|
133
164
|
}
|
|
134
165
|
context.pageLoading.status = true;
|
|
135
166
|
this.page = page;
|
|
167
|
+
try {
|
|
168
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
169
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error("Error on dialog accept registration", error);
|
|
174
|
+
}
|
|
136
175
|
context.page = page;
|
|
137
176
|
context.pages.push(page);
|
|
138
177
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -184,7 +223,9 @@ class StableBrowser {
|
|
|
184
223
|
if (newContextCreated) {
|
|
185
224
|
this.registerEventListeners(this.context);
|
|
186
225
|
await this.goto(this.context.environment.baseUrl);
|
|
187
|
-
|
|
226
|
+
if (!this.fastMode) {
|
|
227
|
+
await this.waitForPageLoad();
|
|
228
|
+
}
|
|
188
229
|
}
|
|
189
230
|
}
|
|
190
231
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -278,6 +319,7 @@ class StableBrowser {
|
|
|
278
319
|
if (!url) {
|
|
279
320
|
throw new Error("url is null, verify that the environment file is correct");
|
|
280
321
|
}
|
|
322
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
281
323
|
if (!url.startsWith("http")) {
|
|
282
324
|
url = "https://" + url;
|
|
283
325
|
}
|
|
@@ -309,6 +351,64 @@ class StableBrowser {
|
|
|
309
351
|
await _commandFinally(state, this);
|
|
310
352
|
}
|
|
311
353
|
}
|
|
354
|
+
async goBack(options, world = null) {
|
|
355
|
+
const state = {
|
|
356
|
+
value: "",
|
|
357
|
+
world: world,
|
|
358
|
+
type: Types.GO_BACK,
|
|
359
|
+
text: `Browser navigate back`,
|
|
360
|
+
operation: "goBack",
|
|
361
|
+
log: "***** navigate back *****\n",
|
|
362
|
+
info: {},
|
|
363
|
+
locate: false,
|
|
364
|
+
scroll: false,
|
|
365
|
+
screenshot: false,
|
|
366
|
+
highlight: false,
|
|
367
|
+
};
|
|
368
|
+
try {
|
|
369
|
+
await _preCommand(state, this);
|
|
370
|
+
await this.page.goBack({
|
|
371
|
+
waitUntil: "load",
|
|
372
|
+
});
|
|
373
|
+
await _screenshot(state, this);
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
console.error("Error on goBack", error);
|
|
377
|
+
_commandError(state, error, this);
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
await _commandFinally(state, this);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async goForward(options, world = null) {
|
|
384
|
+
const state = {
|
|
385
|
+
value: "",
|
|
386
|
+
world: world,
|
|
387
|
+
type: Types.GO_FORWARD,
|
|
388
|
+
text: `Browser navigate forward`,
|
|
389
|
+
operation: "goForward",
|
|
390
|
+
log: "***** navigate forward *****\n",
|
|
391
|
+
info: {},
|
|
392
|
+
locate: false,
|
|
393
|
+
scroll: false,
|
|
394
|
+
screenshot: false,
|
|
395
|
+
highlight: false,
|
|
396
|
+
};
|
|
397
|
+
try {
|
|
398
|
+
await _preCommand(state, this);
|
|
399
|
+
await this.page.goForward({
|
|
400
|
+
waitUntil: "load",
|
|
401
|
+
});
|
|
402
|
+
await _screenshot(state, this);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
console.error("Error on goForward", error);
|
|
406
|
+
_commandError(state, error, this);
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
await _commandFinally(state, this);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
312
412
|
async _getLocator(locator, scope, _params) {
|
|
313
413
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
314
414
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -422,7 +522,7 @@ class StableBrowser {
|
|
|
422
522
|
}
|
|
423
523
|
return { elementCount: tagCount, randomToken };
|
|
424
524
|
}
|
|
425
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
525
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
426
526
|
if (!info) {
|
|
427
527
|
info = {};
|
|
428
528
|
}
|
|
@@ -434,14 +534,13 @@ class StableBrowser {
|
|
|
434
534
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
435
535
|
}
|
|
436
536
|
let locatorSearch = selectorHierarchy[index];
|
|
437
|
-
let originalLocatorSearch = "";
|
|
438
537
|
try {
|
|
439
|
-
|
|
440
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
538
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
441
539
|
}
|
|
442
540
|
catch (e) {
|
|
443
541
|
console.error(e);
|
|
444
542
|
}
|
|
543
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
445
544
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
446
545
|
let locator = null;
|
|
447
546
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -489,7 +588,7 @@ class StableBrowser {
|
|
|
489
588
|
}
|
|
490
589
|
return;
|
|
491
590
|
}
|
|
492
|
-
if (info.locatorLog && count === 0) {
|
|
591
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
493
592
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
494
593
|
}
|
|
495
594
|
for (let j = 0; j < count; j++) {
|
|
@@ -504,7 +603,7 @@ class StableBrowser {
|
|
|
504
603
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
505
604
|
}
|
|
506
605
|
}
|
|
507
|
-
else {
|
|
606
|
+
else if (logErrors) {
|
|
508
607
|
info.failCause.visible = visible;
|
|
509
608
|
info.failCause.enabled = enabled;
|
|
510
609
|
if (!info.printMessages) {
|
|
@@ -583,21 +682,134 @@ class StableBrowser {
|
|
|
583
682
|
}
|
|
584
683
|
return { rerun: false };
|
|
585
684
|
}
|
|
685
|
+
getFilePath() {
|
|
686
|
+
const stackFrames = errorStackParser.parse(new Error());
|
|
687
|
+
const stackFrame = stackFrames.findLast((frame) => frame.fileName && frame.fileName.endsWith(".mjs"));
|
|
688
|
+
// return stackFrame?.fileName || null;
|
|
689
|
+
const filepath = stackFrame?.fileName;
|
|
690
|
+
if (filepath) {
|
|
691
|
+
let jsonFilePath = filepath.replace(".mjs", ".json");
|
|
692
|
+
if (existsSync(jsonFilePath)) {
|
|
693
|
+
return jsonFilePath;
|
|
694
|
+
}
|
|
695
|
+
const config = this.configuration ?? {};
|
|
696
|
+
if (!config?.locatorsMetadataDir) {
|
|
697
|
+
config.locatorsMetadataDir = "features/step_definitions/locators";
|
|
698
|
+
}
|
|
699
|
+
if (config && config.locatorsMetadataDir) {
|
|
700
|
+
jsonFilePath = path.join(config.locatorsMetadataDir, path.basename(jsonFilePath));
|
|
701
|
+
}
|
|
702
|
+
if (existsSync(jsonFilePath)) {
|
|
703
|
+
return jsonFilePath;
|
|
704
|
+
}
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
getFullElementLocators(selectors, filePath) {
|
|
710
|
+
if (!filePath || !existsSync(filePath)) {
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
714
|
+
try {
|
|
715
|
+
const allElements = JSON.parse(content);
|
|
716
|
+
const element_key = selectors?.element_key;
|
|
717
|
+
if (element_key && allElements[element_key]) {
|
|
718
|
+
return allElements[element_key];
|
|
719
|
+
}
|
|
720
|
+
for (const elementKey in allElements) {
|
|
721
|
+
const element = allElements[elementKey];
|
|
722
|
+
let foundStrategy = null;
|
|
723
|
+
for (const key in element) {
|
|
724
|
+
if (key === "strategy") {
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
const locators = element[key];
|
|
728
|
+
if (!locators || !locators.length) {
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
for (const locator of locators) {
|
|
732
|
+
delete locator.score;
|
|
733
|
+
}
|
|
734
|
+
if (JSON.stringify(locators) === JSON.stringify(selectors.locators)) {
|
|
735
|
+
foundStrategy = key;
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (foundStrategy) {
|
|
740
|
+
return element;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
catch (error) {
|
|
745
|
+
console.error("Error parsing locators from file: " + filePath, error);
|
|
746
|
+
}
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
586
749
|
async _locate(selectors, info, _params, timeout, allowDisabled = false) {
|
|
587
750
|
if (!timeout) {
|
|
588
751
|
timeout = 30000;
|
|
589
752
|
}
|
|
753
|
+
let element = null;
|
|
754
|
+
let allStrategyLocators = null;
|
|
755
|
+
let selectedStrategy = null;
|
|
756
|
+
if (this.tryAllStrategies) {
|
|
757
|
+
allStrategyLocators = this.getFullElementLocators(selectors, this.getFilePath());
|
|
758
|
+
selectedStrategy = allStrategyLocators?.strategy;
|
|
759
|
+
}
|
|
590
760
|
for (let i = 0; i < 3; i++) {
|
|
591
761
|
info.log += "attempt " + i + ": total locators " + selectors.locators.length + "\n";
|
|
592
762
|
for (let j = 0; j < selectors.locators.length; j++) {
|
|
593
763
|
let selector = selectors.locators[j];
|
|
594
764
|
info.log += "searching for locator " + j + ":" + JSON.stringify(selector) + "\n";
|
|
595
765
|
}
|
|
596
|
-
|
|
766
|
+
if (this.tryAllStrategies && selectedStrategy) {
|
|
767
|
+
const strategyLocators = allStrategyLocators[selectedStrategy];
|
|
768
|
+
let err;
|
|
769
|
+
if (strategyLocators && strategyLocators.length) {
|
|
770
|
+
try {
|
|
771
|
+
selectors.locators = strategyLocators;
|
|
772
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
773
|
+
info.selectedStrategy = selectedStrategy;
|
|
774
|
+
info.log += "element found using strategy " + selectedStrategy + "\n";
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
err = error;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (!element) {
|
|
781
|
+
for (const key in allStrategyLocators) {
|
|
782
|
+
if (key === "strategy" || key === selectedStrategy) {
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
const strategyLocators = allStrategyLocators[key];
|
|
786
|
+
if (strategyLocators && strategyLocators.length) {
|
|
787
|
+
try {
|
|
788
|
+
info.log += "using strategy " + key + " with locators " + JSON.stringify(strategyLocators) + "\n";
|
|
789
|
+
selectors.locators = strategyLocators;
|
|
790
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
791
|
+
info.selectedStrategy = key;
|
|
792
|
+
info.log += "element found using strategy " + key + "\n";
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
catch (error) {
|
|
796
|
+
err = error;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (err) {
|
|
801
|
+
throw err;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
807
|
+
}
|
|
597
808
|
if (!element.rerun) {
|
|
598
809
|
const randomToken = Math.random().toString(36).substring(7);
|
|
599
|
-
element.evaluate((el, randomToken) => {
|
|
810
|
+
await element.evaluate((el, randomToken) => {
|
|
600
811
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
812
|
+
console.log("set data-blinq-id-" + randomToken + " on element", el);
|
|
601
813
|
}, randomToken);
|
|
602
814
|
// if (element._frame) {
|
|
603
815
|
// return element;
|
|
@@ -649,7 +861,7 @@ class StableBrowser {
|
|
|
649
861
|
break;
|
|
650
862
|
}
|
|
651
863
|
catch (error) {
|
|
652
|
-
console.error("frame not found " + frameLocator.css);
|
|
864
|
+
// console.error("frame not found " + frameLocator.css);
|
|
653
865
|
}
|
|
654
866
|
}
|
|
655
867
|
}
|
|
@@ -727,7 +939,6 @@ class StableBrowser {
|
|
|
727
939
|
let locatorsCount = 0;
|
|
728
940
|
let lazy_scroll = false;
|
|
729
941
|
//let arrayMode = Array.isArray(selectors);
|
|
730
|
-
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
731
942
|
let selectorsLocators = null;
|
|
732
943
|
selectorsLocators = selectors.locators;
|
|
733
944
|
// group selectors by priority
|
|
@@ -755,6 +966,7 @@ class StableBrowser {
|
|
|
755
966
|
let highPriorityOnly = true;
|
|
756
967
|
let visibleOnly = true;
|
|
757
968
|
while (true) {
|
|
969
|
+
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
758
970
|
locatorsCount = 0;
|
|
759
971
|
let result = [];
|
|
760
972
|
let popupResult = await this.closeUnexpectedPopups(info, _params);
|
|
@@ -845,7 +1057,7 @@ class StableBrowser {
|
|
|
845
1057
|
}
|
|
846
1058
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
847
1059
|
}
|
|
848
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
1060
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
849
1061
|
let foundElements = [];
|
|
850
1062
|
const result = {
|
|
851
1063
|
foundElements: foundElements,
|
|
@@ -864,7 +1076,9 @@ class StableBrowser {
|
|
|
864
1076
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
865
1077
|
}
|
|
866
1078
|
catch (e) {
|
|
867
|
-
|
|
1079
|
+
if (logErrors) {
|
|
1080
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
1081
|
+
}
|
|
868
1082
|
}
|
|
869
1083
|
}
|
|
870
1084
|
if (foundLocators.length === 1) {
|
|
@@ -905,7 +1119,7 @@ class StableBrowser {
|
|
|
905
1119
|
});
|
|
906
1120
|
result.locatorIndex = i;
|
|
907
1121
|
}
|
|
908
|
-
else {
|
|
1122
|
+
else if (logErrors) {
|
|
909
1123
|
info.failCause.foundMultiple = true;
|
|
910
1124
|
if (info.locatorLog) {
|
|
911
1125
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -1028,7 +1242,9 @@ class StableBrowser {
|
|
|
1028
1242
|
try {
|
|
1029
1243
|
await _preCommand(state, this);
|
|
1030
1244
|
await performAction("click", state.element, options, this, state, _params);
|
|
1031
|
-
|
|
1245
|
+
if (!this.fastMode) {
|
|
1246
|
+
await this.waitForPageLoad();
|
|
1247
|
+
}
|
|
1032
1248
|
return state.info;
|
|
1033
1249
|
}
|
|
1034
1250
|
catch (e) {
|
|
@@ -1091,7 +1307,7 @@ class StableBrowser {
|
|
|
1091
1307
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1092
1308
|
// console.log(`Highlighting while running from recorder`);
|
|
1093
1309
|
await this._highlightElements(state.element);
|
|
1094
|
-
await state.element.setChecked(checked);
|
|
1310
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1095
1311
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1096
1312
|
// await this._unHighlightElements(element);
|
|
1097
1313
|
// }
|
|
@@ -1103,11 +1319,28 @@ class StableBrowser {
|
|
|
1103
1319
|
this.logger.info("element did not change its state, ignoring...");
|
|
1104
1320
|
}
|
|
1105
1321
|
else {
|
|
1322
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1106
1323
|
//await this.closeUnexpectedPopups();
|
|
1107
1324
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1108
|
-
state.
|
|
1109
|
-
|
|
1110
|
-
|
|
1325
|
+
state.element_found = false;
|
|
1326
|
+
try {
|
|
1327
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1328
|
+
state.element_found = true;
|
|
1329
|
+
// check the check state
|
|
1330
|
+
}
|
|
1331
|
+
catch (error) {
|
|
1332
|
+
// element dismissed
|
|
1333
|
+
}
|
|
1334
|
+
if (state.element_found) {
|
|
1335
|
+
const isChecked = await state.element.isChecked();
|
|
1336
|
+
if (isChecked !== checked) {
|
|
1337
|
+
// perform click
|
|
1338
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1111
1344
|
}
|
|
1112
1345
|
}
|
|
1113
1346
|
await this.waitForPageLoad();
|
|
@@ -1403,7 +1636,9 @@ class StableBrowser {
|
|
|
1403
1636
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1404
1637
|
}
|
|
1405
1638
|
}
|
|
1639
|
+
//if (!this.fastMode) {
|
|
1406
1640
|
await _screenshot(state, this);
|
|
1641
|
+
//}
|
|
1407
1642
|
if (enter === true) {
|
|
1408
1643
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1409
1644
|
await this.page.keyboard.press("Enter");
|
|
@@ -1712,14 +1947,17 @@ class StableBrowser {
|
|
|
1712
1947
|
throw new Error("referanceSnapshot is null");
|
|
1713
1948
|
}
|
|
1714
1949
|
let text = null;
|
|
1715
|
-
if (fs.existsSync(path.join(this.project_path, "snapshots", referanceSnapshot + ".yml"))) {
|
|
1716
|
-
text = fs.readFileSync(path.join(this.project_path, "snapshots", referanceSnapshot + ".yml"), "utf8");
|
|
1950
|
+
if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"))) {
|
|
1951
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yml"), "utf8");
|
|
1952
|
+
}
|
|
1953
|
+
else if (fs.existsSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"))) {
|
|
1954
|
+
text = fs.readFileSync(path.join(this.project_path, "data", "snapshots", this.context.environment.name, referanceSnapshot + ".yaml"), "utf8");
|
|
1717
1955
|
}
|
|
1718
1956
|
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1719
1957
|
text = referanceSnapshot.substring(5);
|
|
1720
1958
|
}
|
|
1721
1959
|
else {
|
|
1722
|
-
throw new Error("
|
|
1960
|
+
throw new Error("referenceSnapshot file not found: " + referanceSnapshot);
|
|
1723
1961
|
}
|
|
1724
1962
|
state.text = text;
|
|
1725
1963
|
const newValue = await this._replaceWithLocalData(text, world);
|
|
@@ -1737,18 +1975,23 @@ class StableBrowser {
|
|
|
1737
1975
|
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1738
1976
|
}
|
|
1739
1977
|
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
1740
|
-
matchResult = snapshotValidation(snapshot, newValue);
|
|
1978
|
+
matchResult = snapshotValidation(snapshot, newValue, referanceSnapshot);
|
|
1741
1979
|
if (matchResult.errorLine !== -1) {
|
|
1742
1980
|
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1743
1981
|
}
|
|
1744
1982
|
// highlight and screenshot
|
|
1983
|
+
try {
|
|
1984
|
+
await await highlightSnapshot(newValue, scope);
|
|
1985
|
+
await _screenshot(state, this);
|
|
1986
|
+
}
|
|
1987
|
+
catch (e) { }
|
|
1745
1988
|
return state.info;
|
|
1746
1989
|
}
|
|
1747
1990
|
catch (e) {
|
|
1748
1991
|
// Log error but continue retrying until timeout is reached
|
|
1749
|
-
this.logger.warn("Retrying
|
|
1992
|
+
//this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
1750
1993
|
}
|
|
1751
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1994
|
+
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 1 second before retrying
|
|
1752
1995
|
}
|
|
1753
1996
|
throw new Error("No snapshot match " + matchResult?.errorLineText);
|
|
1754
1997
|
}
|
|
@@ -1900,12 +2143,7 @@ class StableBrowser {
|
|
|
1900
2143
|
}
|
|
1901
2144
|
}
|
|
1902
2145
|
getTestData(world = null) {
|
|
1903
|
-
|
|
1904
|
-
let data = {};
|
|
1905
|
-
if (fs.existsSync(dataFile)) {
|
|
1906
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1907
|
-
}
|
|
1908
|
-
return data;
|
|
2146
|
+
return _getTestData(world, this.context, this);
|
|
1909
2147
|
}
|
|
1910
2148
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1911
2149
|
// collect url/path/title
|
|
@@ -2125,6 +2363,77 @@ class StableBrowser {
|
|
|
2125
2363
|
await _commandFinally(state, this);
|
|
2126
2364
|
}
|
|
2127
2365
|
}
|
|
2366
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2367
|
+
const state = {
|
|
2368
|
+
selectors,
|
|
2369
|
+
_params,
|
|
2370
|
+
property,
|
|
2371
|
+
variable,
|
|
2372
|
+
options,
|
|
2373
|
+
world,
|
|
2374
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2375
|
+
text: `Extract property from element`,
|
|
2376
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2377
|
+
operation: "extractProperty",
|
|
2378
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2379
|
+
allowDisabled: true,
|
|
2380
|
+
};
|
|
2381
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2382
|
+
try {
|
|
2383
|
+
await _preCommand(state, this);
|
|
2384
|
+
switch (property) {
|
|
2385
|
+
case "inner_text":
|
|
2386
|
+
state.value = await state.element.innerText();
|
|
2387
|
+
break;
|
|
2388
|
+
case "href":
|
|
2389
|
+
state.value = await state.element.getAttribute("href");
|
|
2390
|
+
break;
|
|
2391
|
+
case "value":
|
|
2392
|
+
state.value = await state.element.inputValue();
|
|
2393
|
+
break;
|
|
2394
|
+
case "text":
|
|
2395
|
+
state.value = await state.element.textContent();
|
|
2396
|
+
break;
|
|
2397
|
+
default:
|
|
2398
|
+
if (property.startsWith("dataset.")) {
|
|
2399
|
+
const dataAttribute = property.substring(8);
|
|
2400
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2401
|
+
}
|
|
2402
|
+
else {
|
|
2403
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
if (options !== null) {
|
|
2407
|
+
if (options.regex && options.regex !== "") {
|
|
2408
|
+
// Construct a regex pattern from the provided string
|
|
2409
|
+
const regex = options.regex.slice(1, -1);
|
|
2410
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2411
|
+
const matches = state.value.match(regexPattern);
|
|
2412
|
+
if (matches) {
|
|
2413
|
+
let newValue = "";
|
|
2414
|
+
for (const match of matches) {
|
|
2415
|
+
newValue += match;
|
|
2416
|
+
}
|
|
2417
|
+
state.value = newValue;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2421
|
+
state.value = state.value.trim();
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
state.info.value = state.value;
|
|
2425
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2426
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2427
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2428
|
+
return state.info;
|
|
2429
|
+
}
|
|
2430
|
+
catch (e) {
|
|
2431
|
+
await _commandError(state, e, this);
|
|
2432
|
+
}
|
|
2433
|
+
finally {
|
|
2434
|
+
await _commandFinally(state, this);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2128
2437
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
2129
2438
|
const state = {
|
|
2130
2439
|
selectors,
|
|
@@ -2177,14 +2486,167 @@ class StableBrowser {
|
|
|
2177
2486
|
let regex;
|
|
2178
2487
|
if (expectedValue.startsWith("/") && expectedValue.endsWith("/")) {
|
|
2179
2488
|
const patternBody = expectedValue.slice(1, -1);
|
|
2180
|
-
|
|
2489
|
+
const processedPattern = patternBody.replace(/\n/g, ".*");
|
|
2490
|
+
regex = new RegExp(processedPattern, "gs");
|
|
2491
|
+
state.info.regex = true;
|
|
2181
2492
|
}
|
|
2182
2493
|
else {
|
|
2183
2494
|
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2184
2495
|
regex = new RegExp(escapedPattern, "g");
|
|
2185
2496
|
}
|
|
2186
|
-
if (
|
|
2187
|
-
|
|
2497
|
+
if (attribute === "innerText") {
|
|
2498
|
+
if (state.info.regex) {
|
|
2499
|
+
if (!regex.test(val)) {
|
|
2500
|
+
let errorMessage = `The ${attribute} attribute 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
|
+
const valLines = val.split("\n");
|
|
2508
|
+
const expectedLines = expectedValue.split("\n");
|
|
2509
|
+
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine === expectedLine));
|
|
2510
|
+
if (!isPart) {
|
|
2511
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2512
|
+
state.info.failCause.assertionFailed = true;
|
|
2513
|
+
state.info.failCause.lastError = errorMessage;
|
|
2514
|
+
throw new Error(errorMessage);
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
else {
|
|
2519
|
+
if (!val.match(regex)) {
|
|
2520
|
+
let errorMessage = `The ${attribute} attribute has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2521
|
+
state.info.failCause.assertionFailed = true;
|
|
2522
|
+
state.info.failCause.lastError = errorMessage;
|
|
2523
|
+
throw new Error(errorMessage);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
return state.info;
|
|
2527
|
+
}
|
|
2528
|
+
catch (e) {
|
|
2529
|
+
await _commandError(state, e, this);
|
|
2530
|
+
}
|
|
2531
|
+
finally {
|
|
2532
|
+
await _commandFinally(state, this);
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2536
|
+
const state = {
|
|
2537
|
+
selectors,
|
|
2538
|
+
_params,
|
|
2539
|
+
property,
|
|
2540
|
+
value,
|
|
2541
|
+
options,
|
|
2542
|
+
world,
|
|
2543
|
+
type: Types.VERIFY_PROPERTY,
|
|
2544
|
+
highlight: true,
|
|
2545
|
+
screenshot: true,
|
|
2546
|
+
text: `Verify element property`,
|
|
2547
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2548
|
+
operation: "verifyProperty",
|
|
2549
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2550
|
+
allowDisabled: true,
|
|
2551
|
+
};
|
|
2552
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2553
|
+
let val;
|
|
2554
|
+
let expectedValue;
|
|
2555
|
+
try {
|
|
2556
|
+
await _preCommand(state, this);
|
|
2557
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2558
|
+
state.info.expectedValue = expectedValue;
|
|
2559
|
+
switch (property) {
|
|
2560
|
+
case "innerText":
|
|
2561
|
+
val = String(await state.element.innerText());
|
|
2562
|
+
break;
|
|
2563
|
+
case "text":
|
|
2564
|
+
val = String(await state.element.textContent());
|
|
2565
|
+
break;
|
|
2566
|
+
case "value":
|
|
2567
|
+
val = String(await state.element.inputValue());
|
|
2568
|
+
break;
|
|
2569
|
+
case "checked":
|
|
2570
|
+
val = String(await state.element.isChecked());
|
|
2571
|
+
break;
|
|
2572
|
+
case "disabled":
|
|
2573
|
+
val = String(await state.element.isDisabled());
|
|
2574
|
+
break;
|
|
2575
|
+
case "readOnly":
|
|
2576
|
+
const isEditable = await state.element.isEditable();
|
|
2577
|
+
val = String(!isEditable);
|
|
2578
|
+
break;
|
|
2579
|
+
case "innerHTML":
|
|
2580
|
+
val = String(await state.element.innerHTML());
|
|
2581
|
+
break;
|
|
2582
|
+
case "outerHTML":
|
|
2583
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2584
|
+
break;
|
|
2585
|
+
default:
|
|
2586
|
+
if (property.startsWith("dataset.")) {
|
|
2587
|
+
const dataAttribute = property.substring(8);
|
|
2588
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2589
|
+
}
|
|
2590
|
+
else {
|
|
2591
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
// Helper function to remove all style="" attributes
|
|
2595
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2596
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2597
|
+
};
|
|
2598
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2599
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2600
|
+
val = removeStyleAttributes(val);
|
|
2601
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2602
|
+
}
|
|
2603
|
+
state.info.value = val;
|
|
2604
|
+
let regex;
|
|
2605
|
+
state.info.value = val;
|
|
2606
|
+
const isRegex = expectedValue.startsWith("regex:");
|
|
2607
|
+
const isContains = expectedValue.startsWith("contains:");
|
|
2608
|
+
const isExact = expectedValue.startsWith("exact:");
|
|
2609
|
+
let matchPassed = false;
|
|
2610
|
+
if (isRegex) {
|
|
2611
|
+
const rawPattern = expectedValue.slice(6); // remove "regex:"
|
|
2612
|
+
const lastSlashIndex = rawPattern.lastIndexOf("/");
|
|
2613
|
+
if (rawPattern.startsWith("/") && lastSlashIndex > 0) {
|
|
2614
|
+
const patternBody = rawPattern.slice(1, lastSlashIndex).replace(/\n/g, ".*");
|
|
2615
|
+
const flags = rawPattern.slice(lastSlashIndex + 1) || "gs";
|
|
2616
|
+
const regex = new RegExp(patternBody, flags);
|
|
2617
|
+
state.info.regex = true;
|
|
2618
|
+
matchPassed = regex.test(val);
|
|
2619
|
+
}
|
|
2620
|
+
else {
|
|
2621
|
+
// Fallback: treat as literal
|
|
2622
|
+
const escapedPattern = rawPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2623
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2624
|
+
matchPassed = regex.test(val);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
else if (isContains) {
|
|
2628
|
+
const containsValue = expectedValue.slice(9); // remove "contains:"
|
|
2629
|
+
matchPassed = val.includes(containsValue);
|
|
2630
|
+
}
|
|
2631
|
+
else if (isExact) {
|
|
2632
|
+
const exactValue = expectedValue.slice(6); // remove "exact:"
|
|
2633
|
+
matchPassed = val === exactValue;
|
|
2634
|
+
}
|
|
2635
|
+
else if (property === "innerText") {
|
|
2636
|
+
// Default innerText logic
|
|
2637
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2638
|
+
const valLines = val.split("\n");
|
|
2639
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2640
|
+
matchPassed = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2641
|
+
}
|
|
2642
|
+
else {
|
|
2643
|
+
// Fallback exact or loose match
|
|
2644
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2645
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2646
|
+
matchPassed = regex.test(val);
|
|
2647
|
+
}
|
|
2648
|
+
if (!matchPassed) {
|
|
2649
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2188
2650
|
state.info.failCause.assertionFailed = true;
|
|
2189
2651
|
state.info.failCause.lastError = errorMessage;
|
|
2190
2652
|
throw new Error(errorMessage);
|
|
@@ -2198,6 +2660,132 @@ class StableBrowser {
|
|
|
2198
2660
|
await _commandFinally(state, this);
|
|
2199
2661
|
}
|
|
2200
2662
|
}
|
|
2663
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2664
|
+
// Convert timeout from seconds to milliseconds
|
|
2665
|
+
const timeoutMs = timeout * 1000;
|
|
2666
|
+
const state = {
|
|
2667
|
+
selectors,
|
|
2668
|
+
_params,
|
|
2669
|
+
condition,
|
|
2670
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2671
|
+
options,
|
|
2672
|
+
world,
|
|
2673
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2674
|
+
highlight: true,
|
|
2675
|
+
screenshot: true,
|
|
2676
|
+
text: `Conditional wait for element`,
|
|
2677
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2678
|
+
operation: "conditionalWait",
|
|
2679
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2680
|
+
allowDisabled: true,
|
|
2681
|
+
info: {},
|
|
2682
|
+
};
|
|
2683
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2684
|
+
const startTime = Date.now();
|
|
2685
|
+
let conditionMet = false;
|
|
2686
|
+
let currentValue = null;
|
|
2687
|
+
let lastError = null;
|
|
2688
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2689
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2690
|
+
const elapsedTime = Date.now() - startTime;
|
|
2691
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2692
|
+
try {
|
|
2693
|
+
// Try to execute _preCommand (element location)
|
|
2694
|
+
await _preCommand(state, this);
|
|
2695
|
+
// If _preCommand succeeds, start condition checking
|
|
2696
|
+
const checkCondition = async () => {
|
|
2697
|
+
try {
|
|
2698
|
+
switch (condition.toLowerCase()) {
|
|
2699
|
+
case "checked":
|
|
2700
|
+
currentValue = await state.element.isChecked();
|
|
2701
|
+
return currentValue === true;
|
|
2702
|
+
case "unchecked":
|
|
2703
|
+
currentValue = await state.element.isChecked();
|
|
2704
|
+
return currentValue === false;
|
|
2705
|
+
case "visible":
|
|
2706
|
+
currentValue = await state.element.isVisible();
|
|
2707
|
+
return currentValue === true;
|
|
2708
|
+
case "hidden":
|
|
2709
|
+
currentValue = await state.element.isVisible();
|
|
2710
|
+
return currentValue === false;
|
|
2711
|
+
case "enabled":
|
|
2712
|
+
currentValue = await state.element.isDisabled();
|
|
2713
|
+
return currentValue === false;
|
|
2714
|
+
case "disabled":
|
|
2715
|
+
currentValue = await state.element.isDisabled();
|
|
2716
|
+
return currentValue === true;
|
|
2717
|
+
case "editable":
|
|
2718
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2719
|
+
currentValue = await state.element.isContentEditable();
|
|
2720
|
+
return currentValue === true;
|
|
2721
|
+
default:
|
|
2722
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2723
|
+
state.info.success = false;
|
|
2724
|
+
return false;
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
catch (error) {
|
|
2728
|
+
// Don't throw here, just return false to continue retrying
|
|
2729
|
+
return false;
|
|
2730
|
+
}
|
|
2731
|
+
};
|
|
2732
|
+
// Inner loop for condition checking (once element is located)
|
|
2733
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2734
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2735
|
+
conditionMet = await checkCondition();
|
|
2736
|
+
if (conditionMet) {
|
|
2737
|
+
break;
|
|
2738
|
+
}
|
|
2739
|
+
// Check if we still have time for another attempt
|
|
2740
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2741
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2742
|
+
}
|
|
2743
|
+
else {
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
// If we got here and condition is met, break out of main loop
|
|
2748
|
+
if (conditionMet) {
|
|
2749
|
+
break;
|
|
2750
|
+
}
|
|
2751
|
+
// If condition not met but no exception, we've timed out
|
|
2752
|
+
break;
|
|
2753
|
+
}
|
|
2754
|
+
catch (e) {
|
|
2755
|
+
lastError = e;
|
|
2756
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2757
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2758
|
+
// Check if we have enough time left to retry
|
|
2759
|
+
if (timeLeft > 100) {
|
|
2760
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2761
|
+
}
|
|
2762
|
+
else {
|
|
2763
|
+
break;
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2768
|
+
state.info = {
|
|
2769
|
+
success: conditionMet,
|
|
2770
|
+
conditionMet,
|
|
2771
|
+
actualWaitTime,
|
|
2772
|
+
currentValue,
|
|
2773
|
+
lastError: lastError?.message || null,
|
|
2774
|
+
message: conditionMet
|
|
2775
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2776
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2777
|
+
};
|
|
2778
|
+
if (lastError) {
|
|
2779
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2780
|
+
}
|
|
2781
|
+
try {
|
|
2782
|
+
await _commandFinally(state, this);
|
|
2783
|
+
}
|
|
2784
|
+
catch (finallyError) {
|
|
2785
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2786
|
+
}
|
|
2787
|
+
return state.info;
|
|
2788
|
+
}
|
|
2201
2789
|
async extractEmailData(emailAddress, options, world) {
|
|
2202
2790
|
if (!emailAddress) {
|
|
2203
2791
|
throw new Error("email address is null");
|
|
@@ -2355,56 +2943,49 @@ class StableBrowser {
|
|
|
2355
2943
|
console.debug(error);
|
|
2356
2944
|
}
|
|
2357
2945
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
// });
|
|
2401
|
-
// }
|
|
2402
|
-
// } catch (error) {
|
|
2403
|
-
// // console.debug(error);
|
|
2404
|
-
// }
|
|
2405
|
-
// }
|
|
2946
|
+
_matcher(text) {
|
|
2947
|
+
if (!text) {
|
|
2948
|
+
return { matcher: "contains", queryText: "" };
|
|
2949
|
+
}
|
|
2950
|
+
if (text.length < 2) {
|
|
2951
|
+
return { matcher: "contains", queryText: text };
|
|
2952
|
+
}
|
|
2953
|
+
const split = text.split(":");
|
|
2954
|
+
const matcher = split[0].toLowerCase();
|
|
2955
|
+
const queryText = split.slice(1).join(":").trim();
|
|
2956
|
+
return { matcher, queryText };
|
|
2957
|
+
}
|
|
2958
|
+
_getDomain(url) {
|
|
2959
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
2960
|
+
return "";
|
|
2961
|
+
}
|
|
2962
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
2963
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
2964
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
2965
|
+
}
|
|
2966
|
+
let n = hostnameFragments.length;
|
|
2967
|
+
let fragments = [...hostnameFragments];
|
|
2968
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
2969
|
+
hostnameFragments.pop();
|
|
2970
|
+
n = hostnameFragments.length;
|
|
2971
|
+
}
|
|
2972
|
+
if (n == 0) {
|
|
2973
|
+
if (fragments[0] === "www")
|
|
2974
|
+
fragments = fragments.slice(1);
|
|
2975
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
2976
|
+
}
|
|
2977
|
+
if (hostnameFragments[0] === "www")
|
|
2978
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
2979
|
+
return hostnameFragments.join(".");
|
|
2980
|
+
}
|
|
2981
|
+
/**
|
|
2982
|
+
* Verify the page path matches the given path.
|
|
2983
|
+
* @param {string} pathPart - The path to verify.
|
|
2984
|
+
* @param {object} options - Options for verification.
|
|
2985
|
+
* @param {object} world - The world context.
|
|
2986
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
2987
|
+
*/
|
|
2406
2988
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2407
|
-
const startTime = Date.now();
|
|
2408
2989
|
let error = null;
|
|
2409
2990
|
let screenshotId = null;
|
|
2410
2991
|
let screenshotPath = null;
|
|
@@ -2418,113 +2999,212 @@ class StableBrowser {
|
|
|
2418
2999
|
pathPart = newValue;
|
|
2419
3000
|
}
|
|
2420
3001
|
info.pathPart = pathPart;
|
|
3002
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
3003
|
+
const state = {
|
|
3004
|
+
text_search: queryText,
|
|
3005
|
+
options,
|
|
3006
|
+
world,
|
|
3007
|
+
locate: false,
|
|
3008
|
+
scroll: false,
|
|
3009
|
+
highlight: false,
|
|
3010
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
3011
|
+
text: `Verify the page url is ${queryText}`,
|
|
3012
|
+
_text: `Verify the page url is ${queryText}`,
|
|
3013
|
+
operation: "verifyPagePath",
|
|
3014
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
3015
|
+
};
|
|
2421
3016
|
try {
|
|
3017
|
+
await _preCommand(state, this);
|
|
3018
|
+
state.info.text = queryText;
|
|
2422
3019
|
for (let i = 0; i < 30; i++) {
|
|
2423
3020
|
const url = await this.page.url();
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
3021
|
+
switch (matcher) {
|
|
3022
|
+
case "exact":
|
|
3023
|
+
if (url !== queryText) {
|
|
3024
|
+
if (i === 29) {
|
|
3025
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
3026
|
+
}
|
|
3027
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3028
|
+
continue;
|
|
3029
|
+
}
|
|
3030
|
+
break;
|
|
3031
|
+
case "contains":
|
|
3032
|
+
if (!url.includes(queryText)) {
|
|
3033
|
+
if (i === 29) {
|
|
3034
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
3035
|
+
}
|
|
3036
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3037
|
+
continue;
|
|
3038
|
+
}
|
|
3039
|
+
break;
|
|
3040
|
+
case "starts-with":
|
|
3041
|
+
{
|
|
3042
|
+
const domain = this._getDomain(url);
|
|
3043
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
3044
|
+
if (i === 29) {
|
|
3045
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
3046
|
+
}
|
|
3047
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
break;
|
|
3052
|
+
case "ends-with":
|
|
3053
|
+
{
|
|
3054
|
+
const urlObj = new URL(url);
|
|
3055
|
+
let route = "/";
|
|
3056
|
+
if (urlObj.pathname !== "/") {
|
|
3057
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
3058
|
+
}
|
|
3059
|
+
else {
|
|
3060
|
+
route = "/";
|
|
3061
|
+
}
|
|
3062
|
+
if (route !== queryText) {
|
|
3063
|
+
if (i === 29) {
|
|
3064
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
3065
|
+
}
|
|
3066
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3067
|
+
continue;
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
break;
|
|
3071
|
+
case "regex":
|
|
3072
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3073
|
+
if (!regex.test(url)) {
|
|
3074
|
+
if (i === 29) {
|
|
3075
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
3076
|
+
}
|
|
3077
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3078
|
+
continue;
|
|
3079
|
+
}
|
|
3080
|
+
break;
|
|
3081
|
+
default:
|
|
3082
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3083
|
+
if (!url.includes(pathPart)) {
|
|
3084
|
+
if (i === 29) {
|
|
3085
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
3086
|
+
}
|
|
3087
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3088
|
+
continue;
|
|
3089
|
+
}
|
|
2430
3090
|
}
|
|
2431
|
-
|
|
2432
|
-
return info;
|
|
3091
|
+
await _screenshot(state, this);
|
|
3092
|
+
return state.info;
|
|
2433
3093
|
}
|
|
2434
3094
|
}
|
|
2435
3095
|
catch (e) {
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
info.screenshotPath = screenshotPath;
|
|
2440
|
-
Object.assign(e, { info: info });
|
|
2441
|
-
error = e;
|
|
2442
|
-
// throw e;
|
|
2443
|
-
await _commandError({ text: "verifyPagePath", operation: "verifyPagePath", pathPart, info }, e, this);
|
|
3096
|
+
state.info.failCause.lastError = e.message;
|
|
3097
|
+
state.info.failCause.assertionFailed = true;
|
|
3098
|
+
await _commandError(state, e, this);
|
|
2444
3099
|
}
|
|
2445
3100
|
finally {
|
|
2446
|
-
|
|
2447
|
-
_reportToWorld(world, {
|
|
2448
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2449
|
-
text: "Verify page path",
|
|
2450
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2451
|
-
screenshotId,
|
|
2452
|
-
result: error
|
|
2453
|
-
? {
|
|
2454
|
-
status: "FAILED",
|
|
2455
|
-
startTime,
|
|
2456
|
-
endTime,
|
|
2457
|
-
message: error?.message,
|
|
2458
|
-
}
|
|
2459
|
-
: {
|
|
2460
|
-
status: "PASSED",
|
|
2461
|
-
startTime,
|
|
2462
|
-
endTime,
|
|
2463
|
-
},
|
|
2464
|
-
info: info,
|
|
2465
|
-
});
|
|
3101
|
+
await _commandFinally(state, this);
|
|
2466
3102
|
}
|
|
2467
3103
|
}
|
|
3104
|
+
/**
|
|
3105
|
+
* Verify the page title matches the given title.
|
|
3106
|
+
* @param {string} title - The title to verify.
|
|
3107
|
+
* @param {object} options - Options for verification.
|
|
3108
|
+
* @param {object} world - The world context.
|
|
3109
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
3110
|
+
*/
|
|
2468
3111
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2469
|
-
const startTime = Date.now();
|
|
2470
3112
|
let error = null;
|
|
2471
3113
|
let screenshotId = null;
|
|
2472
3114
|
let screenshotPath = null;
|
|
2473
3115
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2474
|
-
const info = {};
|
|
2475
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2476
|
-
info.operation = "verifyPageTitle";
|
|
2477
3116
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2478
3117
|
if (newValue !== title) {
|
|
2479
3118
|
this.logger.info(title + "=" + newValue);
|
|
2480
3119
|
title = newValue;
|
|
2481
3120
|
}
|
|
2482
|
-
|
|
3121
|
+
const { matcher, queryText } = this._matcher(title);
|
|
3122
|
+
const state = {
|
|
3123
|
+
text_search: queryText,
|
|
3124
|
+
options,
|
|
3125
|
+
world,
|
|
3126
|
+
locate: false,
|
|
3127
|
+
scroll: false,
|
|
3128
|
+
highlight: false,
|
|
3129
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
3130
|
+
text: `Verify the page title is ${queryText}`,
|
|
3131
|
+
_text: `Verify the page title is ${queryText}`,
|
|
3132
|
+
operation: "verifyPageTitle",
|
|
3133
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
3134
|
+
};
|
|
2483
3135
|
try {
|
|
3136
|
+
await _preCommand(state, this);
|
|
3137
|
+
state.info.text = queryText;
|
|
2484
3138
|
for (let i = 0; i < 30; i++) {
|
|
2485
3139
|
const foundTitle = await this.page.title();
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
3140
|
+
switch (matcher) {
|
|
3141
|
+
case "exact":
|
|
3142
|
+
if (foundTitle !== queryText) {
|
|
3143
|
+
if (i === 29) {
|
|
3144
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
3145
|
+
}
|
|
3146
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3147
|
+
continue;
|
|
3148
|
+
}
|
|
3149
|
+
break;
|
|
3150
|
+
case "contains":
|
|
3151
|
+
if (!foundTitle.includes(queryText)) {
|
|
3152
|
+
if (i === 29) {
|
|
3153
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
3154
|
+
}
|
|
3155
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3156
|
+
continue;
|
|
3157
|
+
}
|
|
3158
|
+
break;
|
|
3159
|
+
case "starts-with":
|
|
3160
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3161
|
+
if (i === 29) {
|
|
3162
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3163
|
+
}
|
|
3164
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3165
|
+
continue;
|
|
3166
|
+
}
|
|
3167
|
+
break;
|
|
3168
|
+
case "ends-with":
|
|
3169
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3170
|
+
if (i === 29) {
|
|
3171
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3172
|
+
}
|
|
3173
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3174
|
+
continue;
|
|
3175
|
+
}
|
|
3176
|
+
break;
|
|
3177
|
+
case "regex":
|
|
3178
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3179
|
+
if (!regex.test(foundTitle)) {
|
|
3180
|
+
if (i === 29) {
|
|
3181
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3182
|
+
}
|
|
3183
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3184
|
+
continue;
|
|
3185
|
+
}
|
|
3186
|
+
break;
|
|
3187
|
+
default:
|
|
3188
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3189
|
+
if (!foundTitle.includes(title)) {
|
|
3190
|
+
if (i === 29) {
|
|
3191
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3192
|
+
}
|
|
3193
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3194
|
+
continue;
|
|
3195
|
+
}
|
|
2492
3196
|
}
|
|
2493
|
-
|
|
2494
|
-
return info;
|
|
3197
|
+
await _screenshot(state, this);
|
|
3198
|
+
return state.info;
|
|
2495
3199
|
}
|
|
2496
3200
|
}
|
|
2497
3201
|
catch (e) {
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
info.screenshotPath = screenshotPath;
|
|
2502
|
-
Object.assign(e, { info: info });
|
|
2503
|
-
error = e;
|
|
2504
|
-
// throw e;
|
|
2505
|
-
await _commandError({ text: "verifyPageTitle", operation: "verifyPageTitle", title, info, throwError: true }, e, this);
|
|
3202
|
+
state.info.failCause.lastError = e.message;
|
|
3203
|
+
state.info.failCause.assertionFailed = true;
|
|
3204
|
+
await _commandError(state, e, this);
|
|
2506
3205
|
}
|
|
2507
3206
|
finally {
|
|
2508
|
-
|
|
2509
|
-
_reportToWorld(world, {
|
|
2510
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2511
|
-
text: "Verify page title",
|
|
2512
|
-
_text: "Verify the page title contains " + title,
|
|
2513
|
-
screenshotId,
|
|
2514
|
-
result: error
|
|
2515
|
-
? {
|
|
2516
|
-
status: "FAILED",
|
|
2517
|
-
startTime,
|
|
2518
|
-
endTime,
|
|
2519
|
-
message: error?.message,
|
|
2520
|
-
}
|
|
2521
|
-
: {
|
|
2522
|
-
status: "PASSED",
|
|
2523
|
-
startTime,
|
|
2524
|
-
endTime,
|
|
2525
|
-
},
|
|
2526
|
-
info: info,
|
|
2527
|
-
});
|
|
3207
|
+
await _commandFinally(state, this);
|
|
2528
3208
|
}
|
|
2529
3209
|
}
|
|
2530
3210
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2608,27 +3288,10 @@ class StableBrowser {
|
|
|
2608
3288
|
const frame = resultWithElementsFound[0].frame;
|
|
2609
3289
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2610
3290
|
await this._highlightElements(frame, dataAttribute);
|
|
2611
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2612
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2613
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2614
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2615
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2616
|
-
// .then(async () => {
|
|
2617
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2618
|
-
// })
|
|
2619
|
-
// .catch(
|
|
2620
|
-
// (e) => {}
|
|
2621
|
-
// console.error(e)
|
|
2622
|
-
// );
|
|
2623
|
-
// });
|
|
2624
|
-
// }
|
|
2625
3291
|
const element = await frame.locator(dataAttribute).first();
|
|
2626
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2627
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2628
3292
|
if (element) {
|
|
2629
3293
|
await this.scrollIfNeeded(element, state.info);
|
|
2630
3294
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2631
|
-
// await _screenshot(state, this, element);
|
|
2632
3295
|
}
|
|
2633
3296
|
}
|
|
2634
3297
|
await _screenshot(state, this);
|
|
@@ -2638,7 +3301,6 @@ class StableBrowser {
|
|
|
2638
3301
|
console.error(error);
|
|
2639
3302
|
}
|
|
2640
3303
|
}
|
|
2641
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2642
3304
|
}
|
|
2643
3305
|
catch (e) {
|
|
2644
3306
|
await _commandError(state, e, this);
|
|
@@ -2720,6 +3382,8 @@ class StableBrowser {
|
|
|
2720
3382
|
operation: "verify_text_with_relation",
|
|
2721
3383
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2722
3384
|
};
|
|
3385
|
+
const cmdStartTime = Date.now();
|
|
3386
|
+
let cmdEndTime = null;
|
|
2723
3387
|
const timeout = this._getFindElementTimeout(options);
|
|
2724
3388
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2725
3389
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2755,6 +3419,17 @@ class StableBrowser {
|
|
|
2755
3419
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2756
3420
|
continue;
|
|
2757
3421
|
}
|
|
3422
|
+
else {
|
|
3423
|
+
cmdEndTime = Date.now();
|
|
3424
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3425
|
+
if (foundAncore) {
|
|
3426
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3427
|
+
}
|
|
3428
|
+
else {
|
|
3429
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
2758
3433
|
try {
|
|
2759
3434
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2760
3435
|
foundAncore = true;
|
|
@@ -3154,6 +3829,43 @@ class StableBrowser {
|
|
|
3154
3829
|
});
|
|
3155
3830
|
}
|
|
3156
3831
|
}
|
|
3832
|
+
/**
|
|
3833
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3834
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3835
|
+
* @param options - Optional configuration object
|
|
3836
|
+
* @param world - Optional world context
|
|
3837
|
+
* @returns Promise that resolves after the specified duration
|
|
3838
|
+
*/
|
|
3839
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3840
|
+
const state = {
|
|
3841
|
+
duration,
|
|
3842
|
+
options,
|
|
3843
|
+
world,
|
|
3844
|
+
locate: false,
|
|
3845
|
+
scroll: false,
|
|
3846
|
+
screenshot: false,
|
|
3847
|
+
highlight: false,
|
|
3848
|
+
type: Types.SLEEP,
|
|
3849
|
+
text: `Sleep for ${duration} ms`,
|
|
3850
|
+
_text: `Sleep for ${duration} ms`,
|
|
3851
|
+
operation: "sleep",
|
|
3852
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3853
|
+
};
|
|
3854
|
+
try {
|
|
3855
|
+
await _preCommand(state, this);
|
|
3856
|
+
if (duration < 0) {
|
|
3857
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3858
|
+
}
|
|
3859
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3860
|
+
return state.info;
|
|
3861
|
+
}
|
|
3862
|
+
catch (e) {
|
|
3863
|
+
await _commandError(state, e, this);
|
|
3864
|
+
}
|
|
3865
|
+
finally {
|
|
3866
|
+
await _commandFinally(state, this);
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3157
3869
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3158
3870
|
try {
|
|
3159
3871
|
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
@@ -3184,6 +3896,7 @@ class StableBrowser {
|
|
|
3184
3896
|
}
|
|
3185
3897
|
async saveStoreState(path = null, world = null) {
|
|
3186
3898
|
const storageState = await this.page.context().storageState();
|
|
3899
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3187
3900
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3188
3901
|
if (path) {
|
|
3189
3902
|
// save { storageState: storageState } into the path
|
|
@@ -3194,10 +3907,14 @@ class StableBrowser {
|
|
|
3194
3907
|
}
|
|
3195
3908
|
}
|
|
3196
3909
|
async restoreSaveState(path = null, world = null) {
|
|
3910
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3197
3911
|
await refreshBrowser(this, path, world);
|
|
3198
3912
|
this.registerEventListeners(this.context);
|
|
3199
3913
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
3200
3914
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
3915
|
+
if (this.onRestoreSaveState) {
|
|
3916
|
+
this.onRestoreSaveState(path);
|
|
3917
|
+
}
|
|
3201
3918
|
}
|
|
3202
3919
|
async waitForPageLoad(options = {}, world = null) {
|
|
3203
3920
|
let timeout = this._getLoadTimeout(options);
|
|
@@ -3232,7 +3949,6 @@ class StableBrowser {
|
|
|
3232
3949
|
else if (e.label === "domcontentloaded") {
|
|
3233
3950
|
console.log("waited for the domcontent loaded timeout");
|
|
3234
3951
|
}
|
|
3235
|
-
console.log(".");
|
|
3236
3952
|
}
|
|
3237
3953
|
finally {
|
|
3238
3954
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -3276,7 +3992,6 @@ class StableBrowser {
|
|
|
3276
3992
|
await this.page.close();
|
|
3277
3993
|
}
|
|
3278
3994
|
catch (e) {
|
|
3279
|
-
console.log(".");
|
|
3280
3995
|
await _commandError(state, e, this);
|
|
3281
3996
|
}
|
|
3282
3997
|
finally {
|
|
@@ -3391,7 +4106,6 @@ class StableBrowser {
|
|
|
3391
4106
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3392
4107
|
}
|
|
3393
4108
|
catch (e) {
|
|
3394
|
-
console.log(".");
|
|
3395
4109
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3396
4110
|
}
|
|
3397
4111
|
finally {
|
|
@@ -3429,7 +4143,6 @@ class StableBrowser {
|
|
|
3429
4143
|
await this.page.reload();
|
|
3430
4144
|
}
|
|
3431
4145
|
catch (e) {
|
|
3432
|
-
console.log(".");
|
|
3433
4146
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3434
4147
|
}
|
|
3435
4148
|
finally {
|
|
@@ -3473,6 +4186,10 @@ class StableBrowser {
|
|
|
3473
4186
|
}
|
|
3474
4187
|
}
|
|
3475
4188
|
async beforeScenario(world, scenario) {
|
|
4189
|
+
if (world && world.attach) {
|
|
4190
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4191
|
+
}
|
|
4192
|
+
this.context.loadedRoutes = null;
|
|
3476
4193
|
this.beforeScenarioCalled = true;
|
|
3477
4194
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
3478
4195
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -3496,14 +4213,18 @@ class StableBrowser {
|
|
|
3496
4213
|
envName = this.context.environment.name;
|
|
3497
4214
|
}
|
|
3498
4215
|
if (!process.env.TEMP_RUN) {
|
|
3499
|
-
await getTestData(envName, world, undefined, this.featureName, this.scenarioName);
|
|
4216
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
3500
4217
|
}
|
|
3501
4218
|
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3502
4219
|
}
|
|
3503
4220
|
async afterScenario(world, scenario) { }
|
|
3504
4221
|
async beforeStep(world, step) {
|
|
4222
|
+
if (this.abortedExecution) {
|
|
4223
|
+
throw new Error("Aborted");
|
|
4224
|
+
}
|
|
3505
4225
|
if (!this.beforeScenarioCalled) {
|
|
3506
4226
|
this.beforeScenario(world, step);
|
|
4227
|
+
this.context.loadedRoutes = null;
|
|
3507
4228
|
}
|
|
3508
4229
|
if (this.stepIndex === undefined) {
|
|
3509
4230
|
this.stepIndex = 0;
|
|
@@ -3528,13 +4249,16 @@ class StableBrowser {
|
|
|
3528
4249
|
}
|
|
3529
4250
|
if (this.initSnapshotTaken === false) {
|
|
3530
4251
|
this.initSnapshotTaken = true;
|
|
3531
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4252
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3532
4253
|
const snapshot = await this.getAriaSnapshot();
|
|
3533
4254
|
if (snapshot) {
|
|
3534
4255
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3535
4256
|
}
|
|
3536
4257
|
}
|
|
3537
4258
|
}
|
|
4259
|
+
this.context.routeResults = null;
|
|
4260
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4261
|
+
networkBeforeStep(this.stepName);
|
|
3538
4262
|
}
|
|
3539
4263
|
async getAriaSnapshot() {
|
|
3540
4264
|
try {
|
|
@@ -3554,12 +4278,18 @@ class StableBrowser {
|
|
|
3554
4278
|
try {
|
|
3555
4279
|
// Ensure frame is attached and has body
|
|
3556
4280
|
const body = frame.locator("body");
|
|
3557
|
-
await body.waitFor({ timeout }); // wait explicitly
|
|
4281
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
3558
4282
|
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4283
|
+
if (!snapshot) {
|
|
4284
|
+
continue;
|
|
4285
|
+
}
|
|
3559
4286
|
content.push(`- frame: ${i}`);
|
|
3560
4287
|
content.push(snapshot);
|
|
3561
4288
|
}
|
|
3562
|
-
catch (innerErr) {
|
|
4289
|
+
catch (innerErr) {
|
|
4290
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4291
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4292
|
+
}
|
|
3563
4293
|
}
|
|
3564
4294
|
return content.join("\n");
|
|
3565
4295
|
}
|
|
@@ -3569,6 +4299,49 @@ class StableBrowser {
|
|
|
3569
4299
|
}
|
|
3570
4300
|
return null;
|
|
3571
4301
|
}
|
|
4302
|
+
/**
|
|
4303
|
+
* Sends command with custom payload to report.
|
|
4304
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4305
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4306
|
+
* @param content - Content of the command to be shown in the report.
|
|
4307
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4308
|
+
* @param world - Optional world context.
|
|
4309
|
+
* @public
|
|
4310
|
+
*/
|
|
4311
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4312
|
+
const state = {
|
|
4313
|
+
options,
|
|
4314
|
+
world,
|
|
4315
|
+
locate: false,
|
|
4316
|
+
scroll: false,
|
|
4317
|
+
screenshot: options.screenshot ?? false,
|
|
4318
|
+
highlight: options.highlight ?? false,
|
|
4319
|
+
type: Types.REPORT_COMMAND,
|
|
4320
|
+
text: commandText,
|
|
4321
|
+
_text: commandText,
|
|
4322
|
+
operation: "report_command",
|
|
4323
|
+
log: "***** " + commandText + " *****\n",
|
|
4324
|
+
};
|
|
4325
|
+
try {
|
|
4326
|
+
await _preCommand(state, this);
|
|
4327
|
+
const payload = {
|
|
4328
|
+
type: options.type ?? "text",
|
|
4329
|
+
content: content,
|
|
4330
|
+
screenshotId: null,
|
|
4331
|
+
};
|
|
4332
|
+
state.payload = payload;
|
|
4333
|
+
if (commandStatus === "FAILED") {
|
|
4334
|
+
state.throwError = true;
|
|
4335
|
+
throw new Error("Command failed");
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
catch (e) {
|
|
4339
|
+
await _commandError(state, e, this);
|
|
4340
|
+
}
|
|
4341
|
+
finally {
|
|
4342
|
+
await _commandFinally(state, this);
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
3572
4345
|
async afterStep(world, step) {
|
|
3573
4346
|
this.stepName = null;
|
|
3574
4347
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3576,23 +4349,55 @@ class StableBrowser {
|
|
|
3576
4349
|
await this.context.browserObject.context.tracing.stopChunk({
|
|
3577
4350
|
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
3578
4351
|
});
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
4352
|
+
if (world && world.attach) {
|
|
4353
|
+
await world.attach(JSON.stringify({
|
|
4354
|
+
type: "trace",
|
|
4355
|
+
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4356
|
+
}), "application/json+trace");
|
|
4357
|
+
}
|
|
3583
4358
|
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
3584
4359
|
}
|
|
3585
4360
|
}
|
|
3586
4361
|
if (this.context) {
|
|
3587
4362
|
this.context.examplesRow = null;
|
|
3588
4363
|
}
|
|
3589
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4364
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3590
4365
|
const snapshot = await this.getAriaSnapshot();
|
|
3591
4366
|
if (snapshot) {
|
|
3592
4367
|
const obj = {};
|
|
3593
4368
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3594
4369
|
}
|
|
3595
4370
|
}
|
|
4371
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4372
|
+
if (this.context.routeResults) {
|
|
4373
|
+
if (world && world.attach) {
|
|
4374
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4377
|
+
if (!process.env.TEMP_RUN) {
|
|
4378
|
+
const state = {
|
|
4379
|
+
world,
|
|
4380
|
+
locate: false,
|
|
4381
|
+
scroll: false,
|
|
4382
|
+
screenshot: true,
|
|
4383
|
+
highlight: true,
|
|
4384
|
+
type: Types.STEP_COMPLETE,
|
|
4385
|
+
text: "end of scenario",
|
|
4386
|
+
_text: "end of scenario",
|
|
4387
|
+
operation: "step_complete",
|
|
4388
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4389
|
+
};
|
|
4390
|
+
try {
|
|
4391
|
+
await _preCommand(state, this);
|
|
4392
|
+
}
|
|
4393
|
+
catch (e) {
|
|
4394
|
+
await _commandError(state, e, this);
|
|
4395
|
+
}
|
|
4396
|
+
finally {
|
|
4397
|
+
await _commandFinally(state, this);
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
networkAfterStep(this.stepName);
|
|
3596
4401
|
}
|
|
3597
4402
|
}
|
|
3598
4403
|
function createTimedPromise(promise, label) {
|