automation_model 1.0.784-dev → 1.0.784-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/lib/api.js +28 -11
- package/lib/api.js.map +1 -1
- package/lib/auto_page.js +51 -15
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +81 -48
- 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 +26 -16
- package/lib/command_common.js.map +1 -1
- package/lib/file_checker.js +136 -25
- package/lib/file_checker.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/init_browser.d.ts +1 -2
- package/lib/init_browser.js +122 -126
- package/lib/init_browser.js.map +1 -1
- package/lib/locator_log.js.map +1 -1
- package/lib/network.d.ts +2 -2
- package/lib/network.js +341 -178
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +64 -2
- package/lib/route.js +493 -192
- package/lib/route.js.map +1 -1
- package/lib/scripts/axe.mini.js +23978 -1
- package/lib/snapshot_validation.js +3 -0
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +13 -7
- package/lib/stable_browser.js +470 -113
- package/lib/stable_browser.js.map +1 -1
- package/lib/table_helper.js +14 -0
- package/lib/table_helper.js.map +1 -1
- package/lib/test_context.d.ts +1 -0
- package/lib/test_context.js +1 -0
- package/lib/test_context.js.map +1 -1
- package/lib/utils.d.ts +6 -2
- package/lib/utils.js +121 -14
- package/lib/utils.js.map +1 -1
- package/package.json +18 -11
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,6 +11,7 @@ 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";
|
|
14
|
+
import errorStackParser from "error-stack-parser";
|
|
13
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";
|
|
@@ -26,6 +28,7 @@ import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
|
26
28
|
import { highlightSnapshot, snapshotValidation } from "./snapshot_validation.js";
|
|
27
29
|
import { loadBrunoParams } from "./bruno.js";
|
|
28
30
|
import { registerAfterStepRoutes, registerBeforeStepRoutes } from "./route.js";
|
|
31
|
+
import { existsSync } from "node:fs";
|
|
29
32
|
export const Types = {
|
|
30
33
|
CLICK: "click_element",
|
|
31
34
|
WAIT_ELEMENT: "wait_element",
|
|
@@ -44,6 +47,7 @@ export const Types = {
|
|
|
44
47
|
VERIFY_PAGE_CONTAINS_NO_TEXT: "verify_page_contains_no_text",
|
|
45
48
|
ANALYZE_TABLE: "analyze_table",
|
|
46
49
|
SELECT: "select_combobox", //
|
|
50
|
+
VERIFY_PROPERTY: "verify_element_property",
|
|
47
51
|
VERIFY_PAGE_PATH: "verify_page_path",
|
|
48
52
|
VERIFY_PAGE_TITLE: "verify_page_title",
|
|
49
53
|
TYPE_PRESS: "type_press",
|
|
@@ -62,12 +66,11 @@ export const Types = {
|
|
|
62
66
|
SET_INPUT: "set_input",
|
|
63
67
|
WAIT_FOR_TEXT_TO_DISAPPEAR: "wait_for_text_to_disappear",
|
|
64
68
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
65
|
-
VERIFY_PROPERTY: "verify_element_property",
|
|
66
69
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
67
70
|
BRUNO: "bruno",
|
|
68
|
-
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
69
71
|
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
70
72
|
SET_INPUT_FILES: "set_input_files",
|
|
73
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
71
74
|
REPORT_COMMAND: "report_command",
|
|
72
75
|
STEP_COMPLETE: "step_complete",
|
|
73
76
|
SLEEP: "sleep",
|
|
@@ -84,6 +87,7 @@ class StableBrowser {
|
|
|
84
87
|
context;
|
|
85
88
|
world;
|
|
86
89
|
fastMode;
|
|
90
|
+
stepTags;
|
|
87
91
|
project_path = null;
|
|
88
92
|
webLogFile = null;
|
|
89
93
|
networkLogger = null;
|
|
@@ -92,13 +96,17 @@ class StableBrowser {
|
|
|
92
96
|
tags = null;
|
|
93
97
|
isRecording = false;
|
|
94
98
|
initSnapshotTaken = false;
|
|
95
|
-
|
|
99
|
+
onlyFailuresScreenshot = process.env.SCREENSHOT_ON_FAILURE_ONLY === "true";
|
|
100
|
+
// set to true if the step issue a report
|
|
101
|
+
inStepReport = false;
|
|
102
|
+
constructor(browser, page, logger = null, context = null, world = null, fastMode = false, stepTags = []) {
|
|
96
103
|
this.browser = browser;
|
|
97
104
|
this.page = page;
|
|
98
105
|
this.logger = logger;
|
|
99
106
|
this.context = context;
|
|
100
107
|
this.world = world;
|
|
101
108
|
this.fastMode = fastMode;
|
|
109
|
+
this.stepTags = stepTags;
|
|
102
110
|
if (!this.logger) {
|
|
103
111
|
this.logger = console;
|
|
104
112
|
}
|
|
@@ -131,7 +139,7 @@ class StableBrowser {
|
|
|
131
139
|
this.fastMode = true;
|
|
132
140
|
}
|
|
133
141
|
if (process.env.FAST_MODE === "true") {
|
|
134
|
-
console.log("Fast mode enabled from environment variable");
|
|
142
|
+
// console.log("Fast mode enabled from environment variable");
|
|
135
143
|
this.fastMode = true;
|
|
136
144
|
}
|
|
137
145
|
if (process.env.FAST_MODE === "false") {
|
|
@@ -174,6 +182,7 @@ class StableBrowser {
|
|
|
174
182
|
registerNetworkEvents(this.world, this, context, this.page);
|
|
175
183
|
registerDownloadEvent(this.page, this.world, context);
|
|
176
184
|
page.on("close", async () => {
|
|
185
|
+
// return if browser context is already closed
|
|
177
186
|
if (this.context && this.context.pages && this.context.pages.length > 1) {
|
|
178
187
|
this.context.pages.pop();
|
|
179
188
|
this.page = this.context.pages[this.context.pages.length - 1];
|
|
@@ -183,7 +192,12 @@ class StableBrowser {
|
|
|
183
192
|
console.log("Switched to page " + title);
|
|
184
193
|
}
|
|
185
194
|
catch (error) {
|
|
186
|
-
|
|
195
|
+
if (error?.message?.includes("Target page, context or browser has been closed")) {
|
|
196
|
+
// Ignore this error
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.error("Error on page close", error);
|
|
200
|
+
}
|
|
187
201
|
}
|
|
188
202
|
}
|
|
189
203
|
});
|
|
@@ -192,7 +206,12 @@ class StableBrowser {
|
|
|
192
206
|
console.log("Switch page: " + (await page.title()));
|
|
193
207
|
}
|
|
194
208
|
catch (e) {
|
|
195
|
-
|
|
209
|
+
if (e?.message?.includes("Target page, context or browser has been closed")) {
|
|
210
|
+
// Ignore this error
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.logger.error("error on page load " + e);
|
|
214
|
+
}
|
|
196
215
|
}
|
|
197
216
|
context.pageLoading.status = false;
|
|
198
217
|
}.bind(this));
|
|
@@ -220,7 +239,7 @@ class StableBrowser {
|
|
|
220
239
|
if (newContextCreated) {
|
|
221
240
|
this.registerEventListeners(this.context);
|
|
222
241
|
await this.goto(this.context.environment.baseUrl);
|
|
223
|
-
if (!this.fastMode) {
|
|
242
|
+
if (!this.fastMode && !this.stepTags.includes("fast-mode")) {
|
|
224
243
|
await this.waitForPageLoad();
|
|
225
244
|
}
|
|
226
245
|
}
|
|
@@ -312,7 +331,7 @@ class StableBrowser {
|
|
|
312
331
|
// async closeUnexpectedPopups() {
|
|
313
332
|
// await closeUnexpectedPopups(this.page);
|
|
314
333
|
// }
|
|
315
|
-
async goto(url, world = null) {
|
|
334
|
+
async goto(url, world = null, options = {}) {
|
|
316
335
|
if (!url) {
|
|
317
336
|
throw new Error("url is null, verify that the environment file is correct");
|
|
318
337
|
}
|
|
@@ -333,10 +352,14 @@ class StableBrowser {
|
|
|
333
352
|
screenshot: false,
|
|
334
353
|
highlight: false,
|
|
335
354
|
};
|
|
355
|
+
let timeout = 60000;
|
|
356
|
+
if (options && options["timeout"]) {
|
|
357
|
+
timeout = options["timeout"];
|
|
358
|
+
}
|
|
336
359
|
try {
|
|
337
360
|
await _preCommand(state, this);
|
|
338
361
|
await this.page.goto(url, {
|
|
339
|
-
timeout:
|
|
362
|
+
timeout: timeout,
|
|
340
363
|
});
|
|
341
364
|
await _screenshot(state, this);
|
|
342
365
|
}
|
|
@@ -504,12 +527,6 @@ class StableBrowser {
|
|
|
504
527
|
if (!el.setAttribute) {
|
|
505
528
|
el = el.parentElement;
|
|
506
529
|
}
|
|
507
|
-
// remove any attributes start with data-blinq-id
|
|
508
|
-
// for (let i = 0; i < el.attributes.length; i++) {
|
|
509
|
-
// if (el.attributes[i].name.startsWith("data-blinq-id")) {
|
|
510
|
-
// el.removeAttribute(el.attributes[i].name);
|
|
511
|
-
// }
|
|
512
|
-
// }
|
|
513
530
|
el.setAttribute("data-blinq-id-" + randomToken, "");
|
|
514
531
|
return true;
|
|
515
532
|
}, [tag1, randomToken]))) {
|
|
@@ -679,40 +696,186 @@ class StableBrowser {
|
|
|
679
696
|
}
|
|
680
697
|
return { rerun: false };
|
|
681
698
|
}
|
|
699
|
+
getFilePath() {
|
|
700
|
+
const stackFrames = errorStackParser.parse(new Error());
|
|
701
|
+
const mjsFrames = stackFrames.filter((frame) => frame.fileName && frame.fileName.endsWith(".mjs"));
|
|
702
|
+
const stackFrame = mjsFrames[mjsFrames.length - 2];
|
|
703
|
+
const filepath = stackFrame?.fileName;
|
|
704
|
+
if (filepath) {
|
|
705
|
+
let jsonFilePath = filepath.replace(".mjs", ".json");
|
|
706
|
+
if (existsSync(jsonFilePath)) {
|
|
707
|
+
return jsonFilePath;
|
|
708
|
+
}
|
|
709
|
+
const config = this.configuration ?? {};
|
|
710
|
+
if (!config?.locatorsMetadataDir) {
|
|
711
|
+
config.locatorsMetadataDir = "features/step_definitions/locators";
|
|
712
|
+
}
|
|
713
|
+
if (config && config.locatorsMetadataDir) {
|
|
714
|
+
jsonFilePath = path.join(config.locatorsMetadataDir, path.basename(jsonFilePath));
|
|
715
|
+
}
|
|
716
|
+
if (existsSync(jsonFilePath)) {
|
|
717
|
+
return jsonFilePath;
|
|
718
|
+
}
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
getFullElementLocators(selectors, filePath) {
|
|
724
|
+
if (!filePath || !existsSync(filePath)) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
728
|
+
try {
|
|
729
|
+
const allElements = JSON.parse(content);
|
|
730
|
+
const element_key = selectors?.element_key;
|
|
731
|
+
if (element_key && allElements[element_key]) {
|
|
732
|
+
return allElements[element_key];
|
|
733
|
+
}
|
|
734
|
+
for (const elementKey in allElements) {
|
|
735
|
+
const element = allElements[elementKey];
|
|
736
|
+
let foundStrategy = null;
|
|
737
|
+
for (const key in element) {
|
|
738
|
+
if (key === "strategy") {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
const locators = element[key];
|
|
742
|
+
if (!locators || !locators.length) {
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
for (const locator of locators) {
|
|
746
|
+
delete locator.score;
|
|
747
|
+
}
|
|
748
|
+
if (JSON.stringify(locators) === JSON.stringify(selectors.locators)) {
|
|
749
|
+
foundStrategy = key;
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (foundStrategy) {
|
|
754
|
+
return element;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
console.error("Error parsing locators from file: " + filePath, error);
|
|
760
|
+
}
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
682
763
|
async _locate(selectors, info, _params, timeout, allowDisabled = false) {
|
|
683
764
|
if (!timeout) {
|
|
684
765
|
timeout = 30000;
|
|
685
766
|
}
|
|
767
|
+
let element = null;
|
|
768
|
+
let allStrategyLocators = null;
|
|
769
|
+
let selectedStrategy = null;
|
|
770
|
+
if (this.tryAllStrategies) {
|
|
771
|
+
allStrategyLocators = this.getFullElementLocators(selectors, this.getFilePath());
|
|
772
|
+
selectedStrategy = allStrategyLocators?.strategy;
|
|
773
|
+
}
|
|
686
774
|
for (let i = 0; i < 3; i++) {
|
|
687
775
|
info.log += "attempt " + i + ": total locators " + selectors.locators.length + "\n";
|
|
688
776
|
for (let j = 0; j < selectors.locators.length; j++) {
|
|
689
777
|
let selector = selectors.locators[j];
|
|
690
778
|
info.log += "searching for locator " + j + ":" + JSON.stringify(selector) + "\n";
|
|
691
779
|
}
|
|
692
|
-
|
|
780
|
+
if (this.tryAllStrategies && selectedStrategy) {
|
|
781
|
+
const strategyLocators = allStrategyLocators[selectedStrategy];
|
|
782
|
+
let err;
|
|
783
|
+
if (strategyLocators && strategyLocators.length) {
|
|
784
|
+
try {
|
|
785
|
+
selectors.locators = strategyLocators;
|
|
786
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
787
|
+
info.selectedStrategy = selectedStrategy;
|
|
788
|
+
info.log += "element found using strategy " + selectedStrategy + "\n";
|
|
789
|
+
}
|
|
790
|
+
catch (error) {
|
|
791
|
+
err = error;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (!element) {
|
|
795
|
+
for (const key in allStrategyLocators) {
|
|
796
|
+
if (key === "strategy" || key === selectedStrategy) {
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
const strategyLocators = allStrategyLocators[key];
|
|
800
|
+
if (strategyLocators && strategyLocators.length) {
|
|
801
|
+
try {
|
|
802
|
+
info.log += "using strategy " + key + " with locators " + JSON.stringify(strategyLocators) + "\n";
|
|
803
|
+
selectors.locators = strategyLocators;
|
|
804
|
+
element = await this._locate_internal(selectors, info, _params, 10_000, allowDisabled);
|
|
805
|
+
err = null;
|
|
806
|
+
info.selectedStrategy = key;
|
|
807
|
+
info.log += "element found using strategy " + key + "\n";
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
catch (error) {
|
|
811
|
+
err = error;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (err) {
|
|
817
|
+
throw err;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
element = await this._locate_internal(selectors, info, _params, timeout, allowDisabled);
|
|
822
|
+
}
|
|
693
823
|
if (!element.rerun) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
824
|
+
let newElementSelector = "";
|
|
825
|
+
if (this.configuration && this.configuration.stableLocatorStrategy === "csschain") {
|
|
826
|
+
const cssSelector = await element.evaluate((el) => {
|
|
827
|
+
function getCssSelector(el) {
|
|
828
|
+
if (!el || el.nodeType !== 1 || el === document.body)
|
|
829
|
+
return el.tagName.toLowerCase();
|
|
830
|
+
const parent = el.parentElement;
|
|
831
|
+
const tag = el.tagName.toLowerCase();
|
|
832
|
+
// Find the index of the element among its siblings of the same tag
|
|
833
|
+
let index = 1;
|
|
834
|
+
for (let sibling = el.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
|
|
835
|
+
if (sibling.tagName === el.tagName) {
|
|
836
|
+
index++;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// Use nth-child if necessary (i.e., if there's more than one of the same tag)
|
|
840
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === el.tagName);
|
|
841
|
+
const needsNthChild = siblings.length > 1;
|
|
842
|
+
const selector = needsNthChild ? `${tag}:nth-child(${[...parent.children].indexOf(el) + 1})` : tag;
|
|
843
|
+
return getCssSelector(parent) + " > " + selector;
|
|
844
|
+
}
|
|
845
|
+
const cssSelector = getCssSelector(el);
|
|
846
|
+
return cssSelector;
|
|
847
|
+
});
|
|
848
|
+
newElementSelector = cssSelector;
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
const randomToken = "blinq_" + Math.random().toString(36).substring(7);
|
|
852
|
+
if (this.configuration && this.configuration.stableLocatorStrategy === "data-attribute") {
|
|
853
|
+
const dataAttribute = "data-blinq-id";
|
|
854
|
+
await element.evaluate((el, [dataAttribute, randomToken]) => {
|
|
855
|
+
el.setAttribute(dataAttribute, randomToken);
|
|
856
|
+
}, [dataAttribute, randomToken]);
|
|
857
|
+
newElementSelector = `[${dataAttribute}="${randomToken}"]`;
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
// the default case just return the located element
|
|
861
|
+
// will not work for click and type if the locator is placeholder and the placeholder change due to the click event
|
|
862
|
+
return element;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
701
865
|
const scope = element._frame ?? element.page();
|
|
702
|
-
let newElementSelector = "[data-blinq-id-" + randomToken + "]";
|
|
703
866
|
let prefixSelector = "";
|
|
704
867
|
const frameControlSelector = " >> internal:control=enter-frame";
|
|
705
868
|
const frameSelectorIndex = element._selector.lastIndexOf(frameControlSelector);
|
|
706
869
|
if (frameSelectorIndex !== -1) {
|
|
707
870
|
// remove everything after the >> internal:control=enter-frame
|
|
708
871
|
const frameSelector = element._selector.substring(0, frameSelectorIndex);
|
|
709
|
-
prefixSelector = frameSelector + " >> internal:control=enter-frame >>";
|
|
872
|
+
prefixSelector = frameSelector + " >> internal:control=enter-frame >> ";
|
|
710
873
|
}
|
|
711
874
|
// if (element?._frame?._selector) {
|
|
712
875
|
// prefixSelector = element._frame._selector + " >> " + prefixSelector;
|
|
713
876
|
// }
|
|
714
877
|
const newSelector = prefixSelector + newElementSelector;
|
|
715
|
-
return scope.locator(newSelector);
|
|
878
|
+
return scope.locator(newSelector).first();
|
|
716
879
|
}
|
|
717
880
|
}
|
|
718
881
|
throw new Error("unable to locate element " + JSON.stringify(selectors));
|
|
@@ -733,7 +896,7 @@ class StableBrowser {
|
|
|
733
896
|
for (let i = 0; i < frame.selectors.length; i++) {
|
|
734
897
|
let frameLocator = frame.selectors[i];
|
|
735
898
|
if (frameLocator.css) {
|
|
736
|
-
let testframescope = framescope.frameLocator(frameLocator.css);
|
|
899
|
+
let testframescope = framescope.frameLocator(`${frameLocator.css} >> visible=true`);
|
|
737
900
|
if (frameLocator.index) {
|
|
738
901
|
testframescope = framescope.nth(frameLocator.index);
|
|
739
902
|
}
|
|
@@ -811,6 +974,15 @@ class StableBrowser {
|
|
|
811
974
|
});
|
|
812
975
|
}
|
|
813
976
|
async _locate_internal(selectors, info, _params, timeout = 30000, allowDisabled = false) {
|
|
977
|
+
if (selectors.locators && Array.isArray(selectors.locators)) {
|
|
978
|
+
selectors.locators.forEach((locator) => {
|
|
979
|
+
locator.index = locator.index ?? 0;
|
|
980
|
+
locator.visible = locator.visible ?? true;
|
|
981
|
+
if (locator.visible && locator.css && !locator.css.endsWith(">> visible=true")) {
|
|
982
|
+
locator.css = locator.css + " >> visible=true";
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
}
|
|
814
986
|
if (!info) {
|
|
815
987
|
info = {};
|
|
816
988
|
info.failCause = {};
|
|
@@ -823,7 +995,6 @@ class StableBrowser {
|
|
|
823
995
|
let locatorsCount = 0;
|
|
824
996
|
let lazy_scroll = false;
|
|
825
997
|
//let arrayMode = Array.isArray(selectors);
|
|
826
|
-
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
827
998
|
let selectorsLocators = null;
|
|
828
999
|
selectorsLocators = selectors.locators;
|
|
829
1000
|
// group selectors by priority
|
|
@@ -851,6 +1022,7 @@ class StableBrowser {
|
|
|
851
1022
|
let highPriorityOnly = true;
|
|
852
1023
|
let visibleOnly = true;
|
|
853
1024
|
while (true) {
|
|
1025
|
+
let scope = await this._findFrameScope(selectors, timeout, info);
|
|
854
1026
|
locatorsCount = 0;
|
|
855
1027
|
let result = [];
|
|
856
1028
|
let popupResult = await this.closeUnexpectedPopups(info, _params);
|
|
@@ -966,9 +1138,13 @@ class StableBrowser {
|
|
|
966
1138
|
}
|
|
967
1139
|
}
|
|
968
1140
|
if (foundLocators.length === 1) {
|
|
1141
|
+
let box = null;
|
|
1142
|
+
if (!this.onlyFailuresScreenshot) {
|
|
1143
|
+
box = await foundLocators[0].boundingBox();
|
|
1144
|
+
}
|
|
969
1145
|
result.foundElements.push({
|
|
970
1146
|
locator: foundLocators[0],
|
|
971
|
-
box:
|
|
1147
|
+
box: box,
|
|
972
1148
|
unique: true,
|
|
973
1149
|
});
|
|
974
1150
|
result.locatorIndex = i;
|
|
@@ -1123,11 +1299,22 @@ class StableBrowser {
|
|
|
1123
1299
|
operation: "click",
|
|
1124
1300
|
log: "***** click on " + selectors.element_name + " *****\n",
|
|
1125
1301
|
};
|
|
1302
|
+
check_performance("click_all ***", this.context, true);
|
|
1303
|
+
let stepFastMode = this.stepTags.includes("fast-mode");
|
|
1304
|
+
if (stepFastMode) {
|
|
1305
|
+
state.onlyFailuresScreenshot = true;
|
|
1306
|
+
state.scroll = false;
|
|
1307
|
+
state.highlight = false;
|
|
1308
|
+
}
|
|
1126
1309
|
try {
|
|
1310
|
+
check_performance("click_preCommand", this.context, true);
|
|
1127
1311
|
await _preCommand(state, this);
|
|
1312
|
+
check_performance("click_preCommand", this.context, false);
|
|
1128
1313
|
await performAction("click", state.element, options, this, state, _params);
|
|
1129
|
-
if (!this.fastMode) {
|
|
1130
|
-
|
|
1314
|
+
if (!this.fastMode && !this.stepTags.includes("fast-mode")) {
|
|
1315
|
+
check_performance("click_waitForPageLoad", this.context, true);
|
|
1316
|
+
await this.waitForPageLoad({ noSleep: true });
|
|
1317
|
+
check_performance("click_waitForPageLoad", this.context, false);
|
|
1131
1318
|
}
|
|
1132
1319
|
return state.info;
|
|
1133
1320
|
}
|
|
@@ -1135,7 +1322,13 @@ class StableBrowser {
|
|
|
1135
1322
|
await _commandError(state, e, this);
|
|
1136
1323
|
}
|
|
1137
1324
|
finally {
|
|
1325
|
+
check_performance("click_commandFinally", this.context, true);
|
|
1138
1326
|
await _commandFinally(state, this);
|
|
1327
|
+
check_performance("click_commandFinally", this.context, false);
|
|
1328
|
+
check_performance("click_all ***", this.context, false);
|
|
1329
|
+
if (this.context.profile) {
|
|
1330
|
+
console.log(JSON.stringify(this.context.profile, null, 2));
|
|
1331
|
+
}
|
|
1139
1332
|
}
|
|
1140
1333
|
}
|
|
1141
1334
|
async waitForElement(selectors, _params, options = {}, world = null) {
|
|
@@ -1227,7 +1420,7 @@ class StableBrowser {
|
|
|
1227
1420
|
}
|
|
1228
1421
|
}
|
|
1229
1422
|
}
|
|
1230
|
-
await this.waitForPageLoad();
|
|
1423
|
+
//await this.waitForPageLoad();
|
|
1231
1424
|
return state.info;
|
|
1232
1425
|
}
|
|
1233
1426
|
catch (e) {
|
|
@@ -1253,7 +1446,7 @@ class StableBrowser {
|
|
|
1253
1446
|
await _preCommand(state, this);
|
|
1254
1447
|
await performAction("hover", state.element, options, this, state, _params);
|
|
1255
1448
|
await _screenshot(state, this);
|
|
1256
|
-
await this.waitForPageLoad();
|
|
1449
|
+
//await this.waitForPageLoad();
|
|
1257
1450
|
return state.info;
|
|
1258
1451
|
}
|
|
1259
1452
|
catch (e) {
|
|
@@ -1289,7 +1482,7 @@ class StableBrowser {
|
|
|
1289
1482
|
state.info.log += "selectOption failed, will try force" + "\n";
|
|
1290
1483
|
await state.element.selectOption(values, { timeout: 10000, force: true });
|
|
1291
1484
|
}
|
|
1292
|
-
await this.waitForPageLoad();
|
|
1485
|
+
//await this.waitForPageLoad();
|
|
1293
1486
|
return state.info;
|
|
1294
1487
|
}
|
|
1295
1488
|
catch (e) {
|
|
@@ -1475,6 +1668,14 @@ class StableBrowser {
|
|
|
1475
1668
|
}
|
|
1476
1669
|
try {
|
|
1477
1670
|
await _preCommand(state, this);
|
|
1671
|
+
const randomToken = "blinq_" + Math.random().toString(36).substring(7);
|
|
1672
|
+
// tag the element
|
|
1673
|
+
let newElementSelector = await state.element.evaluate((el, token) => {
|
|
1674
|
+
// use attribute and not id
|
|
1675
|
+
const attrName = `data-blinq-id-${token}`;
|
|
1676
|
+
el.setAttribute(attrName, "");
|
|
1677
|
+
return `[${attrName}]`;
|
|
1678
|
+
}, randomToken);
|
|
1478
1679
|
state.info.value = _value;
|
|
1479
1680
|
if (!options.press) {
|
|
1480
1681
|
try {
|
|
@@ -1500,6 +1701,25 @@ class StableBrowser {
|
|
|
1500
1701
|
}
|
|
1501
1702
|
}
|
|
1502
1703
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1704
|
+
// check if the element exist after the click (no wait)
|
|
1705
|
+
const count = await state.element.count({ timeout: 0 });
|
|
1706
|
+
if (count === 0) {
|
|
1707
|
+
// the locator changed after the click (placeholder) we need to locate the element using the data-blinq-id
|
|
1708
|
+
const scope = state.element._frame ?? element.page();
|
|
1709
|
+
let prefixSelector = "";
|
|
1710
|
+
const frameControlSelector = " >> internal:control=enter-frame";
|
|
1711
|
+
const frameSelectorIndex = state.element._selector.lastIndexOf(frameControlSelector);
|
|
1712
|
+
if (frameSelectorIndex !== -1) {
|
|
1713
|
+
// remove everything after the >> internal:control=enter-frame
|
|
1714
|
+
const frameSelector = state.element._selector.substring(0, frameSelectorIndex);
|
|
1715
|
+
prefixSelector = frameSelector + " >> internal:control=enter-frame >> ";
|
|
1716
|
+
}
|
|
1717
|
+
// if (element?._frame?._selector) {
|
|
1718
|
+
// prefixSelector = element._frame._selector + " >> " + prefixSelector;
|
|
1719
|
+
// }
|
|
1720
|
+
const newSelector = prefixSelector + newElementSelector;
|
|
1721
|
+
state.element = scope.locator(newSelector).first();
|
|
1722
|
+
}
|
|
1503
1723
|
const valueSegment = state.value.split("&&");
|
|
1504
1724
|
for (let i = 0; i < valueSegment.length; i++) {
|
|
1505
1725
|
if (i > 0) {
|
|
@@ -1571,8 +1791,8 @@ class StableBrowser {
|
|
|
1571
1791
|
if (enter) {
|
|
1572
1792
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1573
1793
|
await this.page.keyboard.press("Enter");
|
|
1794
|
+
await this.waitForPageLoad();
|
|
1574
1795
|
}
|
|
1575
|
-
await this.waitForPageLoad();
|
|
1576
1796
|
return state.info;
|
|
1577
1797
|
}
|
|
1578
1798
|
catch (e) {
|
|
@@ -1831,11 +2051,12 @@ class StableBrowser {
|
|
|
1831
2051
|
throw new Error("referanceSnapshot is null");
|
|
1832
2052
|
}
|
|
1833
2053
|
let text = null;
|
|
1834
|
-
|
|
1835
|
-
|
|
2054
|
+
const snapshotsFolder = process.env.BVT_TEMP_SNAPSHOTS_FOLDER ?? this.context.snapshotFolder; //path .join(this.project_path, "data", "snapshots");
|
|
2055
|
+
if (fs.existsSync(path.join(snapshotsFolder, referanceSnapshot + ".yml"))) {
|
|
2056
|
+
text = fs.readFileSync(path.join(snapshotsFolder, referanceSnapshot + ".yml"), "utf8");
|
|
1836
2057
|
}
|
|
1837
|
-
else if (fs.existsSync(path.join(
|
|
1838
|
-
text = fs.readFileSync(path.join(
|
|
2058
|
+
else if (fs.existsSync(path.join(snapshotsFolder, referanceSnapshot + ".yaml"))) {
|
|
2059
|
+
text = fs.readFileSync(path.join(snapshotsFolder, referanceSnapshot + ".yaml"), "utf8");
|
|
1839
2060
|
}
|
|
1840
2061
|
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1841
2062
|
text = referanceSnapshot.substring(5);
|
|
@@ -1859,7 +2080,13 @@ class StableBrowser {
|
|
|
1859
2080
|
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1860
2081
|
}
|
|
1861
2082
|
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
2083
|
+
if (snapshot && snapshot.length <= 10) {
|
|
2084
|
+
console.log("Page snapshot length is suspiciously small:", snapshot);
|
|
2085
|
+
}
|
|
1862
2086
|
matchResult = snapshotValidation(snapshot, newValue, referanceSnapshot);
|
|
2087
|
+
if (matchResult === undefined) {
|
|
2088
|
+
console.log("snapshotValidation returned undefined");
|
|
2089
|
+
}
|
|
1863
2090
|
if (matchResult.errorLine !== -1) {
|
|
1864
2091
|
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1865
2092
|
}
|
|
@@ -2030,6 +2257,9 @@ class StableBrowser {
|
|
|
2030
2257
|
return _getTestData(world, this.context, this);
|
|
2031
2258
|
}
|
|
2032
2259
|
async _screenShot(options = {}, world = null, info = null) {
|
|
2260
|
+
if (!options) {
|
|
2261
|
+
options = {};
|
|
2262
|
+
}
|
|
2033
2263
|
// collect url/path/title
|
|
2034
2264
|
if (info) {
|
|
2035
2265
|
if (!info.title) {
|
|
@@ -2058,7 +2288,7 @@ class StableBrowser {
|
|
|
2058
2288
|
const uuidStr = "id_" + randomUUID();
|
|
2059
2289
|
const screenshotPath = path.join(world.screenshotPath, uuidStr + ".png");
|
|
2060
2290
|
try {
|
|
2061
|
-
await this.takeScreenshot(screenshotPath);
|
|
2291
|
+
await this.takeScreenshot(screenshotPath, options.fullPage === true);
|
|
2062
2292
|
// let buffer = await this.page.screenshot({ timeout: 4000 });
|
|
2063
2293
|
// // save the buffer to the screenshot path asynchrously
|
|
2064
2294
|
// fs.writeFile(screenshotPath, buffer, (err) => {
|
|
@@ -2079,7 +2309,7 @@ class StableBrowser {
|
|
|
2079
2309
|
else if (options && options.screenshot) {
|
|
2080
2310
|
result.screenshotPath = options.screenshotPath;
|
|
2081
2311
|
try {
|
|
2082
|
-
await this.takeScreenshot(options.screenshotPath);
|
|
2312
|
+
await this.takeScreenshot(options.screenshotPath, options.fullPage === true);
|
|
2083
2313
|
// let buffer = await this.page.screenshot({ timeout: 4000 });
|
|
2084
2314
|
// // save the buffer to the screenshot path asynchrously
|
|
2085
2315
|
// fs.writeFile(options.screenshotPath, buffer, (err) => {
|
|
@@ -2097,7 +2327,7 @@ class StableBrowser {
|
|
|
2097
2327
|
}
|
|
2098
2328
|
return result;
|
|
2099
2329
|
}
|
|
2100
|
-
async takeScreenshot(screenshotPath) {
|
|
2330
|
+
async takeScreenshot(screenshotPath, fullPage = false) {
|
|
2101
2331
|
const playContext = this.context.playContext;
|
|
2102
2332
|
// Using CDP to capture the screenshot
|
|
2103
2333
|
const viewportWidth = Math.max(...(await this.page.evaluate(() => [
|
|
@@ -2122,13 +2352,7 @@ class StableBrowser {
|
|
|
2122
2352
|
const client = await playContext.newCDPSession(this.page);
|
|
2123
2353
|
const { data } = await client.send("Page.captureScreenshot", {
|
|
2124
2354
|
format: "png",
|
|
2125
|
-
|
|
2126
|
-
// x: 0,
|
|
2127
|
-
// y: 0,
|
|
2128
|
-
// width: viewportWidth,
|
|
2129
|
-
// height: viewportHeight,
|
|
2130
|
-
// scale: 1,
|
|
2131
|
-
// },
|
|
2355
|
+
captureBeyondViewport: fullPage,
|
|
2132
2356
|
});
|
|
2133
2357
|
await client.detach();
|
|
2134
2358
|
if (!screenshotPath) {
|
|
@@ -2137,7 +2361,7 @@ class StableBrowser {
|
|
|
2137
2361
|
screenshotBuffer = Buffer.from(data, "base64");
|
|
2138
2362
|
}
|
|
2139
2363
|
else {
|
|
2140
|
-
screenshotBuffer = await this.page.screenshot();
|
|
2364
|
+
screenshotBuffer = await this.page.screenshot({ fullPage: fullPage });
|
|
2141
2365
|
}
|
|
2142
2366
|
// if (focusedElement) {
|
|
2143
2367
|
// // console.log(`Focused element ${JSON.stringify(focusedElement._selector)}`)
|
|
@@ -2237,6 +2461,12 @@ class StableBrowser {
|
|
|
2237
2461
|
state.info.value = state.value;
|
|
2238
2462
|
this.setTestData({ [variable]: state.value }, world);
|
|
2239
2463
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2464
|
+
if (process.env.MODE === "executions") {
|
|
2465
|
+
const globalDataFile = "global_test_data.json";
|
|
2466
|
+
if (existsSync(globalDataFile)) {
|
|
2467
|
+
this.saveTestDataAsGlobal({}, world);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2240
2470
|
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2241
2471
|
return state.info;
|
|
2242
2472
|
}
|
|
@@ -2308,6 +2538,12 @@ class StableBrowser {
|
|
|
2308
2538
|
state.info.value = state.value;
|
|
2309
2539
|
this.setTestData({ [variable]: state.value }, world);
|
|
2310
2540
|
this.logger.info("set test data: " + variable + "=" + state.value);
|
|
2541
|
+
if (process.env.MODE === "executions") {
|
|
2542
|
+
const globalDataFile = "global_test_data.json";
|
|
2543
|
+
if (existsSync(globalDataFile)) {
|
|
2544
|
+
this.saveTestDataAsGlobal({}, world);
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2311
2547
|
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2312
2548
|
return state.info;
|
|
2313
2549
|
}
|
|
@@ -2438,7 +2674,7 @@ class StableBrowser {
|
|
|
2438
2674
|
let expectedValue;
|
|
2439
2675
|
try {
|
|
2440
2676
|
await _preCommand(state, this);
|
|
2441
|
-
expectedValue = await
|
|
2677
|
+
expectedValue = await this._replaceWithLocalData(value, world);
|
|
2442
2678
|
state.info.expectedValue = expectedValue;
|
|
2443
2679
|
switch (property) {
|
|
2444
2680
|
case "innerText":
|
|
@@ -2486,47 +2722,54 @@ class StableBrowser {
|
|
|
2486
2722
|
}
|
|
2487
2723
|
state.info.value = val;
|
|
2488
2724
|
let regex;
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
const
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
state.info.failCause.assertionFailed = true;
|
|
2504
|
-
state.info.failCause.lastError = errorMessage;
|
|
2505
|
-
throw new Error(errorMessage);
|
|
2506
|
-
}
|
|
2725
|
+
state.info.value = val;
|
|
2726
|
+
const isRegex = expectedValue.startsWith("regex:");
|
|
2727
|
+
const isContains = expectedValue.startsWith("contains:");
|
|
2728
|
+
const isExact = expectedValue.startsWith("exact:");
|
|
2729
|
+
let matchPassed = false;
|
|
2730
|
+
if (isRegex) {
|
|
2731
|
+
const rawPattern = expectedValue.slice(6); // remove "regex:"
|
|
2732
|
+
const lastSlashIndex = rawPattern.lastIndexOf("/");
|
|
2733
|
+
if (rawPattern.startsWith("/") && lastSlashIndex > 0) {
|
|
2734
|
+
const patternBody = rawPattern.slice(1, lastSlashIndex).replace(/\n/g, ".*");
|
|
2735
|
+
const flags = rawPattern.slice(lastSlashIndex + 1) || "gs";
|
|
2736
|
+
const regex = new RegExp(patternBody, flags);
|
|
2737
|
+
state.info.regex = true;
|
|
2738
|
+
matchPassed = regex.test(val);
|
|
2507
2739
|
}
|
|
2508
2740
|
else {
|
|
2509
|
-
//
|
|
2510
|
-
const
|
|
2511
|
-
const
|
|
2512
|
-
|
|
2513
|
-
// Check if all expected lines are present in the actual lines
|
|
2514
|
-
const isPart = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2515
|
-
if (!isPart) {
|
|
2516
|
-
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2517
|
-
state.info.failCause.assertionFailed = true;
|
|
2518
|
-
state.info.failCause.lastError = errorMessage;
|
|
2519
|
-
throw new Error(errorMessage);
|
|
2520
|
-
}
|
|
2741
|
+
// Fallback: treat as literal
|
|
2742
|
+
const escapedPattern = rawPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2743
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2744
|
+
matchPassed = regex.test(val);
|
|
2521
2745
|
}
|
|
2522
2746
|
}
|
|
2747
|
+
else if (isContains) {
|
|
2748
|
+
const containsValue = expectedValue.slice(9); // remove "contains:"
|
|
2749
|
+
matchPassed = val.includes(containsValue);
|
|
2750
|
+
}
|
|
2751
|
+
else if (isExact) {
|
|
2752
|
+
const exactValue = expectedValue.slice(6); // remove "exact:"
|
|
2753
|
+
matchPassed = val === exactValue;
|
|
2754
|
+
}
|
|
2755
|
+
else if (property === "innerText") {
|
|
2756
|
+
// Default innerText logic
|
|
2757
|
+
const normalizedExpectedValue = expectedValue.replace(/\\n/g, "\n");
|
|
2758
|
+
const valLines = val.split("\n");
|
|
2759
|
+
const expectedLines = normalizedExpectedValue.split("\n");
|
|
2760
|
+
matchPassed = expectedLines.every((expectedLine) => valLines.some((valLine) => valLine.trim() === expectedLine.trim()));
|
|
2761
|
+
}
|
|
2523
2762
|
else {
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2763
|
+
// Fallback exact or loose match
|
|
2764
|
+
const escapedPattern = expectedValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2765
|
+
const regex = new RegExp(escapedPattern, "g");
|
|
2766
|
+
matchPassed = regex.test(val);
|
|
2767
|
+
}
|
|
2768
|
+
if (!matchPassed) {
|
|
2769
|
+
let errorMessage = `The ${property} property has a value of "${val}", but the expected value is "${expectedValue}"`;
|
|
2770
|
+
state.info.failCause.assertionFailed = true;
|
|
2771
|
+
state.info.failCause.lastError = errorMessage;
|
|
2772
|
+
throw new Error(errorMessage);
|
|
2530
2773
|
}
|
|
2531
2774
|
return state.info;
|
|
2532
2775
|
}
|
|
@@ -2557,6 +2800,7 @@ class StableBrowser {
|
|
|
2557
2800
|
allowDisabled: true,
|
|
2558
2801
|
info: {},
|
|
2559
2802
|
};
|
|
2803
|
+
state.options ??= { timeout: timeoutMs };
|
|
2560
2804
|
// Initialize startTime outside try block to ensure it's always accessible
|
|
2561
2805
|
const startTime = Date.now();
|
|
2562
2806
|
let conditionMet = false;
|
|
@@ -2726,6 +2970,12 @@ class StableBrowser {
|
|
|
2726
2970
|
emailUrl = url;
|
|
2727
2971
|
codeOrUrlFound = true;
|
|
2728
2972
|
}
|
|
2973
|
+
if (process.env.MODE === "executions") {
|
|
2974
|
+
const globalDataFile = "global_test_data.json";
|
|
2975
|
+
if (existsSync(globalDataFile)) {
|
|
2976
|
+
this.saveTestDataAsGlobal({}, world);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2729
2979
|
if (codeOrUrlFound) {
|
|
2730
2980
|
return { emailUrl, emailCode };
|
|
2731
2981
|
}
|
|
@@ -3132,7 +3382,16 @@ class StableBrowser {
|
|
|
3132
3382
|
text = text.replace(/\\"/g, '"');
|
|
3133
3383
|
}
|
|
3134
3384
|
const timeout = this._getFindElementTimeout(options);
|
|
3135
|
-
|
|
3385
|
+
//if (!this.fastMode && !this.stepTags.includes("fast-mode")) {
|
|
3386
|
+
let stepFastMode = this.stepTags.includes("fast-mode");
|
|
3387
|
+
if (!stepFastMode) {
|
|
3388
|
+
if (!this.fastMode) {
|
|
3389
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
3390
|
+
}
|
|
3391
|
+
else {
|
|
3392
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3136
3395
|
const newValue = await this._replaceWithLocalData(text, world);
|
|
3137
3396
|
if (newValue !== text) {
|
|
3138
3397
|
this.logger.info(text + "=" + newValue);
|
|
@@ -3140,6 +3399,11 @@ class StableBrowser {
|
|
|
3140
3399
|
}
|
|
3141
3400
|
let dateAlternatives = findDateAlternatives(text);
|
|
3142
3401
|
let numberAlternatives = findNumberAlternatives(text);
|
|
3402
|
+
if (stepFastMode) {
|
|
3403
|
+
state.onlyFailuresScreenshot = true;
|
|
3404
|
+
state.scroll = false;
|
|
3405
|
+
state.highlight = false;
|
|
3406
|
+
}
|
|
3143
3407
|
try {
|
|
3144
3408
|
await _preCommand(state, this);
|
|
3145
3409
|
state.info.text = text;
|
|
@@ -3259,6 +3523,8 @@ class StableBrowser {
|
|
|
3259
3523
|
operation: "verify_text_with_relation",
|
|
3260
3524
|
log: "***** search for " + textAnchor + " climb " + climb + " and verify " + textToVerify + " found *****\n",
|
|
3261
3525
|
};
|
|
3526
|
+
const cmdStartTime = Date.now();
|
|
3527
|
+
let cmdEndTime = null;
|
|
3262
3528
|
const timeout = this._getFindElementTimeout(options);
|
|
3263
3529
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
3264
3530
|
let newValue = await this._replaceWithLocalData(textAnchor, world);
|
|
@@ -3294,6 +3560,17 @@ class StableBrowser {
|
|
|
3294
3560
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
3295
3561
|
continue;
|
|
3296
3562
|
}
|
|
3563
|
+
else {
|
|
3564
|
+
cmdEndTime = Date.now();
|
|
3565
|
+
if (cmdEndTime - cmdStartTime > 55000) {
|
|
3566
|
+
if (foundAncore) {
|
|
3567
|
+
throw new Error(`Text ${textToVerify} not found in page`);
|
|
3568
|
+
}
|
|
3569
|
+
else {
|
|
3570
|
+
throw new Error(`Text ${textAnchor} not found in page`);
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3297
3574
|
try {
|
|
3298
3575
|
for (let i = 0; i < resultWithElementsFound.length; i++) {
|
|
3299
3576
|
foundAncore = true;
|
|
@@ -3432,7 +3709,7 @@ class StableBrowser {
|
|
|
3432
3709
|
Object.assign(e, { info: info });
|
|
3433
3710
|
error = e;
|
|
3434
3711
|
// throw e;
|
|
3435
|
-
await _commandError({ text: "visualVerification", operation: "visualVerification",
|
|
3712
|
+
await _commandError({ text: "visualVerification", operation: "visualVerification", info }, e, this);
|
|
3436
3713
|
}
|
|
3437
3714
|
finally {
|
|
3438
3715
|
const endTime = Date.now();
|
|
@@ -3781,6 +4058,22 @@ class StableBrowser {
|
|
|
3781
4058
|
}
|
|
3782
4059
|
}
|
|
3783
4060
|
async waitForPageLoad(options = {}, world = null) {
|
|
4061
|
+
// try {
|
|
4062
|
+
// let currentPagePath = null;
|
|
4063
|
+
// currentPagePath = new URL(this.page.url()).pathname;
|
|
4064
|
+
// if (this.latestPagePath) {
|
|
4065
|
+
// // get the currect page path and compare with the latest page path
|
|
4066
|
+
// if (this.latestPagePath === currentPagePath) {
|
|
4067
|
+
// // if the page path is the same, do not wait for page load
|
|
4068
|
+
// console.log("No page change: " + currentPagePath);
|
|
4069
|
+
// return;
|
|
4070
|
+
// }
|
|
4071
|
+
// }
|
|
4072
|
+
// this.latestPagePath = currentPagePath;
|
|
4073
|
+
// } catch (e) {
|
|
4074
|
+
// console.debug("Error getting current page path: ", e);
|
|
4075
|
+
// }
|
|
4076
|
+
//console.log("Waiting for page load");
|
|
3784
4077
|
let timeout = this._getLoadTimeout(options);
|
|
3785
4078
|
const promiseArray = [];
|
|
3786
4079
|
// let waitForNetworkIdle = true;
|
|
@@ -3815,7 +4108,10 @@ class StableBrowser {
|
|
|
3815
4108
|
}
|
|
3816
4109
|
}
|
|
3817
4110
|
finally {
|
|
3818
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
4111
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
4112
|
+
if (options && !options.noSleep) {
|
|
4113
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
4114
|
+
}
|
|
3819
4115
|
({ screenshotId, screenshotPath } = await this._screenShot(options, world));
|
|
3820
4116
|
const endTime = Date.now();
|
|
3821
4117
|
_reportToWorld(world, {
|
|
@@ -3869,7 +4165,7 @@ class StableBrowser {
|
|
|
3869
4165
|
}
|
|
3870
4166
|
operation = options.operation;
|
|
3871
4167
|
// validate operation is one of the supported operations
|
|
3872
|
-
if (operation != "click" && operation != "hover+click") {
|
|
4168
|
+
if (operation != "click" && operation != "hover+click" && operation != "hover") {
|
|
3873
4169
|
throw new Error("operation is not supported");
|
|
3874
4170
|
}
|
|
3875
4171
|
const state = {
|
|
@@ -3938,6 +4234,17 @@ class StableBrowser {
|
|
|
3938
4234
|
state.element = results[0];
|
|
3939
4235
|
await performAction("hover+click", state.element, options, this, state, _params);
|
|
3940
4236
|
break;
|
|
4237
|
+
case "hover":
|
|
4238
|
+
if (!options.css) {
|
|
4239
|
+
throw new Error("css is not defined");
|
|
4240
|
+
}
|
|
4241
|
+
const result1 = await findElementsInArea(options.css, cellArea, this, options);
|
|
4242
|
+
if (result1.length === 0) {
|
|
4243
|
+
throw new Error(`Element not found in cell area`);
|
|
4244
|
+
}
|
|
4245
|
+
state.element = result1[0];
|
|
4246
|
+
await performAction("hover", state.element, options, this, state, _params);
|
|
4247
|
+
break;
|
|
3941
4248
|
default:
|
|
3942
4249
|
throw new Error("operation is not supported");
|
|
3943
4250
|
}
|
|
@@ -3951,6 +4258,12 @@ class StableBrowser {
|
|
|
3951
4258
|
}
|
|
3952
4259
|
saveTestDataAsGlobal(options, world) {
|
|
3953
4260
|
const dataFile = _getDataFile(world, this.context, this);
|
|
4261
|
+
if (process.env.MODE === "executions") {
|
|
4262
|
+
const globalDataFile = path.join(this.project_path, "global_test_data.json");
|
|
4263
|
+
fs.copyFileSync(dataFile, globalDataFile);
|
|
4264
|
+
this.logger.info("Save the scenario test data to " + globalDataFile + " as global for the following scenarios.");
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
3954
4267
|
process.env.GLOBAL_TEST_DATA_FILE = dataFile;
|
|
3955
4268
|
this.logger.info("Save the scenario test data as global for the following scenarios.");
|
|
3956
4269
|
}
|
|
@@ -4053,6 +4366,7 @@ class StableBrowser {
|
|
|
4053
4366
|
if (world && world.attach) {
|
|
4054
4367
|
world.attach(this.context.reportFolder, { mediaType: "text/plain" });
|
|
4055
4368
|
}
|
|
4369
|
+
this.context.loadedRoutes = null;
|
|
4056
4370
|
this.beforeScenarioCalled = true;
|
|
4057
4371
|
if (scenario && scenario.pickle && scenario.pickle.name) {
|
|
4058
4372
|
this.scenarioName = scenario.pickle.name;
|
|
@@ -4079,11 +4393,32 @@ class StableBrowser {
|
|
|
4079
4393
|
await getTestData(envName, world, undefined, this.featureName, this.scenarioName, this.context);
|
|
4080
4394
|
}
|
|
4081
4395
|
await loadBrunoParams(this.context, this.context.environment.name);
|
|
4396
|
+
if ((process.env.TRACE === "true" || this.configuration.trace === true) && this.context) {
|
|
4397
|
+
this.trace = true;
|
|
4398
|
+
const traceFolder = path.join(this.context.reportFolder, "trace");
|
|
4399
|
+
if (!fs.existsSync(traceFolder)) {
|
|
4400
|
+
fs.mkdirSync(traceFolder, { recursive: true });
|
|
4401
|
+
}
|
|
4402
|
+
this.traceFolder = traceFolder;
|
|
4403
|
+
await this.context.playContext.tracing.start({ screenshots: true, snapshots: true });
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
async afterScenario(world, scenario) {
|
|
4407
|
+
const id = scenario.testCaseStartedId;
|
|
4408
|
+
if (this.trace) {
|
|
4409
|
+
await this.context.playContext.tracing.stop({
|
|
4410
|
+
path: path.join(this.traceFolder, `trace-${id}.zip`),
|
|
4411
|
+
});
|
|
4412
|
+
}
|
|
4082
4413
|
}
|
|
4083
|
-
async afterScenario(world, scenario) { }
|
|
4084
4414
|
async beforeStep(world, step) {
|
|
4415
|
+
if (step?.pickleStep && this.trace) {
|
|
4416
|
+
await this.context.playContext.tracing.group(`Step: ${step.pickleStep.text}`);
|
|
4417
|
+
}
|
|
4418
|
+
this.stepTags = [];
|
|
4085
4419
|
if (!this.beforeScenarioCalled) {
|
|
4086
4420
|
this.beforeScenario(world, step);
|
|
4421
|
+
this.context.loadedRoutes = null;
|
|
4087
4422
|
}
|
|
4088
4423
|
if (this.stepIndex === undefined) {
|
|
4089
4424
|
this.stepIndex = 0;
|
|
@@ -4093,7 +4428,12 @@ class StableBrowser {
|
|
|
4093
4428
|
}
|
|
4094
4429
|
if (step && step.pickleStep && step.pickleStep.text) {
|
|
4095
4430
|
this.stepName = step.pickleStep.text;
|
|
4096
|
-
|
|
4431
|
+
let printableStepName = this.stepName;
|
|
4432
|
+
// take the printableStepName and replace quated value with \x1b[33m and \x1b[0m
|
|
4433
|
+
printableStepName = printableStepName.replace(/"([^"]*)"/g, (match, p1) => {
|
|
4434
|
+
return `\x1b[33m"${p1}"\x1b[0m`;
|
|
4435
|
+
});
|
|
4436
|
+
this.logger.info("\x1b[38;5;208mstep:\x1b[0m " + printableStepName);
|
|
4097
4437
|
}
|
|
4098
4438
|
else if (step && step.text) {
|
|
4099
4439
|
this.stepName = step.text;
|
|
@@ -4108,7 +4448,10 @@ class StableBrowser {
|
|
|
4108
4448
|
}
|
|
4109
4449
|
if (this.initSnapshotTaken === false) {
|
|
4110
4450
|
this.initSnapshotTaken = true;
|
|
4111
|
-
if (world &&
|
|
4451
|
+
if (world &&
|
|
4452
|
+
world.attach &&
|
|
4453
|
+
!process.env.DISABLE_SNAPSHOT &&
|
|
4454
|
+
(!this.fastMode || this.stepTags.includes("fast-mode"))) {
|
|
4112
4455
|
const snapshot = await this.getAriaSnapshot();
|
|
4113
4456
|
if (snapshot) {
|
|
4114
4457
|
await world.attach(JSON.stringify(snapshot), "application/json+snapshot-before");
|
|
@@ -4118,7 +4461,11 @@ class StableBrowser {
|
|
|
4118
4461
|
this.context.routeResults = null;
|
|
4119
4462
|
this.context.loadedRoutes = null;
|
|
4120
4463
|
await registerBeforeStepRoutes(this.context, this.stepName, world);
|
|
4121
|
-
networkBeforeStep(this.stepName);
|
|
4464
|
+
networkBeforeStep(this.stepName, this.context);
|
|
4465
|
+
this.inStepReport = false;
|
|
4466
|
+
}
|
|
4467
|
+
setStepTags(tags) {
|
|
4468
|
+
this.stepTags = tags;
|
|
4122
4469
|
}
|
|
4123
4470
|
async getAriaSnapshot() {
|
|
4124
4471
|
try {
|
|
@@ -4192,7 +4539,7 @@ class StableBrowser {
|
|
|
4192
4539
|
state.payload = payload;
|
|
4193
4540
|
if (commandStatus === "FAILED") {
|
|
4194
4541
|
state.throwError = true;
|
|
4195
|
-
throw new Error(
|
|
4542
|
+
throw new Error(commandText);
|
|
4196
4543
|
}
|
|
4197
4544
|
}
|
|
4198
4545
|
catch (e) {
|
|
@@ -4202,26 +4549,22 @@ class StableBrowser {
|
|
|
4202
4549
|
await _commandFinally(state, this);
|
|
4203
4550
|
}
|
|
4204
4551
|
}
|
|
4205
|
-
async afterStep(world, step) {
|
|
4552
|
+
async afterStep(world, step, result) {
|
|
4206
4553
|
this.stepName = null;
|
|
4207
|
-
if (this.context && this.context.browserObject && this.context.browserObject.trace === true) {
|
|
4208
|
-
if (this.context.browserObject.context) {
|
|
4209
|
-
await this.context.browserObject.context.tracing.stopChunk({
|
|
4210
|
-
path: path.join(this.context.browserObject.traceFolder, `trace-${this.stepIndex}.zip`),
|
|
4211
|
-
});
|
|
4212
|
-
if (world && world.attach) {
|
|
4213
|
-
await world.attach(JSON.stringify({
|
|
4214
|
-
type: "trace",
|
|
4215
|
-
traceFilePath: `trace-${this.stepIndex}.zip`,
|
|
4216
|
-
}), "application/json+trace");
|
|
4217
|
-
}
|
|
4218
|
-
// console.log("trace file created", `trace-${this.stepIndex}.zip`);
|
|
4219
|
-
}
|
|
4220
|
-
}
|
|
4221
4554
|
if (this.context) {
|
|
4222
4555
|
this.context.examplesRow = null;
|
|
4223
4556
|
}
|
|
4224
|
-
if (
|
|
4557
|
+
if (!this.inStepReport) {
|
|
4558
|
+
// check the step result
|
|
4559
|
+
if (result && result.status === "FAILED" && world && world.attach) {
|
|
4560
|
+
await this.addCommandToReport(result.message ? result.message : "Step failed", "FAILED", `${result.message}`, { type: "text", screenshot: true }, world);
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
if (world &&
|
|
4564
|
+
world.attach &&
|
|
4565
|
+
!process.env.DISABLE_SNAPSHOT &&
|
|
4566
|
+
!this.fastMode &&
|
|
4567
|
+
!this.stepTags.includes("fast-mode")) {
|
|
4225
4568
|
const snapshot = await this.getAriaSnapshot();
|
|
4226
4569
|
if (snapshot) {
|
|
4227
4570
|
const obj = {};
|
|
@@ -4229,6 +4572,11 @@ class StableBrowser {
|
|
|
4229
4572
|
}
|
|
4230
4573
|
}
|
|
4231
4574
|
this.context.routeResults = await registerAfterStepRoutes(this.context, world);
|
|
4575
|
+
if (this.context.routeResults) {
|
|
4576
|
+
if (world && world.attach) {
|
|
4577
|
+
await world.attach(JSON.stringify(this.context.routeResults), "application/json+intercept-results");
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4232
4580
|
if (!process.env.TEMP_RUN) {
|
|
4233
4581
|
const state = {
|
|
4234
4582
|
world,
|
|
@@ -4252,7 +4600,16 @@ class StableBrowser {
|
|
|
4252
4600
|
await _commandFinally(state, this);
|
|
4253
4601
|
}
|
|
4254
4602
|
}
|
|
4255
|
-
networkAfterStep(this.stepName);
|
|
4603
|
+
networkAfterStep(this.stepName, this.context);
|
|
4604
|
+
if (process.env.TEMP_RUN === "true") {
|
|
4605
|
+
// Put a sleep for some time to allow the browser to finish processing
|
|
4606
|
+
if (!this.stepTags.includes("fast-mode")) {
|
|
4607
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
4608
|
+
}
|
|
4609
|
+
}
|
|
4610
|
+
if (this.trace) {
|
|
4611
|
+
await this.context.playContext.tracing.groupEnd();
|
|
4612
|
+
}
|
|
4256
4613
|
}
|
|
4257
4614
|
}
|
|
4258
4615
|
function createTimedPromise(promise, label) {
|