automation_model 1.0.710-dev → 1.0.710-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 +4 -3
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +4 -2
- package/lib/auto_page.js +142 -86
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +22 -25
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.js.map +1 -1
- package/lib/check_performance.d.ts +1 -0
- package/lib/check_performance.js +57 -0
- package/lib/check_performance.js.map +1 -0
- package/lib/command_common.d.ts +1 -1
- package/lib/command_common.js +25 -2
- 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/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/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/init_browser.js +115 -125
- 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.js +150 -39
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +62 -26
- package/lib/stable_browser.js +1017 -207
- 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/utils.d.ts +3 -1
- package/lib/utils.js +92 -63
- package/lib/utils.js.map +1 -1
- package/package.json +13 -7
package/lib/stable_browser.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
+
import { check_performance } from "./check_performance.js";
|
|
2
3
|
import { expect } from "@playwright/test";
|
|
3
4
|
import dayjs from "dayjs";
|
|
4
5
|
import fs from "fs";
|
|
@@ -10,7 +11,8 @@ import { getDateTimeValue } from "./date_time.js";
|
|
|
10
11
|
import drawRectangle from "./drawRect.js";
|
|
11
12
|
//import { closeUnexpectedPopups } from "./popups.js";
|
|
12
13
|
import { getTableCells, getTableData } from "./table_analyze.js";
|
|
13
|
-
import
|
|
14
|
+
import errorStackParser from "error-stack-parser";
|
|
15
|
+
import { _convertToRegexQuery, _copyContext, _fixLocatorUsingParams, _fixUsingParams, _getServerUrl, extractStepExampleParameters, KEYBOARD_EVENTS, maskValue, replaceWithLocalTestData, scrollPageToLoadLazyElements, unEscapeString, _getDataFile, testForRegex, performAction, _getTestData, } from "./utils.js";
|
|
14
16
|
import csv from "csv-parser";
|
|
15
17
|
import { Readable } from "node:stream";
|
|
16
18
|
import readline from "readline";
|
|
@@ -19,35 +21,42 @@ import { getTestData } from "./auto_page.js";
|
|
|
19
21
|
import { locate_element } from "./locate_element.js";
|
|
20
22
|
import { randomUUID } from "crypto";
|
|
21
23
|
import { _commandError, _commandFinally, _preCommand, _validateSelectors, _screenshot, _reportToWorld, } from "./command_common.js";
|
|
22
|
-
import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
24
|
+
import { networkAfterStep, networkBeforeStep, registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
23
25
|
import { LocatorLog } from "./locator_log.js";
|
|
24
26
|
import axios from "axios";
|
|
25
27
|
import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
26
|
-
import { snapshotValidation } from "./snapshot_validation.js";
|
|
28
|
+
import { highlightSnapshot, snapshotValidation } from "./snapshot_validation.js";
|
|
27
29
|
import { loadBrunoParams } from "./bruno.js";
|
|
30
|
+
import { registerAfterStepRoutes, registerBeforeStepRoutes } from "./route.js";
|
|
31
|
+
import { existsSync } from "node:fs";
|
|
28
32
|
export const Types = {
|
|
29
33
|
CLICK: "click_element",
|
|
30
34
|
WAIT_ELEMENT: "wait_element",
|
|
31
35
|
NAVIGATE: "navigate",
|
|
36
|
+
GO_BACK: "go_back",
|
|
37
|
+
GO_FORWARD: "go_forward",
|
|
32
38
|
FILL: "fill_element",
|
|
33
|
-
EXECUTE: "execute_page_method",
|
|
34
|
-
OPEN: "open_environment",
|
|
39
|
+
EXECUTE: "execute_page_method", //
|
|
40
|
+
OPEN: "open_environment", //
|
|
35
41
|
COMPLETE: "step_complete",
|
|
36
42
|
ASK: "information_needed",
|
|
37
|
-
GET_PAGE_STATUS: "get_page_status",
|
|
38
|
-
CLICK_ROW_ACTION: "click_row_action",
|
|
43
|
+
GET_PAGE_STATUS: "get_page_status", ///
|
|
44
|
+
CLICK_ROW_ACTION: "click_row_action", //
|
|
39
45
|
VERIFY_ELEMENT_CONTAINS_TEXT: "verify_element_contains_text",
|
|
40
46
|
VERIFY_PAGE_CONTAINS_TEXT: "verify_page_contains_text",
|
|
41
47
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
42
48
|
ANALYZE_TABLE: "analyze_table",
|
|
43
|
-
SELECT: "select_combobox",
|
|
49
|
+
SELECT: "select_combobox", //
|
|
50
|
+
VERIFY_PROPERTY: "verify_element_property",
|
|
44
51
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
52
|
+
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
45
53
|
TYPE_PRESS: "type_press",
|
|
46
54
|
PRESS: "press_key",
|
|
47
55
|
HOVER: "hover_element",
|
|
48
56
|
CHECK: "check_element",
|
|
49
57
|
UNCHECK: "uncheck_element",
|
|
50
58
|
EXTRACT: "extract_attribute",
|
|
59
|
+
EXTRACT_PROPERTY: "extract_property",
|
|
51
60
|
CLOSE_PAGE: "close_page",
|
|
52
61
|
TABLE_OPERATION: "table_operation",
|
|
53
62
|
SET_DATE_TIME: "set_date_time",
|
|
@@ -59,9 +68,13 @@ export const Types = {
|
|
|
59
68
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
60
69
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
61
70
|
BRUNO: "bruno",
|
|
62
|
-
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
63
71
|
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
64
72
|
SET_INPUT_FILES: "set_input_files",
|
|
73
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
74
|
+
REPORT_COMMAND: "report_command",
|
|
75
|
+
STEP_COMPLETE: "step_complete",
|
|
76
|
+
SLEEP: "sleep",
|
|
77
|
+
CONDITIONAL_WAIT: "conditional_wait",
|
|
65
78
|
};
|
|
66
79
|
export const apps = {};
|
|
67
80
|
const formatElementName = (elementName) => {
|
|
@@ -73,6 +86,7 @@ class StableBrowser {
|
|
|
73
86
|
logger;
|
|
74
87
|
context;
|
|
75
88
|
world;
|
|
89
|
+
fastMode;
|
|
76
90
|
project_path = null;
|
|
77
91
|
webLogFile = null;
|
|
78
92
|
networkLogger = null;
|
|
@@ -81,12 +95,15 @@ class StableBrowser {
|
|
|
81
95
|
tags = null;
|
|
82
96
|
isRecording = false;
|
|
83
97
|
initSnapshotTaken = false;
|
|
84
|
-
|
|
98
|
+
abortedExecution = false;
|
|
99
|
+
onlyFailuresScreenshot = process.env.SCREENSHOT_ON_FAILURE_ONLY === "true";
|
|
100
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
85
101
|
this.browser = browser;
|
|
86
102
|
this.page = page;
|
|
87
103
|
this.logger = logger;
|
|
88
104
|
this.context = context;
|
|
89
105
|
this.world = world;
|
|
106
|
+
this.fastMode = fastMode;
|
|
90
107
|
if (!this.logger) {
|
|
91
108
|
this.logger = console;
|
|
92
109
|
}
|
|
@@ -115,6 +132,19 @@ class StableBrowser {
|
|
|
115
132
|
context.pages = [this.page];
|
|
116
133
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
117
134
|
this.world = world;
|
|
135
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
136
|
+
this.fastMode = true;
|
|
137
|
+
}
|
|
138
|
+
if (process.env.FAST_MODE === "true") {
|
|
139
|
+
// console.log("Fast mode enabled from environment variable");
|
|
140
|
+
this.fastMode = true;
|
|
141
|
+
}
|
|
142
|
+
if (process.env.FAST_MODE === "false") {
|
|
143
|
+
this.fastMode = false;
|
|
144
|
+
}
|
|
145
|
+
if (this.context) {
|
|
146
|
+
this.context.fastMode = this.fastMode;
|
|
147
|
+
}
|
|
118
148
|
this.registerEventListeners(this.context);
|
|
119
149
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
120
150
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -125,6 +155,9 @@ class StableBrowser {
|
|
|
125
155
|
if (!context.pageLoading) {
|
|
126
156
|
context.pageLoading = { status: false };
|
|
127
157
|
}
|
|
158
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
159
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
160
|
+
}
|
|
128
161
|
context.playContext.on("page", async function (page) {
|
|
129
162
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
130
163
|
console.log("close unexpected popups");
|
|
@@ -133,6 +166,14 @@ class StableBrowser {
|
|
|
133
166
|
}
|
|
134
167
|
context.pageLoading.status = true;
|
|
135
168
|
this.page = page;
|
|
169
|
+
try {
|
|
170
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
171
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error("Error on dialog accept registration", error);
|
|
176
|
+
}
|
|
136
177
|
context.page = page;
|
|
137
178
|
context.pages.push(page);
|
|
138
179
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
@@ -184,7 +225,9 @@ class StableBrowser {
|
|
|
184
225
|
if (newContextCreated) {
|
|
185
226
|
this.registerEventListeners(this.context);
|
|
186
227
|
await this.goto(this.context.environment.baseUrl);
|
|
187
|
-
|
|
228
|
+
if (!this.fastMode) {
|
|
229
|
+
await this.waitForPageLoad();
|
|
230
|
+
}
|
|
188
231
|
}
|
|
189
232
|
}
|
|
190
233
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -278,6 +321,7 @@ class StableBrowser {
|
|
|
278
321
|
if (!url) {
|
|
279
322
|
throw new Error("url is null, verify that the environment file is correct");
|
|
280
323
|
}
|
|
324
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
281
325
|
if (!url.startsWith("http")) {
|
|
282
326
|
url = "https://" + url;
|
|
283
327
|
}
|
|
@@ -309,6 +353,64 @@ class StableBrowser {
|
|
|
309
353
|
await _commandFinally(state, this);
|
|
310
354
|
}
|
|
311
355
|
}
|
|
356
|
+
async goBack(options, world = null) {
|
|
357
|
+
const state = {
|
|
358
|
+
value: "",
|
|
359
|
+
world: world,
|
|
360
|
+
type: Types.GO_BACK,
|
|
361
|
+
text: `Browser navigate back`,
|
|
362
|
+
operation: "goBack",
|
|
363
|
+
log: "***** navigate back *****\n",
|
|
364
|
+
info: {},
|
|
365
|
+
locate: false,
|
|
366
|
+
scroll: false,
|
|
367
|
+
screenshot: false,
|
|
368
|
+
highlight: false,
|
|
369
|
+
};
|
|
370
|
+
try {
|
|
371
|
+
await _preCommand(state, this);
|
|
372
|
+
await this.page.goBack({
|
|
373
|
+
waitUntil: "load",
|
|
374
|
+
});
|
|
375
|
+
await _screenshot(state, this);
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
console.error("Error on goBack", error);
|
|
379
|
+
_commandError(state, error, this);
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
await _commandFinally(state, this);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async goForward(options, world = null) {
|
|
386
|
+
const state = {
|
|
387
|
+
value: "",
|
|
388
|
+
world: world,
|
|
389
|
+
type: Types.GO_FORWARD,
|
|
390
|
+
text: `Browser navigate forward`,
|
|
391
|
+
operation: "goForward",
|
|
392
|
+
log: "***** navigate forward *****\n",
|
|
393
|
+
info: {},
|
|
394
|
+
locate: false,
|
|
395
|
+
scroll: false,
|
|
396
|
+
screenshot: false,
|
|
397
|
+
highlight: false,
|
|
398
|
+
};
|
|
399
|
+
try {
|
|
400
|
+
await _preCommand(state, this);
|
|
401
|
+
await this.page.goForward({
|
|
402
|
+
waitUntil: "load",
|
|
403
|
+
});
|
|
404
|
+
await _screenshot(state, this);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
console.error("Error on goForward", error);
|
|
408
|
+
_commandError(state, error, this);
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
await _commandFinally(state, this);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
312
414
|
async _getLocator(locator, scope, _params) {
|
|
313
415
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
314
416
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -407,12 +509,6 @@ class StableBrowser {
|
|
|
407
509
|
if (!el.setAttribute) {
|
|
408
510
|
el = el.parentElement;
|
|
409
511
|
}
|
|
410
|
-
// remove any attributes start with data-blinq-id
|
|
411
|
-
// for (let i = 0; i < el.attributes.length; i++) {
|
|
412
|
-
// if (el.attributes[i].name.startsWith("data-blinq-id")) {
|
|
413
|
-
// el.removeAttribute(el.attributes[i].name);
|
|
414
|
-
// }
|
|
415
|
-
// }
|
|
416
512
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
417
513
|
return true;
|
|
418
514
|
}, [tag1, randomToken]))) {
|
|
@@ -422,7 +518,7 @@ class StableBrowser {
|
|
|
422
518
|
}
|
|
423
519
|
return { elementCount: tagCount, randomToken };
|
|
424
520
|
}
|
|
425
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
521
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
426
522
|
if (!info) {
|
|
427
523
|
info = {};
|
|
428
524
|
}
|
|
@@ -434,14 +530,13 @@ class StableBrowser {
|
|
|
434
530
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
435
531
|
}
|
|
436
532
|
let locatorSearch = selectorHierarchy[index];
|
|
437
|
-
let originalLocatorSearch = "";
|
|
438
533
|
try {
|
|
439
|
-
|
|
440
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
534
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
441
535
|
}
|
|
442
536
|
catch (e) {
|
|
443
537
|
console.error(e);
|
|
444
538
|
}
|
|
539
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
445
540
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
446
541
|
let locator = null;
|
|
447
542
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -489,7 +584,7 @@ class StableBrowser {
|
|
|
489
584
|
}
|
|
490
585
|
return;
|
|
491
586
|
}
|
|
492
|
-
if (info.locatorLog && count === 0) {
|
|
587
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
493
588
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
494
589
|
}
|
|
495
590
|
for (let j = 0; j < count; j++) {
|
|
@@ -504,7 +599,7 @@ class StableBrowser {
|
|
|
504
599
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
505
600
|
}
|
|
506
601
|
}
|
|
507
|
-
else {
|
|
602
|
+
else if (logErrors) {
|
|
508
603
|
info.failCause.visible = visible;
|
|
509
604
|
info.failCause.enabled = enabled;
|
|
510
605
|
if (!info.printMessages) {
|
|
@@ -583,27 +678,148 @@ class StableBrowser {
|
|
|
583
678
|
}
|
|
584
679
|
return { rerun: false };
|
|
585
680
|
}
|
|
681
|
+
getFilePath() {
|
|
682
|
+
const stackFrames = errorStackParser.parse(new Error());
|
|
683
|
+
const stackFrame = stackFrames.findLast((frame) => frame.fileName && frame.fileName.endsWith(".mjs"));
|
|
684
|
+
// return stackFrame?.fileName || null;
|
|
685
|
+
const filepath = stackFrame?.fileName;
|
|
686
|
+
if (filepath) {
|
|
687
|
+
let jsonFilePath = filepath.replace(".mjs", ".json");
|
|
688
|
+
if (existsSync(jsonFilePath)) {
|
|
689
|
+
return jsonFilePath;
|
|
690
|
+
}
|
|
691
|
+
const config = this.configuration ?? {};
|
|
692
|
+
if (!config?.locatorsMetadataDir) {
|
|
693
|
+
config.locatorsMetadataDir = "features/step_definitions/locators";
|
|
694
|
+
}
|
|
695
|
+
if (config && config.locatorsMetadataDir) {
|
|
696
|
+
jsonFilePath = path.join(config.locatorsMetadataDir, path.basename(jsonFilePath));
|
|
697
|
+
}
|
|
698
|
+
if (existsSync(jsonFilePath)) {
|
|
699
|
+
return jsonFilePath;
|
|
700
|
+
}
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
getFullElementLocators(selectors, filePath) {
|
|
706
|
+
if (!filePath || !existsSync(filePath)) {
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
710
|
+
try {
|
|
711
|
+
const allElements = JSON.parse(content);
|
|
712
|
+
const element_key = selectors?.element_key;
|
|
713
|
+
if (element_key && allElements[element_key]) {
|
|
714
|
+
return allElements[element_key];
|
|
715
|
+
}
|
|
716
|
+
for (const elementKey in allElements) {
|
|
717
|
+
const element = allElements[elementKey];
|
|
718
|
+
let foundStrategy = null;
|
|
719
|
+
for (const key in element) {
|
|
720
|
+
if (key === "strategy") {
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
const locators = element[key];
|
|
724
|
+
if (!locators || !locators.length) {
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
for (const locator of locators) {
|
|
728
|
+
delete locator.score;
|
|
729
|
+
}
|
|
730
|
+
if (JSON.stringify(locators) === JSON.stringify(selectors.locators)) {
|
|
731
|
+
foundStrategy = key;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (foundStrategy) {
|
|
736
|
+
return element;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
catch (error) {
|
|
741
|
+
console.error("Error parsing locators from file: " + filePath, error);
|
|
742
|
+
}
|
|
743
|
+
return null;
|
|
744
|
+
}
|
|
586
745
|
async _locate(selectors, info, _params, timeout, allowDisabled = false) {
|
|
587
746
|
if (!timeout) {
|
|
588
747
|
timeout = 30000;
|
|
589
748
|
}
|
|
749
|
+
let element = null;
|
|
750
|
+
let allStrategyLocators = null;
|
|
751
|
+
let selectedStrategy = null;
|
|
752
|
+
if (this.tryAllStrategies) {
|
|
753
|
+
allStrategyLocators = this.getFullElementLocators(selectors, this.getFilePath());
|
|
754
|
+
selectedStrategy = allStrategyLocators?.strategy;
|
|
755
|
+
}
|
|
590
756
|
for (let i = 0; i < 3; i++) {
|
|
591
757
|
info.log += "attempt " + i + ": total locators " + selectors.locators.length + "\n";
|
|
592
758
|
for (let j = 0; j < selectors.locators.length; j++) {
|
|
593
759
|
let selector = selectors.locators[j];
|
|
594
760
|
info.log += "searching for locator " + j + ":" + JSON.stringify(selector) + "\n";
|
|
595
761
|
}
|
|
596
|
-
|
|
762
|
+
if (this.tryAllStrategies && selectedStrategy) {
|
|
763
|
+
const strategyLocators = allStrategyLocators[selectedStrategy];
|
|
764
|
+
let err;
|
|
765
|
+
if (strategyLocators && strategyLocators.length) {
|
|
766
|
+
try {
|
|
767
|
+
selectors.locators = strategyLocators;
|
|
768
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
769
|
+
info.selectedStrategy = selectedStrategy;
|
|
770
|
+
info.log += "element found using strategy " + selectedStrategy + "\n";
|
|
771
|
+
}
|
|
772
|
+
catch (error) {
|
|
773
|
+
err = error;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (!element) {
|
|
777
|
+
for (const key in allStrategyLocators) {
|
|
778
|
+
if (key === "strategy" || key === selectedStrategy) {
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
const strategyLocators = allStrategyLocators[key];
|
|
782
|
+
if (strategyLocators && strategyLocators.length) {
|
|
783
|
+
try {
|
|
784
|
+
info.log += "using strategy " + key + " with locators " + JSON.stringify(strategyLocators) + "\n";
|
|
785
|
+
selectors.locators = strategyLocators;
|
|
786
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
787
|
+
err = null;
|
|
788
|
+
info.selectedStrategy = key;
|
|
789
|
+
info.log += "element found using strategy " + key + "\n";
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
catch (error) {
|
|
793
|
+
err = error;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (err) {
|
|
799
|
+
throw err;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
804
|
+
}
|
|
597
805
|
if (!element.rerun) {
|
|
598
|
-
const randomToken = Math.random().toString(36).substring(7);
|
|
599
|
-
element.evaluate((el, randomToken) => {
|
|
600
|
-
|
|
806
|
+
const randomToken = "blinq_" + Math.random().toString(36).substring(7);
|
|
807
|
+
const id = await element.evaluate((el, randomToken) => {
|
|
808
|
+
// check if the element has id attribute
|
|
809
|
+
if (el.id) {
|
|
810
|
+
return el.id;
|
|
811
|
+
}
|
|
812
|
+
el.setAttribute("id", randomToken);
|
|
813
|
+
console.log("set id=" + randomToken + " on element", el);
|
|
814
|
+
return randomToken;
|
|
601
815
|
}, randomToken);
|
|
602
|
-
// if (element._frame) {
|
|
603
|
-
// return element;
|
|
604
|
-
// }
|
|
605
816
|
const scope = element._frame ?? element.page();
|
|
606
|
-
let newElementSelector = "
|
|
817
|
+
let newElementSelector = "#" + id;
|
|
818
|
+
// check if the id contains :
|
|
819
|
+
if (id.includes(":")) {
|
|
820
|
+
// //*[@id="radix-:r0:"]
|
|
821
|
+
newElementSelector = `//*[@id="${id}"]`;
|
|
822
|
+
}
|
|
607
823
|
let prefixSelector = "";
|
|
608
824
|
const frameControlSelector = " >> internal:control=enter-frame";
|
|
609
825
|
const frameSelectorIndex = element._selector.lastIndexOf(frameControlSelector);
|
|
@@ -649,7 +865,7 @@ class StableBrowser {
|
|
|
649
865
|
break;
|
|
650
866
|
}
|
|
651
867
|
catch (error) {
|
|
652
|
-
console.error("frame not found " + frameLocator.css);
|
|
868
|
+
// console.error("frame not found " + frameLocator.css);
|
|
653
869
|
}
|
|
654
870
|
}
|
|
655
871
|
}
|
|
@@ -727,7 +943,6 @@ class StableBrowser {
|
|
|
727
943
|
let locatorsCount = 0;
|
|
728
944
|
let lazy_scroll = false;
|
|
729
945
|
//let arrayMode = Array.isArray(selectors);
|
|
730
|
-
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
731
946
|
let selectorsLocators = null;
|
|
732
947
|
selectorsLocators = selectors.locators;
|
|
733
948
|
// group selectors by priority
|
|
@@ -755,6 +970,7 @@ class StableBrowser {
|
|
|
755
970
|
let highPriorityOnly = true;
|
|
756
971
|
let visibleOnly = true;
|
|
757
972
|
while (true) {
|
|
973
|
+
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
758
974
|
locatorsCount = 0;
|
|
759
975
|
let result = [];
|
|
760
976
|
let popupResult = await this.closeUnexpectedPopups(info, _params);
|
|
@@ -845,7 +1061,7 @@ class StableBrowser {
|
|
|
845
1061
|
}
|
|
846
1062
|
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
847
1063
|
}
|
|
848
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
1064
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
849
1065
|
let foundElements = [];
|
|
850
1066
|
const result = {
|
|
851
1067
|
foundElements: foundElements,
|
|
@@ -864,13 +1080,19 @@ class StableBrowser {
|
|
|
864
1080
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
865
1081
|
}
|
|
866
1082
|
catch (e) {
|
|
867
|
-
|
|
1083
|
+
if (logErrors) {
|
|
1084
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
1085
|
+
}
|
|
868
1086
|
}
|
|
869
1087
|
}
|
|
870
1088
|
if (foundLocators.length === 1) {
|
|
1089
|
+
let box = null;
|
|
1090
|
+
if (!this.onlyFailuresScreenshot) {
|
|
1091
|
+
box = await foundLocators[0].boundingBox();
|
|
1092
|
+
}
|
|
871
1093
|
result.foundElements.push({
|
|
872
1094
|
locator: foundLocators[0],
|
|
873
|
-
box:
|
|
1095
|
+
box: box,
|
|
874
1096
|
unique: true,
|
|
875
1097
|
});
|
|
876
1098
|
result.locatorIndex = i;
|
|
@@ -905,7 +1127,7 @@ class StableBrowser {
|
|
|
905
1127
|
});
|
|
906
1128
|
result.locatorIndex = i;
|
|
907
1129
|
}
|
|
908
|
-
else {
|
|
1130
|
+
else if (logErrors) {
|
|
909
1131
|
info.failCause.foundMultiple = true;
|
|
910
1132
|
if (info.locatorLog) {
|
|
911
1133
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -1025,17 +1247,30 @@ class StableBrowser {
|
|
|
1025
1247
|
operation: "click",
|
|
1026
1248
|
log: "***** click on " + selectors.element_name + " *****\n",
|
|
1027
1249
|
};
|
|
1250
|
+
check_performance("click_all ***", this.context, true);
|
|
1028
1251
|
try {
|
|
1252
|
+
check_performance("click_preCommand", this.context, true);
|
|
1029
1253
|
await _preCommand(state, this);
|
|
1254
|
+
check_performance("click_preCommand", this.context, false);
|
|
1030
1255
|
await performAction("click", state.element, options, this, state, _params);
|
|
1031
|
-
|
|
1256
|
+
if (!this.fastMode) {
|
|
1257
|
+
check_performance("click_waitForPageLoad", this.context, true);
|
|
1258
|
+
await this.waitForPageLoad({ noSleep: true });
|
|
1259
|
+
check_performance("click_waitForPageLoad", this.context, false);
|
|
1260
|
+
}
|
|
1032
1261
|
return state.info;
|
|
1033
1262
|
}
|
|
1034
1263
|
catch (e) {
|
|
1035
1264
|
await _commandError(state, e, this);
|
|
1036
1265
|
}
|
|
1037
1266
|
finally {
|
|
1267
|
+
check_performance("click_commandFinally", this.context, true);
|
|
1038
1268
|
await _commandFinally(state, this);
|
|
1269
|
+
check_performance("click_commandFinally", this.context, false);
|
|
1270
|
+
check_performance("click_all ***", this.context, false);
|
|
1271
|
+
if (this.context.profile) {
|
|
1272
|
+
console.log(JSON.stringify(this.context.profile, null, 2));
|
|
1273
|
+
}
|
|
1039
1274
|
}
|
|
1040
1275
|
}
|
|
1041
1276
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1091,7 +1326,7 @@ class StableBrowser {
|
|
|
1091
1326
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1092
1327
|
// console.log(`Highlighting while running from recorder`);
|
|
1093
1328
|
await this._highlightElements(state.element);
|
|
1094
|
-
await state.element.setChecked(checked);
|
|
1329
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1095
1330
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1096
1331
|
// await this._unHighlightElements(element);
|
|
1097
1332
|
// }
|
|
@@ -1103,14 +1338,31 @@ class StableBrowser {
|
|
|
1103
1338
|
this.logger.info("element did not change its state, ignoring...");
|
|
1104
1339
|
}
|
|
1105
1340
|
else {
|
|
1341
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1106
1342
|
//await this.closeUnexpectedPopups();
|
|
1107
1343
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1108
|
-
state.
|
|
1109
|
-
|
|
1110
|
-
|
|
1344
|
+
state.element_found = false;
|
|
1345
|
+
try {
|
|
1346
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1347
|
+
state.element_found = true;
|
|
1348
|
+
// check the check state
|
|
1349
|
+
}
|
|
1350
|
+
catch (error) {
|
|
1351
|
+
// element dismissed
|
|
1352
|
+
}
|
|
1353
|
+
if (state.element_found) {
|
|
1354
|
+
const isChecked = await state.element.isChecked();
|
|
1355
|
+
if (isChecked !== checked) {
|
|
1356
|
+
// perform click
|
|
1357
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1358
|
+
}
|
|
1359
|
+
else {
|
|
1360
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1111
1363
|
}
|
|
1112
1364
|
}
|
|
1113
|
-
await this.waitForPageLoad();
|
|
1365
|
+
//await this.waitForPageLoad();
|
|
1114
1366
|
return state.info;
|
|
1115
1367
|
}
|
|
1116
1368
|
catch (e) {
|
|
@@ -1136,7 +1388,7 @@ class StableBrowser {
|
|
|
1136
1388
|
await _preCommand(state, this);
|
|
1137
1389
|
await performAction("hover", state.element, options, this, state, _params);
|
|
1138
1390
|
await _screenshot(state, this);
|
|
1139
|
-
await this.waitForPageLoad();
|
|
1391
|
+
//await this.waitForPageLoad();
|
|
1140
1392
|
return state.info;
|
|
1141
1393
|
}
|
|
1142
1394
|
catch (e) {
|
|
@@ -1172,7 +1424,7 @@ class StableBrowser {
|
|
|
1172
1424
|
state.info.log += "selectOption failed, will try force" + "\n";
|
|
1173
1425
|
await state.element.selectOption(values, { timeout: 10000, force: true });
|
|
1174
1426
|
}
|
|
1175
|
-
await this.waitForPageLoad();
|
|
1427
|
+
//await this.waitForPageLoad();
|
|
1176
1428
|
return state.info;
|
|
1177
1429
|
}
|
|
1178
1430
|
catch (e) {
|
|
@@ -1403,7 +1655,9 @@ class StableBrowser {
|
|
|
1403
1655
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1404
1656
|
}
|
|
1405
1657
|
}
|
|
1658
|
+
//if (!this.fastMode) {
|
|
1406
1659
|
await _screenshot(state, this);
|
|
1660
|
+
//}
|
|
1407
1661
|
if (enter === true) {
|
|
1408
1662
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1409
1663
|
await this.page.keyboard.press("Enter");
|
|
@@ -1452,8 +1706,8 @@ class StableBrowser {
|
|
|
1452
1706
|
if (enter) {
|
|
1453
1707
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1454
1708
|
await this.page.keyboard.press("Enter");
|
|
1709
|
+
await this.waitForPageLoad();
|
|
1455
1710
|
}
|
|
1456
|
-
await this.waitForPageLoad();
|
|
1457
1711
|
return state.info;
|
|
1458
1712
|
}
|
|
1459
1713
|
catch (e) {
|
|
@@ -1745,11 +1999,16 @@ class StableBrowser {
|
|
|
1745
1999
|
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1746
2000
|
}
|
|
1747
2001
|
// highlight and screenshot
|
|
2002
|
+
try {
|
|
2003
|
+
await await highlightSnapshot(newValue, scope);
|
|
2004
|
+
await _screenshot(state, this);
|
|
2005
|
+
}
|
|
2006
|
+
catch (e) { }
|
|
1748
2007
|
return state.info;
|
|
1749
2008
|
}
|
|
1750
2009
|
catch (e) {
|
|
1751
2010
|
// Log error but continue retrying until timeout is reached
|
|
1752
|
-
this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
2011
|
+
//this.logger.warn("Retrying snapshot validation due to: " + e.message);
|
|
1753
2012
|
}
|
|
1754
2013
|
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 1 second before retrying
|
|
1755
2014
|
}
|
|
@@ -1903,12 +2162,7 @@ class StableBrowser {
|
|
|
1903
2162
|
}
|
|
1904
2163
|
}
|
|
1905
2164
|
getTestData(world = null) {
|
|
1906
|
-
|
|
1907
|
-
let data = {};
|
|
1908
|
-
if (fs.existsSync(dataFile)) {
|
|
1909
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1910
|
-
}
|
|
1911
|
-
return data;
|
|
2165
|
+
return _getTestData(world, this.context, this);
|
|
1912
2166
|
}
|
|
1913
2167
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1914
2168
|
// collect url/path/title
|
|
@@ -2128,6 +2382,77 @@ class StableBrowser {
|
|
|
2128
2382
|
await _commandFinally(state, this);
|
|
2129
2383
|
}
|
|
2130
2384
|
}
|
|
2385
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2386
|
+
const state = {
|
|
2387
|
+
selectors,
|
|
2388
|
+
_params,
|
|
2389
|
+
property,
|
|
2390
|
+
variable,
|
|
2391
|
+
options,
|
|
2392
|
+
world,
|
|
2393
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2394
|
+
text: `Extract property from element`,
|
|
2395
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2396
|
+
operation: "extractProperty",
|
|
2397
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2398
|
+
allowDisabled: true,
|
|
2399
|
+
};
|
|
2400
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2401
|
+
try {
|
|
2402
|
+
await _preCommand(state, this);
|
|
2403
|
+
switch (property) {
|
|
2404
|
+
case "inner_text":
|
|
2405
|
+
state.value = await state.element.innerText();
|
|
2406
|
+
break;
|
|
2407
|
+
case "href":
|
|
2408
|
+
state.value = await state.element.getAttribute("href");
|
|
2409
|
+
break;
|
|
2410
|
+
case "value":
|
|
2411
|
+
state.value = await state.element.inputValue();
|
|
2412
|
+
break;
|
|
2413
|
+
case "text":
|
|
2414
|
+
state.value = await state.element.textContent();
|
|
2415
|
+
break;
|
|
2416
|
+
default:
|
|
2417
|
+
if (property.startsWith("dataset.")) {
|
|
2418
|
+
const dataAttribute = property.substring(8);
|
|
2419
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2420
|
+
}
|
|
2421
|
+
else {
|
|
2422
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
if (options !== null) {
|
|
2426
|
+
if (options.regex && options.regex !== "") {
|
|
2427
|
+
// Construct a regex pattern from the provided string
|
|
2428
|
+
const regex = options.regex.slice(1, -1);
|
|
2429
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2430
|
+
const matches = state.value.match(regexPattern);
|
|
2431
|
+
if (matches) {
|
|
2432
|
+
let newValue = "";
|
|
2433
|
+
for (const match of matches) {
|
|
2434
|
+
newValue += match;
|
|
2435
|
+
}
|
|
2436
|
+
state.value = newValue;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2440
|
+
state.value = state.value.trim();
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
state.info.value = state.value;
|
|
2444
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2445
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2446
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2447
|
+
return state.info;
|
|
2448
|
+
}
|
|
2449
|
+
catch (e) {
|
|
2450
|
+
await _commandError(state, e, this);
|
|
2451
|
+
}
|
|
2452
|
+
finally {
|
|
2453
|
+
await _commandFinally(state, this);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2131
2456
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
2132
2457
|
const state = {
|
|
2133
2458
|
selectors,
|
|
@@ -2226,6 +2551,260 @@ class StableBrowser {
|
|
|
2226
2551
|
await _commandFinally(state, this);
|
|
2227
2552
|
}
|
|
2228
2553
|
}
|
|
2554
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2555
|
+
const state = {
|
|
2556
|
+
selectors,
|
|
2557
|
+
_params,
|
|
2558
|
+
property,
|
|
2559
|
+
value,
|
|
2560
|
+
options,
|
|
2561
|
+
world,
|
|
2562
|
+
type: Types.VERIFY_PROPERTY,
|
|
2563
|
+
highlight: true,
|
|
2564
|
+
screenshot: true,
|
|
2565
|
+
text: `Verify element property`,
|
|
2566
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2567
|
+
operation: "verifyProperty",
|
|
2568
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2569
|
+
allowDisabled: true,
|
|
2570
|
+
};
|
|
2571
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2572
|
+
let val;
|
|
2573
|
+
let expectedValue;
|
|
2574
|
+
try {
|
|
2575
|
+
await _preCommand(state, this);
|
|
2576
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2577
|
+
state.info.expectedValue = expectedValue;
|
|
2578
|
+
switch (property) {
|
|
2579
|
+
case "innerText":
|
|
2580
|
+
val = String(await state.element.innerText());
|
|
2581
|
+
break;
|
|
2582
|
+
case "text":
|
|
2583
|
+
val = String(await state.element.textContent());
|
|
2584
|
+
break;
|
|
2585
|
+
case "value":
|
|
2586
|
+
val = String(await state.element.inputValue());
|
|
2587
|
+
break;
|
|
2588
|
+
case "checked":
|
|
2589
|
+
val = String(await state.element.isChecked());
|
|
2590
|
+
break;
|
|
2591
|
+
case "disabled":
|
|
2592
|
+
val = String(await state.element.isDisabled());
|
|
2593
|
+
break;
|
|
2594
|
+
case "readOnly":
|
|
2595
|
+
const isEditable = await state.element.isEditable();
|
|
2596
|
+
val = String(!isEditable);
|
|
2597
|
+
break;
|
|
2598
|
+
case "innerHTML":
|
|
2599
|
+
val = String(await state.element.innerHTML());
|
|
2600
|
+
break;
|
|
2601
|
+
case "outerHTML":
|
|
2602
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2603
|
+
break;
|
|
2604
|
+
default:
|
|
2605
|
+
if (property.startsWith("dataset.")) {
|
|
2606
|
+
const dataAttribute = property.substring(8);
|
|
2607
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2608
|
+
}
|
|
2609
|
+
else {
|
|
2610
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
// Helper function to remove all style="" attributes
|
|
2614
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2615
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2616
|
+
};
|
|
2617
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2618
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2619
|
+
val = removeStyleAttributes(val);
|
|
2620
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2621
|
+
}
|
|
2622
|
+
state.info.value = val;
|
|
2623
|
+
let regex;
|
|
2624
|
+
state.info.value = val;
|
|
2625
|
+
const isRegex = expectedValue.startsWith("regex:");
|
|
2626
|
+
const isContains = expectedValue.startsWith("contains:");
|
|
2627
|
+
const isExact = expectedValue.startsWith("exact:");
|
|
2628
|
+
let matchPassed = false;
|
|
2629
|
+
if (isRegex) {
|
|
2630
|
+
const rawPattern = expectedValue.slice(6); // remove "regex:"
|
|
2631
|
+
const lastSlashIndex = rawPattern.lastIndexOf("/");
|
|
2632
|
+
if (rawPattern.startsWith("/") && lastSlashIndex > 0) {
|
|
2633
|
+
const patternBody = rawPattern.slice(1, lastSlashIndex).replace(/\n/g, ".*");
|
|
2634
|
+
const flags = rawPattern.slice(lastSlashIndex + 1) || "gs";
|
|
2635
|
+
const regex = new RegExp(patternBody, flags);
|
|
2636
|
+
state.info.regex = true;
|
|
2637
|
+
matchPassed = regex.test(val);
|
|
2638
|
+
}
|
|
2639
|
+
else {
|
|
2640
|
+
// Fallback: treat as literal
|
|
2641
|
+
const escapedPattern = rawPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2642
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2643
|
+
matchPassed = regex.test(val);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
else if (isContains) {
|
|
2647
|
+
const containsValue = expectedValue.slice(9); // remove "contains:"
|
|
2648
|
+
matchPassed = val.includes(containsValue);
|
|
2649
|
+
}
|
|
2650
|
+
else if (isExact) {
|
|
2651
|
+
const exactValue = expectedValue.slice(6); // remove "exact:"
|
|
2652
|
+
matchPassed = val === exactValue;
|
|
2653
|
+
}
|
|
2654
|
+
else if (property === "innerText") {
|
|
2655
|
+
// Default innerText logic
|
|
2656
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2657
|
+
const valLines = val.split("\n");
|
|
2658
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2659
|
+
matchPassed = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2660
|
+
}
|
|
2661
|
+
else {
|
|
2662
|
+
// Fallback exact or loose match
|
|
2663
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2664
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2665
|
+
matchPassed = regex.test(val);
|
|
2666
|
+
}
|
|
2667
|
+
if (!matchPassed) {
|
|
2668
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2669
|
+
state.info.failCause.assertionFailed = true;
|
|
2670
|
+
state.info.failCause.lastError = errorMessage;
|
|
2671
|
+
throw new Error(errorMessage);
|
|
2672
|
+
}
|
|
2673
|
+
return state.info;
|
|
2674
|
+
}
|
|
2675
|
+
catch (e) {
|
|
2676
|
+
await _commandError(state, e, this);
|
|
2677
|
+
}
|
|
2678
|
+
finally {
|
|
2679
|
+
await _commandFinally(state, this);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2683
|
+
// Convert timeout from seconds to milliseconds
|
|
2684
|
+
const timeoutMs = timeout * 1000;
|
|
2685
|
+
const state = {
|
|
2686
|
+
selectors,
|
|
2687
|
+
_params,
|
|
2688
|
+
condition,
|
|
2689
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2690
|
+
options,
|
|
2691
|
+
world,
|
|
2692
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2693
|
+
highlight: true,
|
|
2694
|
+
screenshot: true,
|
|
2695
|
+
text: `Conditional wait for element`,
|
|
2696
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2697
|
+
operation: "conditionalWait",
|
|
2698
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2699
|
+
allowDisabled: true,
|
|
2700
|
+
info: {},
|
|
2701
|
+
};
|
|
2702
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2703
|
+
const startTime = Date.now();
|
|
2704
|
+
let conditionMet = false;
|
|
2705
|
+
let currentValue = null;
|
|
2706
|
+
let lastError = null;
|
|
2707
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2708
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2709
|
+
const elapsedTime = Date.now() - startTime;
|
|
2710
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2711
|
+
try {
|
|
2712
|
+
// Try to execute _preCommand (element location)
|
|
2713
|
+
await _preCommand(state, this);
|
|
2714
|
+
// If _preCommand succeeds, start condition checking
|
|
2715
|
+
const checkCondition = async () => {
|
|
2716
|
+
try {
|
|
2717
|
+
switch (condition.toLowerCase()) {
|
|
2718
|
+
case "checked":
|
|
2719
|
+
currentValue = await state.element.isChecked();
|
|
2720
|
+
return currentValue === true;
|
|
2721
|
+
case "unchecked":
|
|
2722
|
+
currentValue = await state.element.isChecked();
|
|
2723
|
+
return currentValue === false;
|
|
2724
|
+
case "visible":
|
|
2725
|
+
currentValue = await state.element.isVisible();
|
|
2726
|
+
return currentValue === true;
|
|
2727
|
+
case "hidden":
|
|
2728
|
+
currentValue = await state.element.isVisible();
|
|
2729
|
+
return currentValue === false;
|
|
2730
|
+
case "enabled":
|
|
2731
|
+
currentValue = await state.element.isDisabled();
|
|
2732
|
+
return currentValue === false;
|
|
2733
|
+
case "disabled":
|
|
2734
|
+
currentValue = await state.element.isDisabled();
|
|
2735
|
+
return currentValue === true;
|
|
2736
|
+
case "editable":
|
|
2737
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2738
|
+
currentValue = await state.element.isContentEditable();
|
|
2739
|
+
return currentValue === true;
|
|
2740
|
+
default:
|
|
2741
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2742
|
+
state.info.success = false;
|
|
2743
|
+
return false;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
catch (error) {
|
|
2747
|
+
// Don't throw here, just return false to continue retrying
|
|
2748
|
+
return false;
|
|
2749
|
+
}
|
|
2750
|
+
};
|
|
2751
|
+
// Inner loop for condition checking (once element is located)
|
|
2752
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2753
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2754
|
+
conditionMet = await checkCondition();
|
|
2755
|
+
if (conditionMet) {
|
|
2756
|
+
break;
|
|
2757
|
+
}
|
|
2758
|
+
// Check if we still have time for another attempt
|
|
2759
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2760
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2761
|
+
}
|
|
2762
|
+
else {
|
|
2763
|
+
break;
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
// If we got here and condition is met, break out of main loop
|
|
2767
|
+
if (conditionMet) {
|
|
2768
|
+
break;
|
|
2769
|
+
}
|
|
2770
|
+
// If condition not met but no exception, we've timed out
|
|
2771
|
+
break;
|
|
2772
|
+
}
|
|
2773
|
+
catch (e) {
|
|
2774
|
+
lastError = e;
|
|
2775
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2776
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2777
|
+
// Check if we have enough time left to retry
|
|
2778
|
+
if (timeLeft > 100) {
|
|
2779
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2780
|
+
}
|
|
2781
|
+
else {
|
|
2782
|
+
break;
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2787
|
+
state.info = {
|
|
2788
|
+
success: conditionMet,
|
|
2789
|
+
conditionMet,
|
|
2790
|
+
actualWaitTime,
|
|
2791
|
+
currentValue,
|
|
2792
|
+
lastError: lastError?.message || null,
|
|
2793
|
+
message: conditionMet
|
|
2794
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2795
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2796
|
+
};
|
|
2797
|
+
if (lastError) {
|
|
2798
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2799
|
+
}
|
|
2800
|
+
try {
|
|
2801
|
+
await _commandFinally(state, this);
|
|
2802
|
+
}
|
|
2803
|
+
catch (finallyError) {
|
|
2804
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2805
|
+
}
|
|
2806
|
+
return state.info;
|
|
2807
|
+
}
|
|
2229
2808
|
async extractEmailData(emailAddress, options, world) {
|
|
2230
2809
|
if (!emailAddress) {
|
|
2231
2810
|
throw new Error("email address is null");
|
|
@@ -2383,56 +2962,49 @@ class StableBrowser {
|
|
|
2383
2962
|
console.debug(error);
|
|
2384
2963
|
}
|
|
2385
2964
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
// });
|
|
2429
|
-
// }
|
|
2430
|
-
// } catch (error) {
|
|
2431
|
-
// // console.debug(error);
|
|
2432
|
-
// }
|
|
2433
|
-
// }
|
|
2965
|
+
_matcher(text) {
|
|
2966
|
+
if (!text) {
|
|
2967
|
+
return { matcher: "contains", queryText: "" };
|
|
2968
|
+
}
|
|
2969
|
+
if (text.length < 2) {
|
|
2970
|
+
return { matcher: "contains", queryText: text };
|
|
2971
|
+
}
|
|
2972
|
+
const split = text.split(":");
|
|
2973
|
+
const matcher = split[0].toLowerCase();
|
|
2974
|
+
const queryText = split.slice(1).join(":").trim();
|
|
2975
|
+
return { matcher, queryText };
|
|
2976
|
+
}
|
|
2977
|
+
_getDomain(url) {
|
|
2978
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
2979
|
+
return "";
|
|
2980
|
+
}
|
|
2981
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
2982
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
2983
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
2984
|
+
}
|
|
2985
|
+
let n = hostnameFragments.length;
|
|
2986
|
+
let fragments = [...hostnameFragments];
|
|
2987
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
2988
|
+
hostnameFragments.pop();
|
|
2989
|
+
n = hostnameFragments.length;
|
|
2990
|
+
}
|
|
2991
|
+
if (n == 0) {
|
|
2992
|
+
if (fragments[0] === "www")
|
|
2993
|
+
fragments = fragments.slice(1);
|
|
2994
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
2995
|
+
}
|
|
2996
|
+
if (hostnameFragments[0] === "www")
|
|
2997
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
2998
|
+
return hostnameFragments.join(".");
|
|
2999
|
+
}
|
|
3000
|
+
/**
|
|
3001
|
+
* Verify the page path matches the given path.
|
|
3002
|
+
* @param {string} pathPart - The path to verify.
|
|
3003
|
+
* @param {object} options - Options for verification.
|
|
3004
|
+
* @param {object} world - The world context.
|
|
3005
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
3006
|
+
*/
|
|
2434
3007
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2435
|
-
const startTime = Date.now();
|
|
2436
3008
|
let error = null;
|
|
2437
3009
|
let screenshotId = null;
|
|
2438
3010
|
let screenshotPath = null;
|
|
@@ -2446,113 +3018,212 @@ class StableBrowser {
|
|
|
2446
3018
|
pathPart = newValue;
|
|
2447
3019
|
}
|
|
2448
3020
|
info.pathPart = pathPart;
|
|
3021
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
3022
|
+
const state = {
|
|
3023
|
+
text_search: queryText,
|
|
3024
|
+
options,
|
|
3025
|
+
world,
|
|
3026
|
+
locate: false,
|
|
3027
|
+
scroll: false,
|
|
3028
|
+
highlight: false,
|
|
3029
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
3030
|
+
text: `Verify the page url is ${queryText}`,
|
|
3031
|
+
_text: `Verify the page url is ${queryText}`,
|
|
3032
|
+
operation: "verifyPagePath",
|
|
3033
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
3034
|
+
};
|
|
2449
3035
|
try {
|
|
3036
|
+
await _preCommand(state, this);
|
|
3037
|
+
state.info.text = queryText;
|
|
2450
3038
|
for (let i = 0; i < 30; i++) {
|
|
2451
3039
|
const url = await this.page.url();
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
3040
|
+
switch (matcher) {
|
|
3041
|
+
case "exact":
|
|
3042
|
+
if (url !== queryText) {
|
|
3043
|
+
if (i === 29) {
|
|
3044
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
3045
|
+
}
|
|
3046
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
break;
|
|
3050
|
+
case "contains":
|
|
3051
|
+
if (!url.includes(queryText)) {
|
|
3052
|
+
if (i === 29) {
|
|
3053
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
3054
|
+
}
|
|
3055
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3056
|
+
continue;
|
|
3057
|
+
}
|
|
3058
|
+
break;
|
|
3059
|
+
case "starts-with":
|
|
3060
|
+
{
|
|
3061
|
+
const domain = this._getDomain(url);
|
|
3062
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
3063
|
+
if (i === 29) {
|
|
3064
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
3065
|
+
}
|
|
3066
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3067
|
+
continue;
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
break;
|
|
3071
|
+
case "ends-with":
|
|
3072
|
+
{
|
|
3073
|
+
const urlObj = new URL(url);
|
|
3074
|
+
let route = "/";
|
|
3075
|
+
if (urlObj.pathname !== "/") {
|
|
3076
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
3077
|
+
}
|
|
3078
|
+
else {
|
|
3079
|
+
route = "/";
|
|
3080
|
+
}
|
|
3081
|
+
if (route !== queryText) {
|
|
3082
|
+
if (i === 29) {
|
|
3083
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
3084
|
+
}
|
|
3085
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3086
|
+
continue;
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
break;
|
|
3090
|
+
case "regex":
|
|
3091
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3092
|
+
if (!regex.test(url)) {
|
|
3093
|
+
if (i === 29) {
|
|
3094
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
3095
|
+
}
|
|
3096
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3097
|
+
continue;
|
|
3098
|
+
}
|
|
3099
|
+
break;
|
|
3100
|
+
default:
|
|
3101
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3102
|
+
if (!url.includes(pathPart)) {
|
|
3103
|
+
if (i === 29) {
|
|
3104
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
3105
|
+
}
|
|
3106
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3107
|
+
continue;
|
|
3108
|
+
}
|
|
2458
3109
|
}
|
|
2459
|
-
|
|
2460
|
-
return info;
|
|
3110
|
+
await _screenshot(state, this);
|
|
3111
|
+
return state.info;
|
|
2461
3112
|
}
|
|
2462
3113
|
}
|
|
2463
3114
|
catch (e) {
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
info.screenshotPath = screenshotPath;
|
|
2468
|
-
Object.assign(e, { info: info });
|
|
2469
|
-
error = e;
|
|
2470
|
-
// throw e;
|
|
2471
|
-
await _commandError({ text: "verifyPagePath", operation: "verifyPagePath", pathPart, info, throwError: true }, e, this);
|
|
3115
|
+
state.info.failCause.lastError = e.message;
|
|
3116
|
+
state.info.failCause.assertionFailed = true;
|
|
3117
|
+
await _commandError(state, e, this);
|
|
2472
3118
|
}
|
|
2473
3119
|
finally {
|
|
2474
|
-
|
|
2475
|
-
_reportToWorld(world, {
|
|
2476
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2477
|
-
text: "Verify page path",
|
|
2478
|
-
_text: "Verify the page path contains " + pathPart,
|
|
2479
|
-
screenshotId,
|
|
2480
|
-
result: error
|
|
2481
|
-
? {
|
|
2482
|
-
status: "FAILED",
|
|
2483
|
-
startTime,
|
|
2484
|
-
endTime,
|
|
2485
|
-
message: error?.message,
|
|
2486
|
-
}
|
|
2487
|
-
: {
|
|
2488
|
-
status: "PASSED",
|
|
2489
|
-
startTime,
|
|
2490
|
-
endTime,
|
|
2491
|
-
},
|
|
2492
|
-
info: info,
|
|
2493
|
-
});
|
|
3120
|
+
await _commandFinally(state, this);
|
|
2494
3121
|
}
|
|
2495
3122
|
}
|
|
3123
|
+
/**
|
|
3124
|
+
* Verify the page title matches the given title.
|
|
3125
|
+
* @param {string} title - The title to verify.
|
|
3126
|
+
* @param {object} options - Options for verification.
|
|
3127
|
+
* @param {object} world - The world context.
|
|
3128
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
3129
|
+
*/
|
|
2496
3130
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2497
|
-
const startTime = Date.now();
|
|
2498
3131
|
let error = null;
|
|
2499
3132
|
let screenshotId = null;
|
|
2500
3133
|
let screenshotPath = null;
|
|
2501
3134
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2502
|
-
const info = {};
|
|
2503
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2504
|
-
info.operation = "verifyPageTitle";
|
|
2505
3135
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2506
3136
|
if (newValue !== title) {
|
|
2507
3137
|
this.logger.info(title + "=" + newValue);
|
|
2508
3138
|
title = newValue;
|
|
2509
3139
|
}
|
|
2510
|
-
|
|
3140
|
+
const { matcher, queryText } = this._matcher(title);
|
|
3141
|
+
const state = {
|
|
3142
|
+
text_search: queryText,
|
|
3143
|
+
options,
|
|
3144
|
+
world,
|
|
3145
|
+
locate: false,
|
|
3146
|
+
scroll: false,
|
|
3147
|
+
highlight: false,
|
|
3148
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
3149
|
+
text: `Verify the page title is ${queryText}`,
|
|
3150
|
+
_text: `Verify the page title is ${queryText}`,
|
|
3151
|
+
operation: "verifyPageTitle",
|
|
3152
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
3153
|
+
};
|
|
2511
3154
|
try {
|
|
3155
|
+
await _preCommand(state, this);
|
|
3156
|
+
state.info.text = queryText;
|
|
2512
3157
|
for (let i = 0; i < 30; i++) {
|
|
2513
3158
|
const foundTitle = await this.page.title();
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
3159
|
+
switch (matcher) {
|
|
3160
|
+
case "exact":
|
|
3161
|
+
if (foundTitle !== queryText) {
|
|
3162
|
+
if (i === 29) {
|
|
3163
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
3164
|
+
}
|
|
3165
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3166
|
+
continue;
|
|
3167
|
+
}
|
|
3168
|
+
break;
|
|
3169
|
+
case "contains":
|
|
3170
|
+
if (!foundTitle.includes(queryText)) {
|
|
3171
|
+
if (i === 29) {
|
|
3172
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
3173
|
+
}
|
|
3174
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3175
|
+
continue;
|
|
3176
|
+
}
|
|
3177
|
+
break;
|
|
3178
|
+
case "starts-with":
|
|
3179
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3180
|
+
if (i === 29) {
|
|
3181
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3182
|
+
}
|
|
3183
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3184
|
+
continue;
|
|
3185
|
+
}
|
|
3186
|
+
break;
|
|
3187
|
+
case "ends-with":
|
|
3188
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3189
|
+
if (i === 29) {
|
|
3190
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3191
|
+
}
|
|
3192
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3193
|
+
continue;
|
|
3194
|
+
}
|
|
3195
|
+
break;
|
|
3196
|
+
case "regex":
|
|
3197
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3198
|
+
if (!regex.test(foundTitle)) {
|
|
3199
|
+
if (i === 29) {
|
|
3200
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3201
|
+
}
|
|
3202
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3203
|
+
continue;
|
|
3204
|
+
}
|
|
3205
|
+
break;
|
|
3206
|
+
default:
|
|
3207
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3208
|
+
if (!foundTitle.includes(title)) {
|
|
3209
|
+
if (i === 29) {
|
|
3210
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3211
|
+
}
|
|
3212
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3213
|
+
continue;
|
|
3214
|
+
}
|
|
2520
3215
|
}
|
|
2521
|
-
|
|
2522
|
-
return info;
|
|
3216
|
+
await _screenshot(state, this);
|
|
3217
|
+
return state.info;
|
|
2523
3218
|
}
|
|
2524
3219
|
}
|
|
2525
3220
|
catch (e) {
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
info.screenshotPath = screenshotPath;
|
|
2530
|
-
Object.assign(e, { info: info });
|
|
2531
|
-
error = e;
|
|
2532
|
-
// throw e;
|
|
2533
|
-
await _commandError({ text: "verifyPageTitle", operation: "verifyPageTitle", title, info, throwError: true }, e, this);
|
|
3221
|
+
state.info.failCause.lastError = e.message;
|
|
3222
|
+
state.info.failCause.assertionFailed = true;
|
|
3223
|
+
await _commandError(state, e, this);
|
|
2534
3224
|
}
|
|
2535
3225
|
finally {
|
|
2536
|
-
|
|
2537
|
-
_reportToWorld(world, {
|
|
2538
|
-
type: Types.VERIFY_PAGE_PATH,
|
|
2539
|
-
text: "Verify page title",
|
|
2540
|
-
_text: "Verify the page title contains " + title,
|
|
2541
|
-
screenshotId,
|
|
2542
|
-
result: error
|
|
2543
|
-
? {
|
|
2544
|
-
status: "FAILED",
|
|
2545
|
-
startTime,
|
|
2546
|
-
endTime,
|
|
2547
|
-
message: error?.message,
|
|
2548
|
-
}
|
|
2549
|
-
: {
|
|
2550
|
-
status: "PASSED",
|
|
2551
|
-
startTime,
|
|
2552
|
-
endTime,
|
|
2553
|
-
},
|
|
2554
|
-
info: info,
|
|
2555
|
-
});
|
|
3226
|
+
await _commandFinally(state, this);
|
|
2556
3227
|
}
|
|
2557
3228
|
}
|
|
2558
3229
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2636,27 +3307,10 @@ class StableBrowser {
|
|
|
2636
3307
|
const frame = resultWithElementsFound[0].frame;
|
|
2637
3308
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2638
3309
|
await this._highlightElements(frame, dataAttribute);
|
|
2639
|
-
// if (world && world.screenshot && !world.screenshotPath) {
|
|
2640
|
-
// console.log(`Highlighting for verify text is found while running from recorder`);
|
|
2641
|
-
// this._highlightElements(frame, dataAttribute).then(async () => {
|
|
2642
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2643
|
-
// this._unhighlightElements(frame, dataAttribute)
|
|
2644
|
-
// .then(async () => {
|
|
2645
|
-
// console.log(`Unhighlighted frame dataAttribute successfully`);
|
|
2646
|
-
// })
|
|
2647
|
-
// .catch(
|
|
2648
|
-
// (e) => {}
|
|
2649
|
-
// console.error(e)
|
|
2650
|
-
// );
|
|
2651
|
-
// });
|
|
2652
|
-
// }
|
|
2653
3310
|
const element = await frame.locator(dataAttribute).first();
|
|
2654
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2655
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2656
3311
|
if (element) {
|
|
2657
3312
|
await this.scrollIfNeeded(element, state.info);
|
|
2658
3313
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2659
|
-
// await _screenshot(state, this, element);
|
|
2660
3314
|
}
|
|
2661
3315
|
}
|
|
2662
3316
|
await _screenshot(state, this);
|
|
@@ -2666,7 +3320,6 @@ class StableBrowser {
|
|
|
2666
3320
|
console.error(error);
|
|
2667
3321
|
}
|
|
2668
3322
|
}
|
|
2669
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2670
3323
|
}
|
|
2671
3324
|
catch (e) {
|
|
2672
3325
|
await _commandError(state, e, this);
|
|
@@ -2748,6 +3401,8 @@ class StableBrowser {
|
|
|
2748
3401
|
operation: "verify_text_with_relation",
|
|
2749
3402
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2750
3403
|
};
|
|
3404
|
+
const cmdStartTime = Date.now();
|
|
3405
|
+
let cmdEndTime = null;
|
|
2751
3406
|
const timeout = this._getFindElementTimeout(options);
|
|
2752
3407
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2753
3408
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2783,6 +3438,17 @@ class StableBrowser {
|
|
|
2783
3438
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2784
3439
|
continue;
|
|
2785
3440
|
}
|
|
3441
|
+
else {
|
|
3442
|
+
cmdEndTime = Date.now();
|
|
3443
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3444
|
+
if (foundAncore) {
|
|
3445
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3446
|
+
}
|
|
3447
|
+
else {
|
|
3448
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
2786
3452
|
try {
|
|
2787
3453
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2788
3454
|
foundAncore = true;
|
|
@@ -3182,6 +3848,43 @@ class StableBrowser {
|
|
|
3182
3848
|
});
|
|
3183
3849
|
}
|
|
3184
3850
|
}
|
|
3851
|
+
/**
|
|
3852
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3853
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3854
|
+
* @param options - Optional configuration object
|
|
3855
|
+
* @param world - Optional world context
|
|
3856
|
+
* @returns Promise that resolves after the specified duration
|
|
3857
|
+
*/
|
|
3858
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3859
|
+
const state = {
|
|
3860
|
+
duration,
|
|
3861
|
+
options,
|
|
3862
|
+
world,
|
|
3863
|
+
locate: false,
|
|
3864
|
+
scroll: false,
|
|
3865
|
+
screenshot: false,
|
|
3866
|
+
highlight: false,
|
|
3867
|
+
type: Types.SLEEP,
|
|
3868
|
+
text: `Sleep for ${duration} ms`,
|
|
3869
|
+
_text: `Sleep for ${duration} ms`,
|
|
3870
|
+
operation: "sleep",
|
|
3871
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3872
|
+
};
|
|
3873
|
+
try {
|
|
3874
|
+
await _preCommand(state, this);
|
|
3875
|
+
if (duration < 0) {
|
|
3876
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3877
|
+
}
|
|
3878
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3879
|
+
return state.info;
|
|
3880
|
+
}
|
|
3881
|
+
catch (e) {
|
|
3882
|
+
await _commandError(state, e, this);
|
|
3883
|
+
}
|
|
3884
|
+
finally {
|
|
3885
|
+
await _commandFinally(state, this);
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3185
3888
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3186
3889
|
try {
|
|
3187
3890
|
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
@@ -3212,6 +3915,7 @@ class StableBrowser {
|
|
|
3212
3915
|
}
|
|
3213
3916
|
async saveStoreState(path = null, world = null) {
|
|
3214
3917
|
const storageState = await this.page.context().storageState();
|
|
3918
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3215
3919
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3216
3920
|
if (path) {
|
|
3217
3921
|
// save { storageState: storageState } into the path
|
|
@@ -3222,6 +3926,7 @@ class StableBrowser {
|
|
|
3222
3926
|
}
|
|
3223
3927
|
}
|
|
3224
3928
|
async restoreSaveState(path = null, world = null) {
|
|
3929
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3225
3930
|
await refreshBrowser(this, path, world);
|
|
3226
3931
|
this.registerEventListeners(this.context);
|
|
3227
3932
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
@@ -3231,6 +3936,22 @@ class StableBrowser {
|
|
|
3231
3936
|
}
|
|
3232
3937
|
}
|
|
3233
3938
|
async waitForPageLoad(options = {}, world = null) {
|
|
3939
|
+
// try {
|
|
3940
|
+
// let currentPagePath = null;
|
|
3941
|
+
// currentPagePath = new URL(this.page.url()).pathname;
|
|
3942
|
+
// if (this.latestPagePath) {
|
|
3943
|
+
// // get the currect page path and compare with the latest page path
|
|
3944
|
+
// if (this.latestPagePath === currentPagePath) {
|
|
3945
|
+
// // if the page path is the same, do not wait for page load
|
|
3946
|
+
// console.log("No page change: " + currentPagePath);
|
|
3947
|
+
// return;
|
|
3948
|
+
// }
|
|
3949
|
+
// }
|
|
3950
|
+
// this.latestPagePath = currentPagePath;
|
|
3951
|
+
// } catch (e) {
|
|
3952
|
+
// console.debug("Error getting current page path: ", e);
|
|
3953
|
+
// }
|
|
3954
|
+
//console.log("Waiting for page load");
|
|
3234
3955
|
let timeout = this._getLoadTimeout(options);
|
|
3235
3956
|
const promiseArray = [];
|
|
3236
3957
|
// let waitForNetworkIdle = true;
|
|
@@ -3263,10 +3984,12 @@ class StableBrowser {
|
|
|
3263
3984
|
else if (e.label === "domcontentloaded") {
|
|
3264
3985
|
console.log("waited for the domcontent loaded timeout");
|
|
3265
3986
|
}
|
|
3266
|
-
console.log(".");
|
|
3267
3987
|
}
|
|
3268
3988
|
finally {
|
|
3269
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3989
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
3990
|
+
if (options && !options.noSleep) {
|
|
3991
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
3992
|
+
}
|
|
3270
3993
|
({ screenshotId, screenshotPath } = await this._screenShot(options, world));
|
|
3271
3994
|
const endTime = Date.now();
|
|
3272
3995
|
_reportToWorld(world, {
|
|
@@ -3307,7 +4030,6 @@ class StableBrowser {
|
|
|
3307
4030
|
await this.page.close();
|
|
3308
4031
|
}
|
|
3309
4032
|
catch (e) {
|
|
3310
|
-
console.log(".");
|
|
3311
4033
|
await _commandError(state, e, this);
|
|
3312
4034
|
}
|
|
3313
4035
|
finally {
|
|
@@ -3422,7 +4144,6 @@ class StableBrowser {
|
|
|
3422
4144
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3423
4145
|
}
|
|
3424
4146
|
catch (e) {
|
|
3425
|
-
console.log(".");
|
|
3426
4147
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3427
4148
|
}
|
|
3428
4149
|
finally {
|
|
@@ -3460,7 +4181,6 @@ class StableBrowser {
|
|
|
3460
4181
|
await this.page.reload();
|
|
3461
4182
|
}
|
|
3462
4183
|
catch (e) {
|
|
3463
|
-
console.log(".");
|
|
3464
4184
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3465
4185
|
}
|
|
3466
4186
|
finally {
|
|
@@ -3504,6 +4224,10 @@ class StableBrowser {
|
|
|
3504
4224
|
}
|
|
3505
4225
|
}
|
|
3506
4226
|
async beforeScenario(world, scenario) {
|
|
4227
|
+
if (world && world.attach) {
|
|
4228
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4229
|
+
}
|
|
4230
|
+
this.context.loadedRoutes = null;
|
|
3507
4231
|
this.beforeScenarioCalled = true;
|
|
3508
4232
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
3509
4233
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -3527,14 +4251,18 @@ class StableBrowser {
|
|
|
3527
4251
|
envName = this.context.environment.name;
|
|
3528
4252
|
}
|
|
3529
4253
|
if (!process.env.TEMP_RUN) {
|
|
3530
|
-
await getTestData(envName, world, undefined, this.featureName, this.scenarioName);
|
|
4254
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
3531
4255
|
}
|
|
3532
4256
|
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3533
4257
|
}
|
|
3534
4258
|
async afterScenario(world, scenario) { }
|
|
3535
4259
|
async beforeStep(world, step) {
|
|
4260
|
+
if (this.abortedExecution) {
|
|
4261
|
+
throw new Error("Aborted");
|
|
4262
|
+
}
|
|
3536
4263
|
if (!this.beforeScenarioCalled) {
|
|
3537
4264
|
this.beforeScenario(world, step);
|
|
4265
|
+
this.context.loadedRoutes = null;
|
|
3538
4266
|
}
|
|
3539
4267
|
if (this.stepIndex === undefined) {
|
|
3540
4268
|
this.stepIndex = 0;
|
|
@@ -3559,13 +4287,16 @@ class StableBrowser {
|
|
|
3559
4287
|
}
|
|
3560
4288
|
if (this.initSnapshotTaken === false) {
|
|
3561
4289
|
this.initSnapshotTaken = true;
|
|
3562
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4290
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3563
4291
|
const snapshot = await this.getAriaSnapshot();
|
|
3564
4292
|
if (snapshot) {
|
|
3565
4293
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3566
4294
|
}
|
|
3567
4295
|
}
|
|
3568
4296
|
}
|
|
4297
|
+
this.context.routeResults = null;
|
|
4298
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4299
|
+
networkBeforeStep(this.stepName);
|
|
3569
4300
|
}
|
|
3570
4301
|
async getAriaSnapshot() {
|
|
3571
4302
|
try {
|
|
@@ -3585,12 +4316,18 @@ class StableBrowser {
|
|
|
3585
4316
|
try {
|
|
3586
4317
|
// Ensure frame is attached and has body
|
|
3587
4318
|
const body = frame.locator("body");
|
|
3588
|
-
await body.waitFor({ timeout }); // wait explicitly
|
|
4319
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
3589
4320
|
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4321
|
+
if (!snapshot) {
|
|
4322
|
+
continue;
|
|
4323
|
+
}
|
|
3590
4324
|
content.push(`- frame: ${i}`);
|
|
3591
4325
|
content.push(snapshot);
|
|
3592
4326
|
}
|
|
3593
|
-
catch (innerErr) {
|
|
4327
|
+
catch (innerErr) {
|
|
4328
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4329
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4330
|
+
}
|
|
3594
4331
|
}
|
|
3595
4332
|
return content.join("\n");
|
|
3596
4333
|
}
|
|
@@ -3600,6 +4337,49 @@ class StableBrowser {
|
|
|
3600
4337
|
}
|
|
3601
4338
|
return null;
|
|
3602
4339
|
}
|
|
4340
|
+
/**
|
|
4341
|
+
* Sends command with custom payload to report.
|
|
4342
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4343
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4344
|
+
* @param content - Content of the command to be shown in the report.
|
|
4345
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4346
|
+
* @param world - Optional world context.
|
|
4347
|
+
* @public
|
|
4348
|
+
*/
|
|
4349
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4350
|
+
const state = {
|
|
4351
|
+
options,
|
|
4352
|
+
world,
|
|
4353
|
+
locate: false,
|
|
4354
|
+
scroll: false,
|
|
4355
|
+
screenshot: options.screenshot ?? false,
|
|
4356
|
+
highlight: options.highlight ?? false,
|
|
4357
|
+
type: Types.REPORT_COMMAND,
|
|
4358
|
+
text: commandText,
|
|
4359
|
+
_text: commandText,
|
|
4360
|
+
operation: "report_command",
|
|
4361
|
+
log: "***** " + commandText + " *****\n",
|
|
4362
|
+
};
|
|
4363
|
+
try {
|
|
4364
|
+
await _preCommand(state, this);
|
|
4365
|
+
const payload = {
|
|
4366
|
+
type: options.type ?? "text",
|
|
4367
|
+
content: content,
|
|
4368
|
+
screenshotId: null,
|
|
4369
|
+
};
|
|
4370
|
+
state.payload = payload;
|
|
4371
|
+
if (commandStatus === "FAILED") {
|
|
4372
|
+
state.throwError = true;
|
|
4373
|
+
throw new Error("Command failed");
|
|
4374
|
+
}
|
|
4375
|
+
}
|
|
4376
|
+
catch (e) {
|
|
4377
|
+
await _commandError(state, e, this);
|
|
4378
|
+
}
|
|
4379
|
+
finally {
|
|
4380
|
+
await _commandFinally(state, this);
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
3603
4383
|
async afterStep(world, step) {
|
|
3604
4384
|
this.stepName = null;
|
|
3605
4385
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3619,13 +4399,43 @@ class StableBrowser {
|
|
|
3619
4399
|
if (this.context) {
|
|
3620
4400
|
this.context.examplesRow = null;
|
|
3621
4401
|
}
|
|
3622
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4402
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3623
4403
|
const snapshot = await this.getAriaSnapshot();
|
|
3624
4404
|
if (snapshot) {
|
|
3625
4405
|
const obj = {};
|
|
3626
4406
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3627
4407
|
}
|
|
3628
4408
|
}
|
|
4409
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4410
|
+
if (this.context.routeResults) {
|
|
4411
|
+
if (world && world.attach) {
|
|
4412
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4413
|
+
}
|
|
4414
|
+
}
|
|
4415
|
+
if (!process.env.TEMP_RUN) {
|
|
4416
|
+
const state = {
|
|
4417
|
+
world,
|
|
4418
|
+
locate: false,
|
|
4419
|
+
scroll: false,
|
|
4420
|
+
screenshot: true,
|
|
4421
|
+
highlight: true,
|
|
4422
|
+
type: Types.STEP_COMPLETE,
|
|
4423
|
+
text: "end of scenario",
|
|
4424
|
+
_text: "end of scenario",
|
|
4425
|
+
operation: "step_complete",
|
|
4426
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4427
|
+
};
|
|
4428
|
+
try {
|
|
4429
|
+
await _preCommand(state, this);
|
|
4430
|
+
}
|
|
4431
|
+
catch (e) {
|
|
4432
|
+
await _commandError(state, e, this);
|
|
4433
|
+
}
|
|
4434
|
+
finally {
|
|
4435
|
+
await _commandFinally(state, this);
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
networkAfterStep(this.stepName);
|
|
3629
4439
|
}
|
|
3630
4440
|
}
|
|
3631
4441
|
function createTimedPromise(promise, label) {
|