automation_model 1.0.715-dev → 1.0.715-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 +141 -85
- 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.js +22 -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 +521 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +3 -3
- package/lib/snapshot_validation.js +149 -38
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +61 -26
- package/lib/stable_browser.js +1068 -212
- 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 +91 -62
- package/lib/utils.js.map +1 -1
- package/package.json +15 -9
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,14 @@ class StableBrowser {
|
|
|
81
95
|
tags = null;
|
|
82
96
|
isRecording = false;
|
|
83
97
|
initSnapshotTaken = false;
|
|
84
|
-
|
|
98
|
+
onlyFailuresScreenshot = process.env.SCREENSHOT_ON_FAILURE_ONLY === "true";
|
|
99
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false) {
|
|
85
100
|
this.browser = browser;
|
|
86
101
|
this.page = page;
|
|
87
102
|
this.logger = logger;
|
|
88
103
|
this.context = context;
|
|
89
104
|
this.world = world;
|
|
105
|
+
this.fastMode = fastMode;
|
|
90
106
|
if (!this.logger) {
|
|
91
107
|
this.logger = console;
|
|
92
108
|
}
|
|
@@ -115,6 +131,19 @@ class StableBrowser {
|
|
|
115
131
|
context.pages = [this.page];
|
|
116
132
|
const logFolder = path.join(this.project_path, "logs", "web");
|
|
117
133
|
this.world = world;
|
|
134
|
+
if (this.configuration && this.configuration.fastMode === true) {
|
|
135
|
+
this.fastMode = true;
|
|
136
|
+
}
|
|
137
|
+
if (process.env.FAST_MODE === "true") {
|
|
138
|
+
// console.log("Fast mode enabled from environment variable");
|
|
139
|
+
this.fastMode = true;
|
|
140
|
+
}
|
|
141
|
+
if (process.env.FAST_MODE === "false") {
|
|
142
|
+
this.fastMode = false;
|
|
143
|
+
}
|
|
144
|
+
if (this.context) {
|
|
145
|
+
this.context.fastMode = this.fastMode;
|
|
146
|
+
}
|
|
118
147
|
this.registerEventListeners(this.context);
|
|
119
148
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
120
149
|
registerDownloadEvent(this.page, this.world, this.context);
|
|
@@ -125,6 +154,9 @@ class StableBrowser {
|
|
|
125
154
|
if (!context.pageLoading) {
|
|
126
155
|
context.pageLoading = { status: false };
|
|
127
156
|
}
|
|
157
|
+
if (this.configuration && this.configuration.acceptDialog && this.page) {
|
|
158
|
+
this.page.on("dialog", (dialog) => dialog.accept());
|
|
159
|
+
}
|
|
128
160
|
context.playContext.on("page", async function (page) {
|
|
129
161
|
if (this.configuration && this.configuration.closePopups === true) {
|
|
130
162
|
console.log("close unexpected popups");
|
|
@@ -133,11 +165,20 @@ class StableBrowser {
|
|
|
133
165
|
}
|
|
134
166
|
context.pageLoading.status = true;
|
|
135
167
|
this.page = page;
|
|
168
|
+
try {
|
|
169
|
+
if (this.configuration && this.configuration.acceptDialog) {
|
|
170
|
+
await page.on("dialog", (dialog) => dialog.accept());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error("Error on dialog accept registration", error);
|
|
175
|
+
}
|
|
136
176
|
context.page = page;
|
|
137
177
|
context.pages.push(page);
|
|
138
178
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
139
179
|
registerDownloadEvent(this.page, this.world, context);
|
|
140
180
|
page.on("close", async () => {
|
|
181
|
+
// return if browser context is already closed
|
|
141
182
|
if (this.context && this.context.pages && this.context.pages.length > 1) {
|
|
142
183
|
this.context.pages.pop();
|
|
143
184
|
this.page = this.context.pages[this.context.pages.length - 1];
|
|
@@ -147,7 +188,12 @@ class StableBrowser {
|
|
|
147
188
|
console.log("Switched to page " + title);
|
|
148
189
|
}
|
|
149
190
|
catch (error) {
|
|
150
|
-
|
|
191
|
+
if (error?.message?.includes("Target page, context or browser has been closed")) {
|
|
192
|
+
// Ignore this error
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
console.error("Error on page close", error);
|
|
196
|
+
}
|
|
151
197
|
}
|
|
152
198
|
}
|
|
153
199
|
});
|
|
@@ -156,7 +202,12 @@ class StableBrowser {
|
|
|
156
202
|
console.log("Switch page: " + (await page.title()));
|
|
157
203
|
}
|
|
158
204
|
catch (e) {
|
|
159
|
-
|
|
205
|
+
if (e?.message?.includes("Target page, context or browser has been closed")) {
|
|
206
|
+
// Ignore this error
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
this.logger.error("error on page load " + e);
|
|
210
|
+
}
|
|
160
211
|
}
|
|
161
212
|
context.pageLoading.status = false;
|
|
162
213
|
}.bind(this));
|
|
@@ -184,7 +235,9 @@ class StableBrowser {
|
|
|
184
235
|
if (newContextCreated) {
|
|
185
236
|
this.registerEventListeners(this.context);
|
|
186
237
|
await this.goto(this.context.environment.baseUrl);
|
|
187
|
-
|
|
238
|
+
if (!this.fastMode) {
|
|
239
|
+
await this.waitForPageLoad();
|
|
240
|
+
}
|
|
188
241
|
}
|
|
189
242
|
}
|
|
190
243
|
async switchTab(tabTitleOrIndex) {
|
|
@@ -278,6 +331,7 @@ class StableBrowser {
|
|
|
278
331
|
if (!url) {
|
|
279
332
|
throw new Error("url is null, verify that the environment file is correct");
|
|
280
333
|
}
|
|
334
|
+
url = await this._replaceWithLocalData(url, this.world);
|
|
281
335
|
if (!url.startsWith("http")) {
|
|
282
336
|
url = "https://" + url;
|
|
283
337
|
}
|
|
@@ -309,6 +363,64 @@ class StableBrowser {
|
|
|
309
363
|
await _commandFinally(state, this);
|
|
310
364
|
}
|
|
311
365
|
}
|
|
366
|
+
async goBack(options, world = null) {
|
|
367
|
+
const state = {
|
|
368
|
+
value: "",
|
|
369
|
+
world: world,
|
|
370
|
+
type: Types.GO_BACK,
|
|
371
|
+
text: `Browser navigate back`,
|
|
372
|
+
operation: "goBack",
|
|
373
|
+
log: "***** navigate back *****\n",
|
|
374
|
+
info: {},
|
|
375
|
+
locate: false,
|
|
376
|
+
scroll: false,
|
|
377
|
+
screenshot: false,
|
|
378
|
+
highlight: false,
|
|
379
|
+
};
|
|
380
|
+
try {
|
|
381
|
+
await _preCommand(state, this);
|
|
382
|
+
await this.page.goBack({
|
|
383
|
+
waitUntil: "load",
|
|
384
|
+
});
|
|
385
|
+
await _screenshot(state, this);
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
console.error("Error on goBack", error);
|
|
389
|
+
_commandError(state, error, this);
|
|
390
|
+
}
|
|
391
|
+
finally {
|
|
392
|
+
await _commandFinally(state, this);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async goForward(options, world = null) {
|
|
396
|
+
const state = {
|
|
397
|
+
value: "",
|
|
398
|
+
world: world,
|
|
399
|
+
type: Types.GO_FORWARD,
|
|
400
|
+
text: `Browser navigate forward`,
|
|
401
|
+
operation: "goForward",
|
|
402
|
+
log: "***** navigate forward *****\n",
|
|
403
|
+
info: {},
|
|
404
|
+
locate: false,
|
|
405
|
+
scroll: false,
|
|
406
|
+
screenshot: false,
|
|
407
|
+
highlight: false,
|
|
408
|
+
};
|
|
409
|
+
try {
|
|
410
|
+
await _preCommand(state, this);
|
|
411
|
+
await this.page.goForward({
|
|
412
|
+
waitUntil: "load",
|
|
413
|
+
});
|
|
414
|
+
await _screenshot(state, this);
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
console.error("Error on goForward", error);
|
|
418
|
+
_commandError(state, error, this);
|
|
419
|
+
}
|
|
420
|
+
finally {
|
|
421
|
+
await _commandFinally(state, this);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
312
424
|
async _getLocator(locator, scope, _params) {
|
|
313
425
|
locator = _fixLocatorUsingParams(locator, _params);
|
|
314
426
|
// locator = await this._replaceWithLocalData(locator);
|
|
@@ -407,12 +519,6 @@ class StableBrowser {
|
|
|
407
519
|
if (!el.setAttribute) {
|
|
408
520
|
el = el.parentElement;
|
|
409
521
|
}
|
|
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
522
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
417
523
|
return true;
|
|
418
524
|
}, [tag1, randomToken]))) {
|
|
@@ -422,7 +528,7 @@ class StableBrowser {
|
|
|
422
528
|
}
|
|
423
529
|
return { elementCount: tagCount, randomToken };
|
|
424
530
|
}
|
|
425
|
-
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null) {
|
|
531
|
+
async _collectLocatorInformation(selectorHierarchy, index = 0, scope, foundLocators, _params, info, visibleOnly = true, allowDisabled = false, element_name = null, logErrors = false) {
|
|
426
532
|
if (!info) {
|
|
427
533
|
info = {};
|
|
428
534
|
}
|
|
@@ -434,14 +540,13 @@ class StableBrowser {
|
|
|
434
540
|
info.locatorLog = new LocatorLog(selectorHierarchy);
|
|
435
541
|
}
|
|
436
542
|
let locatorSearch = selectorHierarchy[index];
|
|
437
|
-
let originalLocatorSearch = "";
|
|
438
543
|
try {
|
|
439
|
-
|
|
440
|
-
locatorSearch = JSON.parse(originalLocatorSearch);
|
|
544
|
+
locatorSearch = _fixLocatorUsingParams(locatorSearch, _params);
|
|
441
545
|
}
|
|
442
546
|
catch (e) {
|
|
443
547
|
console.error(e);
|
|
444
548
|
}
|
|
549
|
+
let originalLocatorSearch = JSON.stringify(locatorSearch);
|
|
445
550
|
//info.log += "searching for locator " + JSON.stringify(locatorSearch) + "\n";
|
|
446
551
|
let locator = null;
|
|
447
552
|
if (locatorSearch.climb && locatorSearch.climb >= 0) {
|
|
@@ -489,7 +594,7 @@ class StableBrowser {
|
|
|
489
594
|
}
|
|
490
595
|
return;
|
|
491
596
|
}
|
|
492
|
-
if (info.locatorLog && count === 0) {
|
|
597
|
+
if (info.locatorLog && count === 0 && logErrors) {
|
|
493
598
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "NOT_FOUND");
|
|
494
599
|
}
|
|
495
600
|
for (let j = 0; j < count; j++) {
|
|
@@ -504,7 +609,7 @@ class StableBrowser {
|
|
|
504
609
|
info.locatorLog.setLocatorSearchStatus(originalLocatorSearch, "FOUND");
|
|
505
610
|
}
|
|
506
611
|
}
|
|
507
|
-
else {
|
|
612
|
+
else if (logErrors) {
|
|
508
613
|
info.failCause.visible = visible;
|
|
509
614
|
info.failCause.enabled = enabled;
|
|
510
615
|
if (!info.printMessages) {
|
|
@@ -583,34 +688,183 @@ class StableBrowser {
|
|
|
583
688
|
}
|
|
584
689
|
return { rerun: false };
|
|
585
690
|
}
|
|
691
|
+
getFilePath() {
|
|
692
|
+
const stackFrames = errorStackParser.parse(new Error());
|
|
693
|
+
const stackFrame = stackFrames.findLast((frame) => frame.fileName && frame.fileName.endsWith(".mjs"));
|
|
694
|
+
// return stackFrame?.fileName || null;
|
|
695
|
+
const filepath = stackFrame?.fileName;
|
|
696
|
+
if (filepath) {
|
|
697
|
+
let jsonFilePath = filepath.replace(".mjs", ".json");
|
|
698
|
+
if (existsSync(jsonFilePath)) {
|
|
699
|
+
return jsonFilePath;
|
|
700
|
+
}
|
|
701
|
+
const config = this.configuration ?? {};
|
|
702
|
+
if (!config?.locatorsMetadataDir) {
|
|
703
|
+
config.locatorsMetadataDir = "features/step_definitions/locators";
|
|
704
|
+
}
|
|
705
|
+
if (config && config.locatorsMetadataDir) {
|
|
706
|
+
jsonFilePath = path.join(config.locatorsMetadataDir, path.basename(jsonFilePath));
|
|
707
|
+
}
|
|
708
|
+
if (existsSync(jsonFilePath)) {
|
|
709
|
+
return jsonFilePath;
|
|
710
|
+
}
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
getFullElementLocators(selectors, filePath) {
|
|
716
|
+
if (!filePath || !existsSync(filePath)) {
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
719
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
720
|
+
try {
|
|
721
|
+
const allElements = JSON.parse(content);
|
|
722
|
+
const element_key = selectors?.element_key;
|
|
723
|
+
if (element_key && allElements[element_key]) {
|
|
724
|
+
return allElements[element_key];
|
|
725
|
+
}
|
|
726
|
+
for (const elementKey in allElements) {
|
|
727
|
+
const element = allElements[elementKey];
|
|
728
|
+
let foundStrategy = null;
|
|
729
|
+
for (const key in element) {
|
|
730
|
+
if (key === "strategy") {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
const locators = element[key];
|
|
734
|
+
if (!locators || !locators.length) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
for (const locator of locators) {
|
|
738
|
+
delete locator.score;
|
|
739
|
+
}
|
|
740
|
+
if (JSON.stringify(locators) === JSON.stringify(selectors.locators)) {
|
|
741
|
+
foundStrategy = key;
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (foundStrategy) {
|
|
746
|
+
return element;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
catch (error) {
|
|
751
|
+
console.error("Error parsing locators from file: " + filePath, error);
|
|
752
|
+
}
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
586
755
|
async _locate(selectors, info, _params, timeout, allowDisabled = false) {
|
|
587
756
|
if (!timeout) {
|
|
588
757
|
timeout = 30000;
|
|
589
758
|
}
|
|
759
|
+
let element = null;
|
|
760
|
+
let allStrategyLocators = null;
|
|
761
|
+
let selectedStrategy = null;
|
|
762
|
+
if (this.tryAllStrategies) {
|
|
763
|
+
allStrategyLocators = this.getFullElementLocators(selectors, this.getFilePath());
|
|
764
|
+
selectedStrategy = allStrategyLocators?.strategy;
|
|
765
|
+
}
|
|
590
766
|
for (let i = 0; i < 3; i++) {
|
|
591
767
|
info.log += "attempt " + i + ": total locators " + selectors.locators.length + "\n";
|
|
592
768
|
for (let j = 0; j < selectors.locators.length; j++) {
|
|
593
769
|
let selector = selectors.locators[j];
|
|
594
770
|
info.log += "searching for locator " + j + ":" + JSON.stringify(selector) + "\n";
|
|
595
771
|
}
|
|
596
|
-
|
|
772
|
+
if (this.tryAllStrategies && selectedStrategy) {
|
|
773
|
+
const strategyLocators = allStrategyLocators[selectedStrategy];
|
|
774
|
+
let err;
|
|
775
|
+
if (strategyLocators && strategyLocators.length) {
|
|
776
|
+
try {
|
|
777
|
+
selectors.locators = strategyLocators;
|
|
778
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
779
|
+
info.selectedStrategy = selectedStrategy;
|
|
780
|
+
info.log += "element found using strategy " + selectedStrategy + "\n";
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
err = error;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
if (!element) {
|
|
787
|
+
for (const key in allStrategyLocators) {
|
|
788
|
+
if (key === "strategy" || key === selectedStrategy) {
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
const strategyLocators = allStrategyLocators[key];
|
|
792
|
+
if (strategyLocators && strategyLocators.length) {
|
|
793
|
+
try {
|
|
794
|
+
info.log += "using strategy " + key + " with locators " + JSON.stringify(strategyLocators) + "\n";
|
|
795
|
+
selectors.locators = strategyLocators;
|
|
796
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
797
|
+
err = null;
|
|
798
|
+
info.selectedStrategy = key;
|
|
799
|
+
info.log += "element found using strategy " + key + "\n";
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
catch (error) {
|
|
803
|
+
err = error;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (err) {
|
|
809
|
+
throw err;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
814
|
+
}
|
|
597
815
|
if (!element.rerun) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
816
|
+
let newElementSelector = "";
|
|
817
|
+
if (this.configuration && this.configuration.stableLocatorStrategy === "csschain") {
|
|
818
|
+
const cssSelector = await element.evaluate((el) => {
|
|
819
|
+
function getCssSelector(el) {
|
|
820
|
+
if (!el || el.nodeType !== 1 || el === document.body)
|
|
821
|
+
return el.tagName.toLowerCase();
|
|
822
|
+
const parent = el.parentElement;
|
|
823
|
+
const tag = el.tagName.toLowerCase();
|
|
824
|
+
// Find the index of the element among its siblings of the same tag
|
|
825
|
+
let index = 1;
|
|
826
|
+
for (let sibling = el.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
|
|
827
|
+
if (sibling.tagName === el.tagName) {
|
|
828
|
+
index++;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
// Use nth-child if necessary (i.e., if there's more than one of the same tag)
|
|
832
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === el.tagName);
|
|
833
|
+
const needsNthChild = siblings.length > 1;
|
|
834
|
+
const selector = needsNthChild ? `${tag}:nth-child(${[...parent.children].indexOf(el) + 1})` : tag;
|
|
835
|
+
return getCssSelector(parent) + " > " + selector;
|
|
836
|
+
}
|
|
837
|
+
const cssSelector = getCssSelector(el);
|
|
838
|
+
return cssSelector;
|
|
839
|
+
});
|
|
840
|
+
newElementSelector = cssSelector;
|
|
841
|
+
}
|
|
842
|
+
else {
|
|
843
|
+
const randomToken = "blinq_" + Math.random().toString(36).substring(7);
|
|
844
|
+
const id = await element.evaluate((el, randomToken) => {
|
|
845
|
+
// check if the element has id attribute
|
|
846
|
+
if (el.id) {
|
|
847
|
+
return el.id;
|
|
848
|
+
}
|
|
849
|
+
el.setAttribute("id", randomToken);
|
|
850
|
+
console.log("set id=" + randomToken + " on element", el);
|
|
851
|
+
return randomToken;
|
|
852
|
+
}, randomToken);
|
|
853
|
+
newElementSelector = "#" + id;
|
|
854
|
+
// check if the id contains :
|
|
855
|
+
if (id.includes(":")) {
|
|
856
|
+
// //*[@id="radix-:r0:"]
|
|
857
|
+
newElementSelector = `//*[@id="${id}"]`;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
605
860
|
const scope = element._frame ?? element.page();
|
|
606
|
-
let newElementSelector = "[data-blinq-id-" + randomToken + "]";
|
|
607
861
|
let prefixSelector = "";
|
|
608
862
|
const frameControlSelector = " >> internal:control=enter-frame";
|
|
609
863
|
const frameSelectorIndex = element._selector.lastIndexOf(frameControlSelector);
|
|
610
864
|
if (frameSelectorIndex !== -1) {
|
|
611
865
|
// remove everything after the >> internal:control=enter-frame
|
|
612
866
|
const frameSelector = element._selector.substring(0, frameSelectorIndex);
|
|
613
|
-
prefixSelector = frameSelector + " >> internal:control=enter-frame >>";
|
|
867
|
+
prefixSelector = frameSelector + " >> internal:control=enter-frame >> ";
|
|
614
868
|
}
|
|
615
869
|
// if (element?._frame?._selector) {
|
|
616
870
|
// prefixSelector = element._frame._selector + " >> " + prefixSelector;
|
|
@@ -619,7 +873,7 @@ class StableBrowser {
|
|
|
619
873
|
return scope.locator(newSelector);
|
|
620
874
|
}
|
|
621
875
|
}
|
|
622
|
-
throw new Error("unable to locate element ");
|
|
876
|
+
throw new Error("unable to locate element " + JSON.stringify(selectors));
|
|
623
877
|
}
|
|
624
878
|
async _findFrameScope(selectors, timeout = 30000, info) {
|
|
625
879
|
if (!info) {
|
|
@@ -649,7 +903,7 @@ class StableBrowser {
|
|
|
649
903
|
break;
|
|
650
904
|
}
|
|
651
905
|
catch (error) {
|
|
652
|
-
console.error("frame not found " + frameLocator.css);
|
|
906
|
+
// console.error("frame not found " + frameLocator.css);
|
|
653
907
|
}
|
|
654
908
|
}
|
|
655
909
|
}
|
|
@@ -727,7 +981,6 @@ class StableBrowser {
|
|
|
727
981
|
let locatorsCount = 0;
|
|
728
982
|
let lazy_scroll = false;
|
|
729
983
|
//let arrayMode = Array.isArray(selectors);
|
|
730
|
-
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
731
984
|
let selectorsLocators = null;
|
|
732
985
|
selectorsLocators = selectors.locators;
|
|
733
986
|
// group selectors by priority
|
|
@@ -755,6 +1008,7 @@ class StableBrowser {
|
|
|
755
1008
|
let highPriorityOnly = true;
|
|
756
1009
|
let visibleOnly = true;
|
|
757
1010
|
while (true) {
|
|
1011
|
+
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
758
1012
|
locatorsCount = 0;
|
|
759
1013
|
let result = [];
|
|
760
1014
|
let popupResult = await this.closeUnexpectedPopups(info, _params);
|
|
@@ -843,9 +1097,9 @@ class StableBrowser {
|
|
|
843
1097
|
if (!info?.failCause?.lastError) {
|
|
844
1098
|
info.failCause.lastError = `failed to locate ${formatElementName(selectors.element_name)}, ${locatorsCount > 0 ? `${locatorsCount} matching elements found` : "no matching elements found"}`;
|
|
845
1099
|
}
|
|
846
|
-
throw new Error("failed to locate first element no elements found, ");
|
|
1100
|
+
throw new Error("failed to locate first element no elements found, " + info.log);
|
|
847
1101
|
}
|
|
848
|
-
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name) {
|
|
1102
|
+
async _scanLocatorsGroup(locatorsGroup, scope, _params, info, visibleOnly, allowDisabled = false, element_name, logErrors = false) {
|
|
849
1103
|
let foundElements = [];
|
|
850
1104
|
const result = {
|
|
851
1105
|
foundElements: foundElements,
|
|
@@ -864,13 +1118,19 @@ class StableBrowser {
|
|
|
864
1118
|
await this._collectLocatorInformation(locatorsGroup, i, this.page, foundLocators, _params, info, visibleOnly, allowDisabled, element_name);
|
|
865
1119
|
}
|
|
866
1120
|
catch (e) {
|
|
867
|
-
|
|
1121
|
+
if (logErrors) {
|
|
1122
|
+
this.logger.info("unable to use locator (second try) " + JSON.stringify(locatorsGroup[i]));
|
|
1123
|
+
}
|
|
868
1124
|
}
|
|
869
1125
|
}
|
|
870
1126
|
if (foundLocators.length === 1) {
|
|
1127
|
+
let box = null;
|
|
1128
|
+
if (!this.onlyFailuresScreenshot) {
|
|
1129
|
+
box = await foundLocators[0].boundingBox();
|
|
1130
|
+
}
|
|
871
1131
|
result.foundElements.push({
|
|
872
1132
|
locator: foundLocators[0],
|
|
873
|
-
box:
|
|
1133
|
+
box: box,
|
|
874
1134
|
unique: true,
|
|
875
1135
|
});
|
|
876
1136
|
result.locatorIndex = i;
|
|
@@ -905,7 +1165,7 @@ class StableBrowser {
|
|
|
905
1165
|
});
|
|
906
1166
|
result.locatorIndex = i;
|
|
907
1167
|
}
|
|
908
|
-
else {
|
|
1168
|
+
else if (logErrors) {
|
|
909
1169
|
info.failCause.foundMultiple = true;
|
|
910
1170
|
if (info.locatorLog) {
|
|
911
1171
|
info.locatorLog.setLocatorSearchStatus(JSON.stringify(locatorsGroup[i]), "FOUND_NOT_UNIQUE");
|
|
@@ -1025,17 +1285,30 @@ class StableBrowser {
|
|
|
1025
1285
|
operation: "click",
|
|
1026
1286
|
log: "***** click on " + selectors.element_name + " *****\n",
|
|
1027
1287
|
};
|
|
1288
|
+
check_performance("click_all ***", this.context, true);
|
|
1028
1289
|
try {
|
|
1290
|
+
check_performance("click_preCommand", this.context, true);
|
|
1029
1291
|
await _preCommand(state, this);
|
|
1292
|
+
check_performance("click_preCommand", this.context, false);
|
|
1030
1293
|
await performAction("click", state.element, options, this, state, _params);
|
|
1031
|
-
|
|
1294
|
+
if (!this.fastMode) {
|
|
1295
|
+
check_performance("click_waitForPageLoad", this.context, true);
|
|
1296
|
+
await this.waitForPageLoad({ noSleep: true });
|
|
1297
|
+
check_performance("click_waitForPageLoad", this.context, false);
|
|
1298
|
+
}
|
|
1032
1299
|
return state.info;
|
|
1033
1300
|
}
|
|
1034
1301
|
catch (e) {
|
|
1035
1302
|
await _commandError(state, e, this);
|
|
1036
1303
|
}
|
|
1037
1304
|
finally {
|
|
1305
|
+
check_performance("click_commandFinally", this.context, true);
|
|
1038
1306
|
await _commandFinally(state, this);
|
|
1307
|
+
check_performance("click_commandFinally", this.context, false);
|
|
1308
|
+
check_performance("click_all ***", this.context, false);
|
|
1309
|
+
if (this.context.profile) {
|
|
1310
|
+
console.log(JSON.stringify(this.context.profile, null, 2));
|
|
1311
|
+
}
|
|
1039
1312
|
}
|
|
1040
1313
|
}
|
|
1041
1314
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1091,7 +1364,7 @@ class StableBrowser {
|
|
|
1091
1364
|
// if (world && world.screenshot && !world.screenshotPath) {
|
|
1092
1365
|
// console.log(`Highlighting while running from recorder`);
|
|
1093
1366
|
await this._highlightElements(state.element);
|
|
1094
|
-
await state.element.setChecked(checked);
|
|
1367
|
+
await state.element.setChecked(checked, { timeout: 2000 });
|
|
1095
1368
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1096
1369
|
// await this._unHighlightElements(element);
|
|
1097
1370
|
// }
|
|
@@ -1103,14 +1376,31 @@ class StableBrowser {
|
|
|
1103
1376
|
this.logger.info("element did not change its state, ignoring...");
|
|
1104
1377
|
}
|
|
1105
1378
|
else {
|
|
1379
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1106
1380
|
//await this.closeUnexpectedPopups();
|
|
1107
1381
|
state.info.log += "setCheck failed, will try again" + "\n";
|
|
1108
|
-
state.
|
|
1109
|
-
|
|
1110
|
-
|
|
1382
|
+
state.element_found = false;
|
|
1383
|
+
try {
|
|
1384
|
+
state.element = await this._locate(selectors, state.info, _params, 100);
|
|
1385
|
+
state.element_found = true;
|
|
1386
|
+
// check the check state
|
|
1387
|
+
}
|
|
1388
|
+
catch (error) {
|
|
1389
|
+
// element dismissed
|
|
1390
|
+
}
|
|
1391
|
+
if (state.element_found) {
|
|
1392
|
+
const isChecked = await state.element.isChecked();
|
|
1393
|
+
if (isChecked !== checked) {
|
|
1394
|
+
// perform click
|
|
1395
|
+
await state.element.click({ timeout: 2000, force: true });
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1398
|
+
this.logger.info(`Element ${selectors.element_name} is already in the desired state (${checked})`);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1111
1401
|
}
|
|
1112
1402
|
}
|
|
1113
|
-
await this.waitForPageLoad();
|
|
1403
|
+
//await this.waitForPageLoad();
|
|
1114
1404
|
return state.info;
|
|
1115
1405
|
}
|
|
1116
1406
|
catch (e) {
|
|
@@ -1136,7 +1426,7 @@ class StableBrowser {
|
|
|
1136
1426
|
await _preCommand(state, this);
|
|
1137
1427
|
await performAction("hover", state.element, options, this, state, _params);
|
|
1138
1428
|
await _screenshot(state, this);
|
|
1139
|
-
await this.waitForPageLoad();
|
|
1429
|
+
//await this.waitForPageLoad();
|
|
1140
1430
|
return state.info;
|
|
1141
1431
|
}
|
|
1142
1432
|
catch (e) {
|
|
@@ -1172,7 +1462,7 @@ class StableBrowser {
|
|
|
1172
1462
|
state.info.log += "selectOption failed, will try force" + "\n";
|
|
1173
1463
|
await state.element.selectOption(values, { timeout: 10000, force: true });
|
|
1174
1464
|
}
|
|
1175
|
-
await this.waitForPageLoad();
|
|
1465
|
+
//await this.waitForPageLoad();
|
|
1176
1466
|
return state.info;
|
|
1177
1467
|
}
|
|
1178
1468
|
catch (e) {
|
|
@@ -1403,7 +1693,9 @@ class StableBrowser {
|
|
|
1403
1693
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1404
1694
|
}
|
|
1405
1695
|
}
|
|
1696
|
+
//if (!this.fastMode) {
|
|
1406
1697
|
await _screenshot(state, this);
|
|
1698
|
+
//}
|
|
1407
1699
|
if (enter === true) {
|
|
1408
1700
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1409
1701
|
await this.page.keyboard.press("Enter");
|
|
@@ -1452,8 +1744,8 @@ class StableBrowser {
|
|
|
1452
1744
|
if (enter) {
|
|
1453
1745
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1454
1746
|
await this.page.keyboard.press("Enter");
|
|
1747
|
+
await this.waitForPageLoad();
|
|
1455
1748
|
}
|
|
1456
|
-
await this.waitForPageLoad();
|
|
1457
1749
|
return state.info;
|
|
1458
1750
|
}
|
|
1459
1751
|
catch (e) {
|
|
@@ -1745,6 +2037,11 @@ class StableBrowser {
|
|
|
1745
2037
|
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1746
2038
|
}
|
|
1747
2039
|
// highlight and screenshot
|
|
2040
|
+
try {
|
|
2041
|
+
await await highlightSnapshot(newValue, scope);
|
|
2042
|
+
await _screenshot(state, this);
|
|
2043
|
+
}
|
|
2044
|
+
catch (e) { }
|
|
1748
2045
|
return state.info;
|
|
1749
2046
|
}
|
|
1750
2047
|
catch (e) {
|
|
@@ -1903,12 +2200,7 @@ class StableBrowser {
|
|
|
1903
2200
|
}
|
|
1904
2201
|
}
|
|
1905
2202
|
getTestData(world = null) {
|
|
1906
|
-
|
|
1907
|
-
let data = {};
|
|
1908
|
-
if (fs.existsSync(dataFile)) {
|
|
1909
|
-
data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
|
|
1910
|
-
}
|
|
1911
|
-
return data;
|
|
2203
|
+
return _getTestData(world, this.context, this);
|
|
1912
2204
|
}
|
|
1913
2205
|
async _screenShot(options = {}, world = null, info = null) {
|
|
1914
2206
|
// collect url/path/title
|
|
@@ -2128,6 +2420,77 @@ class StableBrowser {
|
|
|
2128
2420
|
await _commandFinally(state, this);
|
|
2129
2421
|
}
|
|
2130
2422
|
}
|
|
2423
|
+
async extractProperty(selectors, property, variable, _params = null, options = {}, world = null) {
|
|
2424
|
+
const state = {
|
|
2425
|
+
selectors,
|
|
2426
|
+
_params,
|
|
2427
|
+
property,
|
|
2428
|
+
variable,
|
|
2429
|
+
options,
|
|
2430
|
+
world,
|
|
2431
|
+
type: Types.EXTRACT_PROPERTY,
|
|
2432
|
+
text: `Extract property from element`,
|
|
2433
|
+
_text: `Extract property ${property} from ${selectors.element_name}`,
|
|
2434
|
+
operation: "extractProperty",
|
|
2435
|
+
log: "***** extract property " + property + " from " + selectors.element_name + " *****\n",
|
|
2436
|
+
allowDisabled: true,
|
|
2437
|
+
};
|
|
2438
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2439
|
+
try {
|
|
2440
|
+
await _preCommand(state, this);
|
|
2441
|
+
switch (property) {
|
|
2442
|
+
case "inner_text":
|
|
2443
|
+
state.value = await state.element.innerText();
|
|
2444
|
+
break;
|
|
2445
|
+
case "href":
|
|
2446
|
+
state.value = await state.element.getAttribute("href");
|
|
2447
|
+
break;
|
|
2448
|
+
case "value":
|
|
2449
|
+
state.value = await state.element.inputValue();
|
|
2450
|
+
break;
|
|
2451
|
+
case "text":
|
|
2452
|
+
state.value = await state.element.textContent();
|
|
2453
|
+
break;
|
|
2454
|
+
default:
|
|
2455
|
+
if (property.startsWith("dataset.")) {
|
|
2456
|
+
const dataAttribute = property.substring(8);
|
|
2457
|
+
state.value = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2458
|
+
}
|
|
2459
|
+
else {
|
|
2460
|
+
state.value = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
if (options !== null) {
|
|
2464
|
+
if (options.regex && options.regex !== "") {
|
|
2465
|
+
// Construct a regex pattern from the provided string
|
|
2466
|
+
const regex = options.regex.slice(1, -1);
|
|
2467
|
+
const regexPattern = new RegExp(regex, "g");
|
|
2468
|
+
const matches = state.value.match(regexPattern);
|
|
2469
|
+
if (matches) {
|
|
2470
|
+
let newValue = "";
|
|
2471
|
+
for (const match of matches) {
|
|
2472
|
+
newValue += match;
|
|
2473
|
+
}
|
|
2474
|
+
state.value = newValue;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
if (options.trimSpaces && options.trimSpaces === true) {
|
|
2478
|
+
state.value = state.value.trim();
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
state.info.value = state.value;
|
|
2482
|
+
this.setTestData({ [variable]: state.value }, world);
|
|
2483
|
+
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2484
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2485
|
+
return state.info;
|
|
2486
|
+
}
|
|
2487
|
+
catch (e) {
|
|
2488
|
+
await _commandError(state, e, this);
|
|
2489
|
+
}
|
|
2490
|
+
finally {
|
|
2491
|
+
await _commandFinally(state, this);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2131
2494
|
async verifyAttribute(selectors, attribute, value, _params = null, options = {}, world = null) {
|
|
2132
2495
|
const state = {
|
|
2133
2496
|
selectors,
|
|
@@ -2226,6 +2589,260 @@ class StableBrowser {
|
|
|
2226
2589
|
await _commandFinally(state, this);
|
|
2227
2590
|
}
|
|
2228
2591
|
}
|
|
2592
|
+
async verifyProperty(selectors, property, value, _params = null, options = {}, world = null) {
|
|
2593
|
+
const state = {
|
|
2594
|
+
selectors,
|
|
2595
|
+
_params,
|
|
2596
|
+
property,
|
|
2597
|
+
value,
|
|
2598
|
+
options,
|
|
2599
|
+
world,
|
|
2600
|
+
type: Types.VERIFY_PROPERTY,
|
|
2601
|
+
highlight: true,
|
|
2602
|
+
screenshot: true,
|
|
2603
|
+
text: `Verify element property`,
|
|
2604
|
+
_text: `Verify property ${property} from ${selectors.element_name} is ${value}`,
|
|
2605
|
+
operation: "verifyProperty",
|
|
2606
|
+
log: "***** verify property " + property + " from " + selectors.element_name + " *****\n",
|
|
2607
|
+
allowDisabled: true,
|
|
2608
|
+
};
|
|
2609
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2610
|
+
let val;
|
|
2611
|
+
let expectedValue;
|
|
2612
|
+
try {
|
|
2613
|
+
await _preCommand(state, this);
|
|
2614
|
+
expectedValue = await replaceWithLocalTestData(state.value, world);
|
|
2615
|
+
state.info.expectedValue = expectedValue;
|
|
2616
|
+
switch (property) {
|
|
2617
|
+
case "innerText":
|
|
2618
|
+
val = String(await state.element.innerText());
|
|
2619
|
+
break;
|
|
2620
|
+
case "text":
|
|
2621
|
+
val = String(await state.element.textContent());
|
|
2622
|
+
break;
|
|
2623
|
+
case "value":
|
|
2624
|
+
val = String(await state.element.inputValue());
|
|
2625
|
+
break;
|
|
2626
|
+
case "checked":
|
|
2627
|
+
val = String(await state.element.isChecked());
|
|
2628
|
+
break;
|
|
2629
|
+
case "disabled":
|
|
2630
|
+
val = String(await state.element.isDisabled());
|
|
2631
|
+
break;
|
|
2632
|
+
case "readOnly":
|
|
2633
|
+
const isEditable = await state.element.isEditable();
|
|
2634
|
+
val = String(!isEditable);
|
|
2635
|
+
break;
|
|
2636
|
+
case "innerHTML":
|
|
2637
|
+
val = String(await state.element.innerHTML());
|
|
2638
|
+
break;
|
|
2639
|
+
case "outerHTML":
|
|
2640
|
+
val = String(await state.element.evaluate((element) => element.outerHTML));
|
|
2641
|
+
break;
|
|
2642
|
+
default:
|
|
2643
|
+
if (property.startsWith("dataset.")) {
|
|
2644
|
+
const dataAttribute = property.substring(8);
|
|
2645
|
+
val = String(await state.element.getAttribute(`data-${dataAttribute}`)) || "";
|
|
2646
|
+
}
|
|
2647
|
+
else {
|
|
2648
|
+
val = String(await state.element.evaluate((element, prop) => element[prop], property));
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
// Helper function to remove all style="" attributes
|
|
2652
|
+
const removeStyleAttributes = (htmlString) => {
|
|
2653
|
+
return htmlString.replace(/\s*style\s*=\s*"[^"]*"/gi, "");
|
|
2654
|
+
};
|
|
2655
|
+
// Remove style attributes for innerHTML and outerHTML properties
|
|
2656
|
+
if (property === "innerHTML" || property === "outerHTML") {
|
|
2657
|
+
val = removeStyleAttributes(val);
|
|
2658
|
+
expectedValue = removeStyleAttributes(expectedValue);
|
|
2659
|
+
}
|
|
2660
|
+
state.info.value = val;
|
|
2661
|
+
let regex;
|
|
2662
|
+
state.info.value = val;
|
|
2663
|
+
const isRegex = expectedValue.startsWith("regex:");
|
|
2664
|
+
const isContains = expectedValue.startsWith("contains:");
|
|
2665
|
+
const isExact = expectedValue.startsWith("exact:");
|
|
2666
|
+
let matchPassed = false;
|
|
2667
|
+
if (isRegex) {
|
|
2668
|
+
const rawPattern = expectedValue.slice(6); // remove "regex:"
|
|
2669
|
+
const lastSlashIndex = rawPattern.lastIndexOf("/");
|
|
2670
|
+
if (rawPattern.startsWith("/") && lastSlashIndex > 0) {
|
|
2671
|
+
const patternBody = rawPattern.slice(1, lastSlashIndex).replace(/\n/g, ".*");
|
|
2672
|
+
const flags = rawPattern.slice(lastSlashIndex + 1) || "gs";
|
|
2673
|
+
const regex = new RegExp(patternBody, flags);
|
|
2674
|
+
state.info.regex = true;
|
|
2675
|
+
matchPassed = regex.test(val);
|
|
2676
|
+
}
|
|
2677
|
+
else {
|
|
2678
|
+
// Fallback: treat as literal
|
|
2679
|
+
const escapedPattern = rawPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2680
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2681
|
+
matchPassed = regex.test(val);
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
else if (isContains) {
|
|
2685
|
+
const containsValue = expectedValue.slice(9); // remove "contains:"
|
|
2686
|
+
matchPassed = val.includes(containsValue);
|
|
2687
|
+
}
|
|
2688
|
+
else if (isExact) {
|
|
2689
|
+
const exactValue = expectedValue.slice(6); // remove "exact:"
|
|
2690
|
+
matchPassed = val === exactValue;
|
|
2691
|
+
}
|
|
2692
|
+
else if (property === "innerText") {
|
|
2693
|
+
// Default innerText logic
|
|
2694
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2695
|
+
const valLines = val.split("\n");
|
|
2696
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2697
|
+
matchPassed = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2698
|
+
}
|
|
2699
|
+
else {
|
|
2700
|
+
// Fallback exact or loose match
|
|
2701
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2702
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2703
|
+
matchPassed = regex.test(val);
|
|
2704
|
+
}
|
|
2705
|
+
if (!matchPassed) {
|
|
2706
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2707
|
+
state.info.failCause.assertionFailed = true;
|
|
2708
|
+
state.info.failCause.lastError = errorMessage;
|
|
2709
|
+
throw new Error(errorMessage);
|
|
2710
|
+
}
|
|
2711
|
+
return state.info;
|
|
2712
|
+
}
|
|
2713
|
+
catch (e) {
|
|
2714
|
+
await _commandError(state, e, this);
|
|
2715
|
+
}
|
|
2716
|
+
finally {
|
|
2717
|
+
await _commandFinally(state, this);
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
async conditionalWait(selectors, condition, timeout = 1000, _params = null, options = {}, world = null) {
|
|
2721
|
+
// Convert timeout from seconds to milliseconds
|
|
2722
|
+
const timeoutMs = timeout * 1000;
|
|
2723
|
+
const state = {
|
|
2724
|
+
selectors,
|
|
2725
|
+
_params,
|
|
2726
|
+
condition,
|
|
2727
|
+
timeout: timeoutMs, // Store as milliseconds for internal use
|
|
2728
|
+
options,
|
|
2729
|
+
world,
|
|
2730
|
+
type: Types.CONDITIONAL_WAIT,
|
|
2731
|
+
highlight: true,
|
|
2732
|
+
screenshot: true,
|
|
2733
|
+
text: `Conditional wait for element`,
|
|
2734
|
+
_text: `Wait for ${selectors.element_name} to be ${condition} (timeout: ${timeout}s)`, // Display original seconds
|
|
2735
|
+
operation: "conditionalWait",
|
|
2736
|
+
log: `***** conditional wait for ${condition} on ${selectors.element_name} *****\n`,
|
|
2737
|
+
allowDisabled: true,
|
|
2738
|
+
info: {},
|
|
2739
|
+
};
|
|
2740
|
+
// Initialize startTime outside try block to ensure it's always accessible
|
|
2741
|
+
const startTime = Date.now();
|
|
2742
|
+
let conditionMet = false;
|
|
2743
|
+
let currentValue = null;
|
|
2744
|
+
let lastError = null;
|
|
2745
|
+
// Main retry loop - continues until timeout or condition is met
|
|
2746
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2747
|
+
const elapsedTime = Date.now() - startTime;
|
|
2748
|
+
const remainingTime = timeoutMs - elapsedTime;
|
|
2749
|
+
try {
|
|
2750
|
+
// Try to execute _preCommand (element location)
|
|
2751
|
+
await _preCommand(state, this);
|
|
2752
|
+
// If _preCommand succeeds, start condition checking
|
|
2753
|
+
const checkCondition = async () => {
|
|
2754
|
+
try {
|
|
2755
|
+
switch (condition.toLowerCase()) {
|
|
2756
|
+
case "checked":
|
|
2757
|
+
currentValue = await state.element.isChecked();
|
|
2758
|
+
return currentValue === true;
|
|
2759
|
+
case "unchecked":
|
|
2760
|
+
currentValue = await state.element.isChecked();
|
|
2761
|
+
return currentValue === false;
|
|
2762
|
+
case "visible":
|
|
2763
|
+
currentValue = await state.element.isVisible();
|
|
2764
|
+
return currentValue === true;
|
|
2765
|
+
case "hidden":
|
|
2766
|
+
currentValue = await state.element.isVisible();
|
|
2767
|
+
return currentValue === false;
|
|
2768
|
+
case "enabled":
|
|
2769
|
+
currentValue = await state.element.isDisabled();
|
|
2770
|
+
return currentValue === false;
|
|
2771
|
+
case "disabled":
|
|
2772
|
+
currentValue = await state.element.isDisabled();
|
|
2773
|
+
return currentValue === true;
|
|
2774
|
+
case "editable":
|
|
2775
|
+
// currentValue = await String(await state.element.evaluate((element, prop) => element[prop], "isContentEditable"));
|
|
2776
|
+
currentValue = await state.element.isContentEditable();
|
|
2777
|
+
return currentValue === true;
|
|
2778
|
+
default:
|
|
2779
|
+
state.info.message = `Unsupported condition: '${condition}'. Supported conditions are: checked, unchecked, visible, hidden, enabled, disabled, editable.`;
|
|
2780
|
+
state.info.success = false;
|
|
2781
|
+
return false;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
catch (error) {
|
|
2785
|
+
// Don't throw here, just return false to continue retrying
|
|
2786
|
+
return false;
|
|
2787
|
+
}
|
|
2788
|
+
};
|
|
2789
|
+
// Inner loop for condition checking (once element is located)
|
|
2790
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
2791
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2792
|
+
conditionMet = await checkCondition();
|
|
2793
|
+
if (conditionMet) {
|
|
2794
|
+
break;
|
|
2795
|
+
}
|
|
2796
|
+
// Check if we still have time for another attempt
|
|
2797
|
+
if (Date.now() - startTime + 50 < timeoutMs) {
|
|
2798
|
+
await new Promise((res) => setTimeout(res, 50));
|
|
2799
|
+
}
|
|
2800
|
+
else {
|
|
2801
|
+
break;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
// If we got here and condition is met, break out of main loop
|
|
2805
|
+
if (conditionMet) {
|
|
2806
|
+
break;
|
|
2807
|
+
}
|
|
2808
|
+
// If condition not met but no exception, we've timed out
|
|
2809
|
+
break;
|
|
2810
|
+
}
|
|
2811
|
+
catch (e) {
|
|
2812
|
+
lastError = e;
|
|
2813
|
+
const currentElapsedTime = Date.now() - startTime;
|
|
2814
|
+
const timeLeft = timeoutMs - currentElapsedTime;
|
|
2815
|
+
// Check if we have enough time left to retry
|
|
2816
|
+
if (timeLeft > 100) {
|
|
2817
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2818
|
+
}
|
|
2819
|
+
else {
|
|
2820
|
+
break;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
const actualWaitTime = Date.now() - startTime;
|
|
2825
|
+
state.info = {
|
|
2826
|
+
success: conditionMet,
|
|
2827
|
+
conditionMet,
|
|
2828
|
+
actualWaitTime,
|
|
2829
|
+
currentValue,
|
|
2830
|
+
lastError: lastError?.message || null,
|
|
2831
|
+
message: conditionMet
|
|
2832
|
+
? `Condition '${condition}' met after ${(actualWaitTime / 1000).toFixed(2)}s`
|
|
2833
|
+
: `Condition '${condition}' not met within ${timeout}s timeout`,
|
|
2834
|
+
};
|
|
2835
|
+
if (lastError) {
|
|
2836
|
+
state.log += `Last error: ${lastError.message}\n`;
|
|
2837
|
+
}
|
|
2838
|
+
try {
|
|
2839
|
+
await _commandFinally(state, this);
|
|
2840
|
+
}
|
|
2841
|
+
catch (finallyError) {
|
|
2842
|
+
state.log += `Error in _commandFinally: ${finallyError.message}\n`;
|
|
2843
|
+
}
|
|
2844
|
+
return state.info;
|
|
2845
|
+
}
|
|
2229
2846
|
async extractEmailData(emailAddress, options, world) {
|
|
2230
2847
|
if (!emailAddress) {
|
|
2231
2848
|
throw new Error("email address is null");
|
|
@@ -2383,56 +3000,49 @@ class StableBrowser {
|
|
|
2383
3000
|
console.debug(error);
|
|
2384
3001
|
}
|
|
2385
3002
|
}
|
|
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
|
-
// }
|
|
3003
|
+
_matcher(text) {
|
|
3004
|
+
if (!text) {
|
|
3005
|
+
return { matcher: "contains", queryText: "" };
|
|
3006
|
+
}
|
|
3007
|
+
if (text.length < 2) {
|
|
3008
|
+
return { matcher: "contains", queryText: text };
|
|
3009
|
+
}
|
|
3010
|
+
const split = text.split(":");
|
|
3011
|
+
const matcher = split[0].toLowerCase();
|
|
3012
|
+
const queryText = split.slice(1).join(":").trim();
|
|
3013
|
+
return { matcher, queryText };
|
|
3014
|
+
}
|
|
3015
|
+
_getDomain(url) {
|
|
3016
|
+
if (url.length === 0 || (!url.startsWith("http://") && !url.startsWith("https://"))) {
|
|
3017
|
+
return "";
|
|
3018
|
+
}
|
|
3019
|
+
let hostnameFragments = url.split("/")[2].split(".");
|
|
3020
|
+
if (hostnameFragments.some((fragment) => fragment.includes(":"))) {
|
|
3021
|
+
return hostnameFragments.join("-").split(":").join("-");
|
|
3022
|
+
}
|
|
3023
|
+
let n = hostnameFragments.length;
|
|
3024
|
+
let fragments = [...hostnameFragments];
|
|
3025
|
+
while (n > 0 && hostnameFragments[n - 1].length <= 3) {
|
|
3026
|
+
hostnameFragments.pop();
|
|
3027
|
+
n = hostnameFragments.length;
|
|
3028
|
+
}
|
|
3029
|
+
if (n == 0) {
|
|
3030
|
+
if (fragments[0] === "www")
|
|
3031
|
+
fragments = fragments.slice(1);
|
|
3032
|
+
return fragments.length > 1 ? fragments.slice(0, fragments.length - 1).join("-") : fragments.join("-");
|
|
3033
|
+
}
|
|
3034
|
+
if (hostnameFragments[0] === "www")
|
|
3035
|
+
hostnameFragments = hostnameFragments.slice(1);
|
|
3036
|
+
return hostnameFragments.join(".");
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* Verify the page path matches the given path.
|
|
3040
|
+
* @param {string} pathPart - The path to verify.
|
|
3041
|
+
* @param {object} options - Options for verification.
|
|
3042
|
+
* @param {object} world - The world context.
|
|
3043
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
3044
|
+
*/
|
|
2434
3045
|
async verifyPagePath(pathPart, options = {}, world = null) {
|
|
2435
|
-
const startTime = Date.now();
|
|
2436
3046
|
let error = null;
|
|
2437
3047
|
let screenshotId = null;
|
|
2438
3048
|
let screenshotPath = null;
|
|
@@ -2446,113 +3056,212 @@ class StableBrowser {
|
|
|
2446
3056
|
pathPart = newValue;
|
|
2447
3057
|
}
|
|
2448
3058
|
info.pathPart = pathPart;
|
|
3059
|
+
const { matcher, queryText } = this._matcher(pathPart);
|
|
3060
|
+
const state = {
|
|
3061
|
+
text_search: queryText,
|
|
3062
|
+
options,
|
|
3063
|
+
world,
|
|
3064
|
+
locate: false,
|
|
3065
|
+
scroll: false,
|
|
3066
|
+
highlight: false,
|
|
3067
|
+
type: Types.VERIFY_PAGE_PATH,
|
|
3068
|
+
text: `Verify the page url is ${queryText}`,
|
|
3069
|
+
_text: `Verify the page url is ${queryText}`,
|
|
3070
|
+
operation: "verifyPagePath",
|
|
3071
|
+
log: "***** verify page url is " + queryText + " *****\n",
|
|
3072
|
+
};
|
|
2449
3073
|
try {
|
|
3074
|
+
await _preCommand(state, this);
|
|
3075
|
+
state.info.text = queryText;
|
|
2450
3076
|
for (let i = 0; i < 30; i++) {
|
|
2451
3077
|
const url = await this.page.url();
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
3078
|
+
switch (matcher) {
|
|
3079
|
+
case "exact":
|
|
3080
|
+
if (url !== queryText) {
|
|
3081
|
+
if (i === 29) {
|
|
3082
|
+
throw new Error(`Page URL ${url} is not equal to ${queryText}`);
|
|
3083
|
+
}
|
|
3084
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3085
|
+
continue;
|
|
3086
|
+
}
|
|
3087
|
+
break;
|
|
3088
|
+
case "contains":
|
|
3089
|
+
if (!url.includes(queryText)) {
|
|
3090
|
+
if (i === 29) {
|
|
3091
|
+
throw new Error(`Page URL ${url} doesn't contain ${queryText}`);
|
|
3092
|
+
}
|
|
3093
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3094
|
+
continue;
|
|
3095
|
+
}
|
|
3096
|
+
break;
|
|
3097
|
+
case "starts-with":
|
|
3098
|
+
{
|
|
3099
|
+
const domain = this._getDomain(url);
|
|
3100
|
+
if (domain.length > 0 && domain !== queryText) {
|
|
3101
|
+
if (i === 29) {
|
|
3102
|
+
throw new Error(`Page URL ${url} doesn't start with ${queryText}`);
|
|
3103
|
+
}
|
|
3104
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3105
|
+
continue;
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
break;
|
|
3109
|
+
case "ends-with":
|
|
3110
|
+
{
|
|
3111
|
+
const urlObj = new URL(url);
|
|
3112
|
+
let route = "/";
|
|
3113
|
+
if (urlObj.pathname !== "/") {
|
|
3114
|
+
route = urlObj.pathname.split("/").slice(-1)[0].trim();
|
|
3115
|
+
}
|
|
3116
|
+
else {
|
|
3117
|
+
route = "/";
|
|
3118
|
+
}
|
|
3119
|
+
if (route !== queryText) {
|
|
3120
|
+
if (i === 29) {
|
|
3121
|
+
throw new Error(`Page URL ${url} doesn't end with ${queryText}`);
|
|
3122
|
+
}
|
|
3123
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3124
|
+
continue;
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
break;
|
|
3128
|
+
case "regex":
|
|
3129
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3130
|
+
if (!regex.test(url)) {
|
|
3131
|
+
if (i === 29) {
|
|
3132
|
+
throw new Error(`Page URL ${url} doesn't match regex ${queryText}`);
|
|
3133
|
+
}
|
|
3134
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3135
|
+
continue;
|
|
3136
|
+
}
|
|
3137
|
+
break;
|
|
3138
|
+
default:
|
|
3139
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3140
|
+
if (!url.includes(pathPart)) {
|
|
3141
|
+
if (i === 29) {
|
|
3142
|
+
throw new Error(`Page URL ${url} does not contain ${pathPart}`);
|
|
3143
|
+
}
|
|
3144
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3145
|
+
continue;
|
|
3146
|
+
}
|
|
2458
3147
|
}
|
|
2459
|
-
|
|
2460
|
-
return info;
|
|
3148
|
+
await _screenshot(state, this);
|
|
3149
|
+
return state.info;
|
|
2461
3150
|
}
|
|
2462
3151
|
}
|
|
2463
3152
|
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);
|
|
3153
|
+
state.info.failCause.lastError = e.message;
|
|
3154
|
+
state.info.failCause.assertionFailed = true;
|
|
3155
|
+
await _commandError(state, e, this);
|
|
2472
3156
|
}
|
|
2473
3157
|
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
|
-
});
|
|
3158
|
+
await _commandFinally(state, this);
|
|
2494
3159
|
}
|
|
2495
3160
|
}
|
|
3161
|
+
/**
|
|
3162
|
+
* Verify the page title matches the given title.
|
|
3163
|
+
* @param {string} title - The title to verify.
|
|
3164
|
+
* @param {object} options - Options for verification.
|
|
3165
|
+
* @param {object} world - The world context.
|
|
3166
|
+
* @returns {Promise<object>} - The state info after verification.
|
|
3167
|
+
*/
|
|
2496
3168
|
async verifyPageTitle(title, options = {}, world = null) {
|
|
2497
|
-
const startTime = Date.now();
|
|
2498
3169
|
let error = null;
|
|
2499
3170
|
let screenshotId = null;
|
|
2500
3171
|
let screenshotPath = null;
|
|
2501
3172
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2502
|
-
const info = {};
|
|
2503
|
-
info.log = "***** verify page title " + title + " *****\n";
|
|
2504
|
-
info.operation = "verifyPageTitle";
|
|
2505
3173
|
const newValue = await this._replaceWithLocalData(title, world);
|
|
2506
3174
|
if (newValue !== title) {
|
|
2507
3175
|
this.logger.info(title + "=" + newValue);
|
|
2508
3176
|
title = newValue;
|
|
2509
3177
|
}
|
|
2510
|
-
|
|
3178
|
+
const { matcher, queryText } = this._matcher(title);
|
|
3179
|
+
const state = {
|
|
3180
|
+
text_search: queryText,
|
|
3181
|
+
options,
|
|
3182
|
+
world,
|
|
3183
|
+
locate: false,
|
|
3184
|
+
scroll: false,
|
|
3185
|
+
highlight: false,
|
|
3186
|
+
type: Types.VERIFY_PAGE_TITLE,
|
|
3187
|
+
text: `Verify the page title is ${queryText}`,
|
|
3188
|
+
_text: `Verify the page title is ${queryText}`,
|
|
3189
|
+
operation: "verifyPageTitle",
|
|
3190
|
+
log: "***** verify page title is " + queryText + " *****\n",
|
|
3191
|
+
};
|
|
2511
3192
|
try {
|
|
3193
|
+
await _preCommand(state, this);
|
|
3194
|
+
state.info.text = queryText;
|
|
2512
3195
|
for (let i = 0; i < 30; i++) {
|
|
2513
3196
|
const foundTitle = await this.page.title();
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
3197
|
+
switch (matcher) {
|
|
3198
|
+
case "exact":
|
|
3199
|
+
if (foundTitle !== queryText) {
|
|
3200
|
+
if (i === 29) {
|
|
3201
|
+
throw new Error(`Page Title ${foundTitle} is not equal to ${queryText}`);
|
|
3202
|
+
}
|
|
3203
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3204
|
+
continue;
|
|
3205
|
+
}
|
|
3206
|
+
break;
|
|
3207
|
+
case "contains":
|
|
3208
|
+
if (!foundTitle.includes(queryText)) {
|
|
3209
|
+
if (i === 29) {
|
|
3210
|
+
throw new Error(`Page Title ${foundTitle} doesn't contain ${queryText}`);
|
|
3211
|
+
}
|
|
3212
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3213
|
+
continue;
|
|
3214
|
+
}
|
|
3215
|
+
break;
|
|
3216
|
+
case "starts-with":
|
|
3217
|
+
if (!foundTitle.startsWith(queryText)) {
|
|
3218
|
+
if (i === 29) {
|
|
3219
|
+
throw new Error(`Page title ${foundTitle} doesn't start with ${queryText}`);
|
|
3220
|
+
}
|
|
3221
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
break;
|
|
3225
|
+
case "ends-with":
|
|
3226
|
+
if (!foundTitle.endsWith(queryText)) {
|
|
3227
|
+
if (i === 29) {
|
|
3228
|
+
throw new Error(`Page Title ${foundTitle} doesn't end with ${queryText}`);
|
|
3229
|
+
}
|
|
3230
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3231
|
+
continue;
|
|
3232
|
+
}
|
|
3233
|
+
break;
|
|
3234
|
+
case "regex":
|
|
3235
|
+
const regex = new RegExp(queryText.slice(1, -1), "g");
|
|
3236
|
+
if (!regex.test(foundTitle)) {
|
|
3237
|
+
if (i === 29) {
|
|
3238
|
+
throw new Error(`Page Title ${foundTitle} doesn't match regex ${queryText}`);
|
|
3239
|
+
}
|
|
3240
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3241
|
+
continue;
|
|
3242
|
+
}
|
|
3243
|
+
break;
|
|
3244
|
+
default:
|
|
3245
|
+
console.log("Unknown matching type, defaulting to contains matching");
|
|
3246
|
+
if (!foundTitle.includes(title)) {
|
|
3247
|
+
if (i === 29) {
|
|
3248
|
+
throw new Error(`Page Title ${foundTitle} does not contain ${title}`);
|
|
3249
|
+
}
|
|
3250
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3251
|
+
continue;
|
|
3252
|
+
}
|
|
2520
3253
|
}
|
|
2521
|
-
|
|
2522
|
-
return info;
|
|
3254
|
+
await _screenshot(state, this);
|
|
3255
|
+
return state.info;
|
|
2523
3256
|
}
|
|
2524
3257
|
}
|
|
2525
3258
|
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);
|
|
3259
|
+
state.info.failCause.lastError = e.message;
|
|
3260
|
+
state.info.failCause.assertionFailed = true;
|
|
3261
|
+
await _commandError(state, e, this);
|
|
2534
3262
|
}
|
|
2535
3263
|
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
|
-
});
|
|
3264
|
+
await _commandFinally(state, this);
|
|
2556
3265
|
}
|
|
2557
3266
|
}
|
|
2558
3267
|
async findTextInAllFrames(dateAlternatives, numberAlternatives, text, state, partial = true, ignoreCase = false) {
|
|
@@ -2636,27 +3345,10 @@ class StableBrowser {
|
|
|
2636
3345
|
const frame = resultWithElementsFound[0].frame;
|
|
2637
3346
|
const dataAttribute = `[data-blinq-id-${resultWithElementsFound[0].randomToken}]`;
|
|
2638
3347
|
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
3348
|
const element = await frame.locator(dataAttribute).first();
|
|
2654
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2655
|
-
// await this._unhighlightElements(frame, dataAttribute);
|
|
2656
3349
|
if (element) {
|
|
2657
3350
|
await this.scrollIfNeeded(element, state.info);
|
|
2658
3351
|
await element.dispatchEvent("bvt_verify_page_contains_text");
|
|
2659
|
-
// await _screenshot(state, this, element);
|
|
2660
3352
|
}
|
|
2661
3353
|
}
|
|
2662
3354
|
await _screenshot(state, this);
|
|
@@ -2666,7 +3358,6 @@ class StableBrowser {
|
|
|
2666
3358
|
console.error(error);
|
|
2667
3359
|
}
|
|
2668
3360
|
}
|
|
2669
|
-
// await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
2670
3361
|
}
|
|
2671
3362
|
catch (e) {
|
|
2672
3363
|
await _commandError(state, e, this);
|
|
@@ -2748,6 +3439,8 @@ class StableBrowser {
|
|
|
2748
3439
|
operation: "verify_text_with_relation",
|
|
2749
3440
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
2750
3441
|
};
|
|
3442
|
+
const cmdStartTime = Date.now();
|
|
3443
|
+
let cmdEndTime = null;
|
|
2751
3444
|
const timeout = this._getFindElementTimeout(options);
|
|
2752
3445
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2753
3446
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -2783,6 +3476,17 @@ class StableBrowser {
|
|
|
2783
3476
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
2784
3477
|
continue;
|
|
2785
3478
|
}
|
|
3479
|
+
else {
|
|
3480
|
+
cmdEndTime = Date.now();
|
|
3481
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3482
|
+
if (foundAncore) {
|
|
3483
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3484
|
+
}
|
|
3485
|
+
else {
|
|
3486
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
2786
3490
|
try {
|
|
2787
3491
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
2788
3492
|
foundAncore = true;
|
|
@@ -3182,6 +3886,43 @@ class StableBrowser {
|
|
|
3182
3886
|
});
|
|
3183
3887
|
}
|
|
3184
3888
|
}
|
|
3889
|
+
/**
|
|
3890
|
+
* Explicit wait/sleep function that pauses execution for a specified duration
|
|
3891
|
+
* @param duration - Duration to sleep in milliseconds (default: 1000ms)
|
|
3892
|
+
* @param options - Optional configuration object
|
|
3893
|
+
* @param world - Optional world context
|
|
3894
|
+
* @returns Promise that resolves after the specified duration
|
|
3895
|
+
*/
|
|
3896
|
+
async sleep(duration = 1000, options = {}, world = null) {
|
|
3897
|
+
const state = {
|
|
3898
|
+
duration,
|
|
3899
|
+
options,
|
|
3900
|
+
world,
|
|
3901
|
+
locate: false,
|
|
3902
|
+
scroll: false,
|
|
3903
|
+
screenshot: false,
|
|
3904
|
+
highlight: false,
|
|
3905
|
+
type: Types.SLEEP,
|
|
3906
|
+
text: `Sleep for ${duration} ms`,
|
|
3907
|
+
_text: `Sleep for ${duration} ms`,
|
|
3908
|
+
operation: "sleep",
|
|
3909
|
+
log: `***** Sleep for ${duration} ms *****\n`,
|
|
3910
|
+
};
|
|
3911
|
+
try {
|
|
3912
|
+
await _preCommand(state, this);
|
|
3913
|
+
if (duration < 0) {
|
|
3914
|
+
throw new Error("Sleep duration cannot be negative");
|
|
3915
|
+
}
|
|
3916
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
3917
|
+
return state.info;
|
|
3918
|
+
}
|
|
3919
|
+
catch (e) {
|
|
3920
|
+
await _commandError(state, e, this);
|
|
3921
|
+
}
|
|
3922
|
+
finally {
|
|
3923
|
+
await _commandFinally(state, this);
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3185
3926
|
async _replaceWithLocalData(value, world, _decrypt = true, totpWait = true) {
|
|
3186
3927
|
try {
|
|
3187
3928
|
return await replaceWithLocalTestData(value, world, _decrypt, totpWait, this.context, this);
|
|
@@ -3212,6 +3953,7 @@ class StableBrowser {
|
|
|
3212
3953
|
}
|
|
3213
3954
|
async saveStoreState(path = null, world = null) {
|
|
3214
3955
|
const storageState = await this.page.context().storageState();
|
|
3956
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3215
3957
|
//const testDataFile = _getDataFile(world, this.context, this);
|
|
3216
3958
|
if (path) {
|
|
3217
3959
|
// save { storageState: storageState } into the path
|
|
@@ -3222,6 +3964,7 @@ class StableBrowser {
|
|
|
3222
3964
|
}
|
|
3223
3965
|
}
|
|
3224
3966
|
async restoreSaveState(path = null, world = null) {
|
|
3967
|
+
path = await this._replaceWithLocalData(path, this.world);
|
|
3225
3968
|
await refreshBrowser(this, path, world);
|
|
3226
3969
|
this.registerEventListeners(this.context);
|
|
3227
3970
|
registerNetworkEvents(this.world, this, this.context, this.page);
|
|
@@ -3231,6 +3974,22 @@ class StableBrowser {
|
|
|
3231
3974
|
}
|
|
3232
3975
|
}
|
|
3233
3976
|
async waitForPageLoad(options = {}, world = null) {
|
|
3977
|
+
// try {
|
|
3978
|
+
// let currentPagePath = null;
|
|
3979
|
+
// currentPagePath = new URL(this.page.url()).pathname;
|
|
3980
|
+
// if (this.latestPagePath) {
|
|
3981
|
+
// // get the currect page path and compare with the latest page path
|
|
3982
|
+
// if (this.latestPagePath === currentPagePath) {
|
|
3983
|
+
// // if the page path is the same, do not wait for page load
|
|
3984
|
+
// console.log("No page change: " + currentPagePath);
|
|
3985
|
+
// return;
|
|
3986
|
+
// }
|
|
3987
|
+
// }
|
|
3988
|
+
// this.latestPagePath = currentPagePath;
|
|
3989
|
+
// } catch (e) {
|
|
3990
|
+
// console.debug("Error getting current page path: ", e);
|
|
3991
|
+
// }
|
|
3992
|
+
//console.log("Waiting for page load");
|
|
3234
3993
|
let timeout = this._getLoadTimeout(options);
|
|
3235
3994
|
const promiseArray = [];
|
|
3236
3995
|
// let waitForNetworkIdle = true;
|
|
@@ -3263,10 +4022,12 @@ class StableBrowser {
|
|
|
3263
4022
|
else if (e.label === "domcontentloaded") {
|
|
3264
4023
|
console.log("waited for the domcontent loaded timeout");
|
|
3265
4024
|
}
|
|
3266
|
-
console.log(".");
|
|
3267
4025
|
}
|
|
3268
4026
|
finally {
|
|
3269
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
4027
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
4028
|
+
if (options && !options.noSleep) {
|
|
4029
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
4030
|
+
}
|
|
3270
4031
|
({ screenshotId, screenshotPath } = await this._screenShot(options, world));
|
|
3271
4032
|
const endTime = Date.now();
|
|
3272
4033
|
_reportToWorld(world, {
|
|
@@ -3307,7 +4068,6 @@ class StableBrowser {
|
|
|
3307
4068
|
await this.page.close();
|
|
3308
4069
|
}
|
|
3309
4070
|
catch (e) {
|
|
3310
|
-
console.log(".");
|
|
3311
4071
|
await _commandError(state, e, this);
|
|
3312
4072
|
}
|
|
3313
4073
|
finally {
|
|
@@ -3390,6 +4150,17 @@ class StableBrowser {
|
|
|
3390
4150
|
state.element = results[0];
|
|
3391
4151
|
await performAction("hover+click", state.element, options, this, state, _params);
|
|
3392
4152
|
break;
|
|
4153
|
+
case "hover":
|
|
4154
|
+
if (!options.css) {
|
|
4155
|
+
throw new Error("css is not defined");
|
|
4156
|
+
}
|
|
4157
|
+
const result1 = await findElementsInArea(options.css, cellArea, this, options);
|
|
4158
|
+
if (results1.length === 0) {
|
|
4159
|
+
throw new Error(`Element not found in cell area`);
|
|
4160
|
+
}
|
|
4161
|
+
state.element = results1[0];
|
|
4162
|
+
await performAction("hover", state.element, options, this, state, _params);
|
|
4163
|
+
break;
|
|
3393
4164
|
default:
|
|
3394
4165
|
throw new Error("operation is not supported");
|
|
3395
4166
|
}
|
|
@@ -3422,7 +4193,6 @@ class StableBrowser {
|
|
|
3422
4193
|
await this.page.setViewportSize({ width: width, height: hight });
|
|
3423
4194
|
}
|
|
3424
4195
|
catch (e) {
|
|
3425
|
-
console.log(".");
|
|
3426
4196
|
await _commandError({ text: "setViewportSize", operation: "setViewportSize", width, hight, info }, e, this);
|
|
3427
4197
|
}
|
|
3428
4198
|
finally {
|
|
@@ -3460,7 +4230,6 @@ class StableBrowser {
|
|
|
3460
4230
|
await this.page.reload();
|
|
3461
4231
|
}
|
|
3462
4232
|
catch (e) {
|
|
3463
|
-
console.log(".");
|
|
3464
4233
|
await _commandError({ text: "reloadPage", operation: "reloadPage", info }, e, this);
|
|
3465
4234
|
}
|
|
3466
4235
|
finally {
|
|
@@ -3504,6 +4273,10 @@ class StableBrowser {
|
|
|
3504
4273
|
}
|
|
3505
4274
|
}
|
|
3506
4275
|
async beforeScenario(world, scenario) {
|
|
4276
|
+
if (world && world.attach) {
|
|
4277
|
+
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4278
|
+
}
|
|
4279
|
+
this.context.loadedRoutes = null;
|
|
3507
4280
|
this.beforeScenarioCalled = true;
|
|
3508
4281
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
3509
4282
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -3527,7 +4300,7 @@ class StableBrowser {
|
|
|
3527
4300
|
envName = this.context.environment.name;
|
|
3528
4301
|
}
|
|
3529
4302
|
if (!process.env.TEMP_RUN) {
|
|
3530
|
-
await getTestData(envName, world, undefined, this.featureName, this.scenarioName);
|
|
4303
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
3531
4304
|
}
|
|
3532
4305
|
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3533
4306
|
}
|
|
@@ -3535,6 +4308,7 @@ class StableBrowser {
|
|
|
3535
4308
|
async beforeStep(world, step) {
|
|
3536
4309
|
if (!this.beforeScenarioCalled) {
|
|
3537
4310
|
this.beforeScenario(world, step);
|
|
4311
|
+
this.context.loadedRoutes = null;
|
|
3538
4312
|
}
|
|
3539
4313
|
if (this.stepIndex === undefined) {
|
|
3540
4314
|
this.stepIndex = 0;
|
|
@@ -3559,13 +4333,16 @@ class StableBrowser {
|
|
|
3559
4333
|
}
|
|
3560
4334
|
if (this.initSnapshotTaken === false) {
|
|
3561
4335
|
this.initSnapshotTaken = true;
|
|
3562
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4336
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3563
4337
|
const snapshot = await this.getAriaSnapshot();
|
|
3564
4338
|
if (snapshot) {
|
|
3565
4339
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
3566
4340
|
}
|
|
3567
4341
|
}
|
|
3568
4342
|
}
|
|
4343
|
+
this.context.routeResults = null;
|
|
4344
|
+
await registerBeforeStepRoutes(this.context, this.stepName);
|
|
4345
|
+
networkBeforeStep(this.stepName);
|
|
3569
4346
|
}
|
|
3570
4347
|
async getAriaSnapshot() {
|
|
3571
4348
|
try {
|
|
@@ -3585,12 +4362,18 @@ class StableBrowser {
|
|
|
3585
4362
|
try {
|
|
3586
4363
|
// Ensure frame is attached and has body
|
|
3587
4364
|
const body = frame.locator("body");
|
|
3588
|
-
await body.waitFor({ timeout:
|
|
4365
|
+
//await body.waitFor({ timeout: 2000 }); // wait explicitly
|
|
3589
4366
|
const snapshot = await body.ariaSnapshot({ timeout });
|
|
4367
|
+
if (!snapshot) {
|
|
4368
|
+
continue;
|
|
4369
|
+
}
|
|
3590
4370
|
content.push(`- frame: ${i}`);
|
|
3591
4371
|
content.push(snapshot);
|
|
3592
4372
|
}
|
|
3593
|
-
catch (innerErr) {
|
|
4373
|
+
catch (innerErr) {
|
|
4374
|
+
console.warn(`Frame ${i} snapshot failed:`, innerErr);
|
|
4375
|
+
content.push(`- frame: ${i} - error: ${innerErr.message}`);
|
|
4376
|
+
}
|
|
3594
4377
|
}
|
|
3595
4378
|
return content.join("\n");
|
|
3596
4379
|
}
|
|
@@ -3600,6 +4383,49 @@ class StableBrowser {
|
|
|
3600
4383
|
}
|
|
3601
4384
|
return null;
|
|
3602
4385
|
}
|
|
4386
|
+
/**
|
|
4387
|
+
* Sends command with custom payload to report.
|
|
4388
|
+
* @param commandText - Title of the command to be shown in the report.
|
|
4389
|
+
* @param commandStatus - Status of the command (e.g. "PASSED", "FAILED").
|
|
4390
|
+
* @param content - Content of the command to be shown in the report.
|
|
4391
|
+
* @param options - Options for the command. Example: { type: "json", screenshot: true }
|
|
4392
|
+
* @param world - Optional world context.
|
|
4393
|
+
* @public
|
|
4394
|
+
*/
|
|
4395
|
+
async addCommandToReport(commandText, commandStatus, content, options = {}, world = null) {
|
|
4396
|
+
const state = {
|
|
4397
|
+
options,
|
|
4398
|
+
world,
|
|
4399
|
+
locate: false,
|
|
4400
|
+
scroll: false,
|
|
4401
|
+
screenshot: options.screenshot ?? false,
|
|
4402
|
+
highlight: options.highlight ?? false,
|
|
4403
|
+
type: Types.REPORT_COMMAND,
|
|
4404
|
+
text: commandText,
|
|
4405
|
+
_text: commandText,
|
|
4406
|
+
operation: "report_command",
|
|
4407
|
+
log: "***** " + commandText + " *****\n",
|
|
4408
|
+
};
|
|
4409
|
+
try {
|
|
4410
|
+
await _preCommand(state, this);
|
|
4411
|
+
const payload = {
|
|
4412
|
+
type: options.type ?? "text",
|
|
4413
|
+
content: content,
|
|
4414
|
+
screenshotId: null,
|
|
4415
|
+
};
|
|
4416
|
+
state.payload = payload;
|
|
4417
|
+
if (commandStatus === "FAILED") {
|
|
4418
|
+
state.throwError = true;
|
|
4419
|
+
throw new Error("Command failed");
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
catch (e) {
|
|
4423
|
+
await _commandError(state, e, this);
|
|
4424
|
+
}
|
|
4425
|
+
finally {
|
|
4426
|
+
await _commandFinally(state, this);
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
3603
4429
|
async afterStep(world, step) {
|
|
3604
4430
|
this.stepName = null;
|
|
3605
4431
|
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
@@ -3619,13 +4445,43 @@ class StableBrowser {
|
|
|
3619
4445
|
if (this.context) {
|
|
3620
4446
|
this.context.examplesRow = null;
|
|
3621
4447
|
}
|
|
3622
|
-
if (world && world.attach && !process.env.DISABLE_SNAPSHOT) {
|
|
4448
|
+
if (world && world.attach && !process.env.DISABLE_SNAPSHOT && !this.fastMode) {
|
|
3623
4449
|
const snapshot = await this.getAriaSnapshot();
|
|
3624
4450
|
if (snapshot) {
|
|
3625
4451
|
const obj = {};
|
|
3626
4452
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-after");
|
|
3627
4453
|
}
|
|
3628
4454
|
}
|
|
4455
|
+
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4456
|
+
if (this.context.routeResults) {
|
|
4457
|
+
if (world && world.attach) {
|
|
4458
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
if (!process.env.TEMP_RUN) {
|
|
4462
|
+
const state = {
|
|
4463
|
+
world,
|
|
4464
|
+
locate: false,
|
|
4465
|
+
scroll: false,
|
|
4466
|
+
screenshot: true,
|
|
4467
|
+
highlight: true,
|
|
4468
|
+
type: Types.STEP_COMPLETE,
|
|
4469
|
+
text: "end of scenario",
|
|
4470
|
+
_text: "end of scenario",
|
|
4471
|
+
operation: "step_complete",
|
|
4472
|
+
log: "***** " + "end of scenario" + " *****\n",
|
|
4473
|
+
};
|
|
4474
|
+
try {
|
|
4475
|
+
await _preCommand(state, this);
|
|
4476
|
+
}
|
|
4477
|
+
catch (e) {
|
|
4478
|
+
await _commandError(state, e, this);
|
|
4479
|
+
}
|
|
4480
|
+
finally {
|
|
4481
|
+
await _commandFinally(state, this);
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
networkAfterStep(this.stepName);
|
|
3629
4485
|
}
|
|
3630
4486
|
}
|
|
3631
4487
|
function createTimedPromise(promise, label) {
|