automation_model 1.0.690-dev → 1.0.692-dev
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/auto_page.js +9 -5
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +1 -1
- package/lib/browser_manager.js.map +1 -1
- package/lib/bruno.d.ts +1 -0
- package/lib/bruno.js +76 -3
- package/lib/bruno.js.map +1 -1
- package/lib/snapshot_validation.d.ts +35 -0
- package/lib/snapshot_validation.js +239 -0
- package/lib/snapshot_validation.js.map +1 -0
- package/lib/stable_browser.d.ts +2 -0
- package/lib/stable_browser.js +78 -2
- package/lib/stable_browser.js.map +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +7 -2
- package/lib/utils.js.map +1 -1
- package/package.json +3 -2
package/lib/stable_browser.js
CHANGED
|
@@ -23,6 +23,8 @@ import { registerDownloadEvent, registerNetworkEvents } from "./network.js";
|
|
|
23
23
|
import { LocatorLog } from "./locator_log.js";
|
|
24
24
|
import axios from "axios";
|
|
25
25
|
import { _findCellArea, findElementsInArea } from "./table_helper.js";
|
|
26
|
+
import { snapshotValidation } from "./snapshot_validation.js";
|
|
27
|
+
import { loadBrunoParams } from "./bruno.js";
|
|
26
28
|
export const Types = {
|
|
27
29
|
CLICK: "click_element",
|
|
28
30
|
WAIT_ELEMENT: "wait_element",
|
|
@@ -57,6 +59,7 @@ export const Types = {
|
|
|
57
59
|
VERIFY_ATTRIBUTE: "verify_element_attribute",
|
|
58
60
|
VERIFY_TEXT_WITH_RELATION: "verify_text_with_relation",
|
|
59
61
|
BRUNO: "bruno",
|
|
62
|
+
SNAPSHOT_VALIDATION: "snapshot_validation",
|
|
60
63
|
VERIFY_FILE_EXISTS: "verify_file_exists",
|
|
61
64
|
};
|
|
62
65
|
export const apps = {};
|
|
@@ -1652,6 +1655,75 @@ class StableBrowser {
|
|
|
1652
1655
|
await _commandFinally(state, this);
|
|
1653
1656
|
}
|
|
1654
1657
|
}
|
|
1658
|
+
async snapshotValidation(frameSelectors, referanceSnapshot, _params = null, options = {}, world = null) {
|
|
1659
|
+
const timeout = this._getFindElementTimeout(options);
|
|
1660
|
+
const startTime = Date.now();
|
|
1661
|
+
const state = {
|
|
1662
|
+
_params,
|
|
1663
|
+
value: referanceSnapshot,
|
|
1664
|
+
options,
|
|
1665
|
+
world,
|
|
1666
|
+
locate: false,
|
|
1667
|
+
scroll: false,
|
|
1668
|
+
screenshot: true,
|
|
1669
|
+
highlight: false,
|
|
1670
|
+
type: Types.SNAPSHOT_VALIDATION,
|
|
1671
|
+
text: `verify snapshot: ${referanceSnapshot}`,
|
|
1672
|
+
operation: "snapshotValidation",
|
|
1673
|
+
log: "***** verify snapshot *****\n",
|
|
1674
|
+
};
|
|
1675
|
+
if (!referanceSnapshot) {
|
|
1676
|
+
throw new Error("referanceSnapshot is null");
|
|
1677
|
+
}
|
|
1678
|
+
let text = null;
|
|
1679
|
+
if (fs.existsSync(path.join(this.project_path, "snapshots", referanceSnapshot + ".yml"))) {
|
|
1680
|
+
text = fs.readFileSync(path.join(this.project_path, "snapshots", referanceSnapshot + ".yml"), "utf8");
|
|
1681
|
+
}
|
|
1682
|
+
else if (referanceSnapshot.startsWith("yaml:")) {
|
|
1683
|
+
text = referanceSnapshot.substring(5);
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
throw new Error("referanceSnapshot file not found: " + referanceSnapshot);
|
|
1687
|
+
}
|
|
1688
|
+
state.text = text;
|
|
1689
|
+
const newValue = await this._replaceWithLocalData(text, world);
|
|
1690
|
+
await _preCommand(state, this);
|
|
1691
|
+
let foundObj = null;
|
|
1692
|
+
try {
|
|
1693
|
+
let matchResult = null;
|
|
1694
|
+
while (Date.now() - startTime < timeout) {
|
|
1695
|
+
try {
|
|
1696
|
+
let scope = null;
|
|
1697
|
+
if (!frameSelectors) {
|
|
1698
|
+
scope = this.page;
|
|
1699
|
+
}
|
|
1700
|
+
else {
|
|
1701
|
+
scope = await this._findFrameScope(frameSelectors, timeout, state.info);
|
|
1702
|
+
}
|
|
1703
|
+
const snapshot = await scope.locator("body").ariaSnapshot({ timeout });
|
|
1704
|
+
matchResult = snapshotValidation(snapshot, newValue);
|
|
1705
|
+
if (matchResult.errorLine !== -1) {
|
|
1706
|
+
throw new Error("Snapshot validation failed at line " + matchResult.errorLineText);
|
|
1707
|
+
}
|
|
1708
|
+
// highlight and screenshot
|
|
1709
|
+
return state.info;
|
|
1710
|
+
}
|
|
1711
|
+
catch (e) {
|
|
1712
|
+
// Log error but continue retrying until timeout is reached
|
|
1713
|
+
this.logger.warn("Retrying containsText due to: " + e.message);
|
|
1714
|
+
}
|
|
1715
|
+
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second before retrying
|
|
1716
|
+
}
|
|
1717
|
+
throw new Error("No snapshot match " + matchResult?.errorLineText);
|
|
1718
|
+
}
|
|
1719
|
+
catch (e) {
|
|
1720
|
+
await _commandError(state, e, this);
|
|
1721
|
+
throw e;
|
|
1722
|
+
}
|
|
1723
|
+
finally {
|
|
1724
|
+
await _commandFinally(state, this);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1655
1727
|
async waitForUserInput(message, world = null) {
|
|
1656
1728
|
if (!message) {
|
|
1657
1729
|
message = "# Wait for user input. Press any key to continue";
|
|
@@ -3363,7 +3435,10 @@ class StableBrowser {
|
|
|
3363
3435
|
if (this.context && this.context.environment) {
|
|
3364
3436
|
envName = this.context.environment.name;
|
|
3365
3437
|
}
|
|
3366
|
-
|
|
3438
|
+
if (!process.env.TEMP_RUN) {
|
|
3439
|
+
await getTestData(envName, world, undefined, this.featureName, this.scenarioName);
|
|
3440
|
+
}
|
|
3441
|
+
await loadBrunoParams(this.context, this.context.environment.name);
|
|
3367
3442
|
}
|
|
3368
3443
|
async afterScenario(world, scenario) { }
|
|
3369
3444
|
async beforeStep(world, step) {
|
|
@@ -3423,7 +3498,8 @@ class StableBrowser {
|
|
|
3423
3498
|
return content.join("\n");
|
|
3424
3499
|
}
|
|
3425
3500
|
catch (e) {
|
|
3426
|
-
console.
|
|
3501
|
+
console.log("Error in getAriaSnapshot");
|
|
3502
|
+
console.debug(e);
|
|
3427
3503
|
}
|
|
3428
3504
|
return null;
|
|
3429
3505
|
}
|