automation_model 1.0.742-dev → 1.0.742-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/api.js +4 -3
- package/lib/api.js.map +1 -1
- package/lib/auto_page.d.ts +3 -1
- package/lib/auto_page.js +60 -9
- package/lib/auto_page.js.map +1 -1
- package/lib/browser_manager.js +19 -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 +17 -1
- package/lib/command_common.js.map +1 -1
- package/lib/file_checker.js +129 -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 +121 -125
- package/lib/init_browser.js.map +1 -1
- package/lib/locator.d.ts +1 -0
- package/lib/locator.js +9 -2
- 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 +398 -87
- package/lib/network.js.map +1 -1
- package/lib/route.d.ts +83 -0
- package/lib/route.js +682 -0
- package/lib/route.js.map +1 -0
- package/lib/scripts/axe.mini.js +23994 -1
- package/lib/snapshot_validation.js.map +1 -1
- package/lib/stable_browser.d.ts +15 -4
- package/lib/stable_browser.js +570 -89
- 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_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 +5 -1
- package/lib/utils.js +36 -9
- package/lib/utils.js.map +1 -1
- package/package.json +15 -10
package/lib/command_common.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { check_performance } from "./check_performance.js";
|
|
1
2
|
import { getHumanReadableErrorMessage } from "./error-messages.js";
|
|
2
3
|
import { LocatorLog } from "./locator_log.js";
|
|
3
4
|
import { _fixUsingParams, maskValue, replaceWithLocalTestData } from "./utils.js";
|
|
4
5
|
export async function _preCommand(state, web) {
|
|
6
|
+
if (web && web.getCmdId) {
|
|
7
|
+
state.cmdId = web.getCmdId();
|
|
8
|
+
}
|
|
5
9
|
if (!state) {
|
|
6
10
|
return;
|
|
7
11
|
}
|
|
@@ -52,6 +56,7 @@ export async function _preCommand(state, web) {
|
|
|
52
56
|
state.error = null;
|
|
53
57
|
state.screenshotId = null;
|
|
54
58
|
state.screenshotPath = null;
|
|
59
|
+
state.onlyFailuresScreenshot = process.env.SCREENSHOT_ON_FAILURE_ONLY === "true";
|
|
55
60
|
if (state.locate === true) {
|
|
56
61
|
let timeout = null;
|
|
57
62
|
if (state.options && state.options.timeout) {
|
|
@@ -63,7 +68,11 @@ export async function _preCommand(state, web) {
|
|
|
63
68
|
await web.scrollIfNeeded(state.element, state.info);
|
|
64
69
|
}
|
|
65
70
|
if (state.screenshot === true /*&& !web.fastMode*/) {
|
|
66
|
-
|
|
71
|
+
if (!state.onlyFailuresScreenshot) {
|
|
72
|
+
check_performance("screenshot", web.context, true);
|
|
73
|
+
await _screenshot(state, web);
|
|
74
|
+
check_performance("screenshot", web.context, false);
|
|
75
|
+
}
|
|
67
76
|
}
|
|
68
77
|
if (state.highlight === true) {
|
|
69
78
|
try {
|
|
@@ -74,6 +83,12 @@ export async function _preCommand(state, web) {
|
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
state.info.failCause.operationFailed = true;
|
|
86
|
+
if (web.pausedCmd && web.pausedCmd.id === state.cmdId) {
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
web.pausedCmd.resolve = resolve;
|
|
89
|
+
web.pausedCmd.reject = reject;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
77
92
|
}
|
|
78
93
|
export async function _commandError(state, error, web) {
|
|
79
94
|
if (!state.info) {
|
|
@@ -169,6 +184,7 @@ export async function _commandFinally(state, web) {
|
|
|
169
184
|
},
|
|
170
185
|
info: state.info,
|
|
171
186
|
locatorLog: state.info.locatorLog ? state.info.locatorLog.toString() : null,
|
|
187
|
+
cmdId: state.cmdId,
|
|
172
188
|
};
|
|
173
189
|
if (state.originalValue && state.info) {
|
|
174
190
|
state.info.value = maskValue(state.originalValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command_common.js","sourceRoot":"","sources":["../../src/command_common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AA0BlF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAU,EAAE,GAAQ;IACpD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;IACT,CAAC;IAED,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;QACxB,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC3B,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IACtB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC3B,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IACtB,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QAC/B,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC;QAC9B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;IACzB,CAAC;IACD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AC,OAAO,GAAG,OAAO,CAAC;IACjC,CAAC;IACD,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAC5C,CAAC;AACD,MAAM,UAAU,kBAAkB,CAAC,SAAc;IAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AACD,MAAM,UAAU,cAAc,CAAC,KAAU,EAAE,UAAe;IACxD,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
package/lib/file_checker.js
CHANGED
|
@@ -1,54 +1,158 @@
|
|
|
1
|
-
import fs from "fs";
|
|
1
|
+
import * as fs from "fs"; // sync fs
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { promises as fsAsync } from "fs"; // async fs
|
|
2
4
|
import { _commandError, _commandFinally, _preCommand } from "./command_common.js";
|
|
3
5
|
import { Types } from "./stable_browser.js";
|
|
4
6
|
const checkFileAccess = (filePath, accessMode) => {
|
|
5
|
-
return new Promise((resolve
|
|
7
|
+
return new Promise((resolve) => {
|
|
6
8
|
fs.access(filePath, accessMode, (err) => {
|
|
7
|
-
|
|
8
|
-
resolve(false);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
resolve(true);
|
|
12
|
-
}
|
|
9
|
+
resolve(!err);
|
|
13
10
|
});
|
|
14
11
|
});
|
|
15
12
|
};
|
|
16
13
|
const getFileName = (filePath) => {
|
|
17
14
|
const platform = process.platform;
|
|
18
|
-
|
|
19
|
-
if (platform === "win32") {
|
|
20
|
-
fileName = filePath.split("\\").pop() || "";
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
fileName = filePath.split("/").pop() || "";
|
|
24
|
-
}
|
|
25
|
-
return fileName;
|
|
15
|
+
return platform === "win32" ? filePath.split("\\").pop() || "" : filePath.split("/").pop() || "";
|
|
26
16
|
};
|
|
17
|
+
// Simplified regex check
|
|
18
|
+
function testForRegex(text) {
|
|
19
|
+
return text.startsWith("regex:");
|
|
20
|
+
}
|
|
27
21
|
export const verifyFileExists = async (filePath, options, context, world) => {
|
|
28
|
-
|
|
29
|
-
if (!options) {
|
|
22
|
+
if (!options)
|
|
30
23
|
options = {};
|
|
31
|
-
}
|
|
32
24
|
const fileName = getFileName(filePath);
|
|
25
|
+
let isSoft = false;
|
|
26
|
+
const match = filePath.match(/(soft:)?(regex:|exact:|contains:)(.*)/);
|
|
27
|
+
if (match) {
|
|
28
|
+
isSoft = !!match[1]; // true if 'soft:' is present
|
|
29
|
+
}
|
|
33
30
|
const state = {
|
|
34
31
|
locate: false,
|
|
35
32
|
scroll: false,
|
|
36
33
|
screenshot: false,
|
|
37
34
|
highlight: false,
|
|
38
|
-
throwError:
|
|
35
|
+
throwError: !isSoft, // don't throw error for soft assertions
|
|
39
36
|
operation: "verifyFileExists",
|
|
40
37
|
value: filePath,
|
|
41
38
|
text: `Verify file ${fileName} exists`,
|
|
42
39
|
options,
|
|
43
40
|
type: Types.VERIFY_FILE_EXISTS,
|
|
44
|
-
world
|
|
41
|
+
world,
|
|
45
42
|
};
|
|
46
43
|
await _preCommand(state, context.web);
|
|
47
|
-
let fileAccessible = false;
|
|
48
44
|
try {
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
45
|
+
let pathToMatch = filePath;
|
|
46
|
+
if (isSoft) {
|
|
47
|
+
pathToMatch = filePath.replace(/^soft:/, ""); // remove soft: prefix for parsing
|
|
48
|
+
}
|
|
49
|
+
let dir;
|
|
50
|
+
let input;
|
|
51
|
+
console.log("pathSeparator", path.sep);
|
|
52
|
+
if (pathToMatch.includes("regex:")) {
|
|
53
|
+
const regexIndex = pathToMatch.indexOf("regex:");
|
|
54
|
+
// Handle both forward slashes and backslashes before regex:
|
|
55
|
+
let dirPart = pathToMatch.substring(0, regexIndex);
|
|
56
|
+
// Remove trailing slash/backslash
|
|
57
|
+
if (dirPart.endsWith("/") || dirPart.endsWith("\\")) {
|
|
58
|
+
dirPart = dirPart.slice(0, -1);
|
|
59
|
+
}
|
|
60
|
+
dir = dirPart;
|
|
61
|
+
input = pathToMatch.substring(regexIndex);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Use path.sep to handle both forward and backward slashes
|
|
65
|
+
const pathSeparator = path.sep;
|
|
66
|
+
const lastSlashIndex = pathToMatch.lastIndexOf(pathSeparator);
|
|
67
|
+
// If no separator found, try the other separator (for mixed paths)
|
|
68
|
+
if (lastSlashIndex === -1) {
|
|
69
|
+
const alternativeSeparator = pathSeparator === "/" ? "\\" : "/";
|
|
70
|
+
const altLastSlashIndex = pathToMatch.lastIndexOf(alternativeSeparator);
|
|
71
|
+
if (altLastSlashIndex !== -1) {
|
|
72
|
+
dir = pathToMatch.substring(0, altLastSlashIndex);
|
|
73
|
+
input = pathToMatch.substring(altLastSlashIndex + 1);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// No separator found, assume current directory
|
|
77
|
+
dir = ".";
|
|
78
|
+
input = pathToMatch;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
dir = pathToMatch.substring(0, lastSlashIndex);
|
|
83
|
+
input = pathToMatch.substring(lastSlashIndex + 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (isSoft) {
|
|
87
|
+
dir = dir.slice(0, -5);
|
|
88
|
+
}
|
|
89
|
+
console.log(`Directory to check: ${dir}`);
|
|
90
|
+
console.log(`Input pattern: ${input}`);
|
|
91
|
+
const files = await fsAsync.readdir(dir);
|
|
92
|
+
let found = false;
|
|
93
|
+
if (input.startsWith("exact:")) {
|
|
94
|
+
const target = input.replace("exact:", "");
|
|
95
|
+
found = files.includes(target);
|
|
96
|
+
}
|
|
97
|
+
else if (input.startsWith("contains:")) {
|
|
98
|
+
const target = input.replace("contains:", "");
|
|
99
|
+
found = files.some((f) => f.includes(target));
|
|
100
|
+
}
|
|
101
|
+
else if (input.startsWith("format:")) {
|
|
102
|
+
const extension = input.replace("format:", "");
|
|
103
|
+
found = files.some((f) => f.endsWith(`.${extension}`));
|
|
104
|
+
}
|
|
105
|
+
else if (testForRegex(input)) {
|
|
106
|
+
let raw = input.replace("regex:", "").trim(); // e.g. "/file/i" or "file.*::i"
|
|
107
|
+
let pattern = raw;
|
|
108
|
+
let flags = "";
|
|
109
|
+
// Normalize delimiters: convert backslash delimiters to forward slash delimiters
|
|
110
|
+
// This preserves the regex pattern while standardizing the delimiter format
|
|
111
|
+
if (raw.startsWith("\\") && raw.lastIndexOf("\\") > 0) {
|
|
112
|
+
// Convert \pattern\flags to /pattern/flags format
|
|
113
|
+
const lastBackslash = raw.lastIndexOf("\\");
|
|
114
|
+
const patternPart = raw.substring(1, lastBackslash);
|
|
115
|
+
const flagsPart = raw.substring(lastBackslash + 1);
|
|
116
|
+
raw = `/${patternPart}/${flagsPart}`;
|
|
117
|
+
}
|
|
118
|
+
// Now handle the standardized format
|
|
119
|
+
if (raw.startsWith("/") && raw.lastIndexOf("/") > 0) {
|
|
120
|
+
// Standard regex format: /pattern/flags
|
|
121
|
+
const lastSlash = raw.lastIndexOf("/");
|
|
122
|
+
flags = raw.substring(lastSlash + 1);
|
|
123
|
+
pattern = raw.substring(1, lastSlash);
|
|
124
|
+
}
|
|
125
|
+
else if (raw.includes("::")) {
|
|
126
|
+
// Alternative format: pattern::flags
|
|
127
|
+
[pattern, flags] = raw.split("::");
|
|
128
|
+
}
|
|
129
|
+
console.log(`Regex pattern: ${pattern}, flags: ${flags}`);
|
|
130
|
+
try {
|
|
131
|
+
const regex = new RegExp(pattern, flags);
|
|
132
|
+
found = files.some((f) => {
|
|
133
|
+
const matched = regex.test(f);
|
|
134
|
+
return matched;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (regexError) {
|
|
138
|
+
throw new Error(`Invalid regex pattern: ${pattern}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Fallback to exact path check
|
|
143
|
+
found = await checkFileAccess(pathToMatch, fs.constants.F_OK);
|
|
144
|
+
}
|
|
145
|
+
if (!found) {
|
|
146
|
+
console.log(`Available files in '${dir}':`, files);
|
|
147
|
+
if (!isSoft) {
|
|
148
|
+
throw new Error(`No file matched the pattern: ${filePath}`);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.warn(`Soft assertion failed for pattern: ${filePath}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.log(`File verification successful for pattern: ${input}`);
|
|
52
156
|
}
|
|
53
157
|
}
|
|
54
158
|
catch (err) {
|
package/lib/file_checker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_checker.js","sourceRoot":"","sources":["../../src/file_checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"file_checker.js","sourceRoot":"","sources":["../../src/file_checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,UAAU;A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M,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBAC9B,OAAO,OAAO,CAAC;gBACjB,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;aAAM,CAAC;YACN,+BAA+B;YAC/B,KAAK,GAAG,MAAM,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;YACnD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;YAC9D,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,6CAA6C,KAAK,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;YAAS,CAAC;QACT,MAAM,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,+BAA+B"}
|
package/lib/init_browser.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Environment } from "./environment.js";
|
|
2
|
-
import { TestContext } from "./test_context.js";
|
|
3
2
|
import { StableBrowser } from "./stable_browser.js";
|
|
4
3
|
import { Browser as PlaywrightBrowser } from "playwright";
|
|
5
4
|
import { Browser } from "./browser_manager.js";
|
|
6
5
|
import { InitScripts } from "./generation_scripts.js";
|
|
7
|
-
declare const getContext: (environment: Environment | null, headless: boolean | undefined, world: any, logger?: null, appName?: string | null, createStable?: boolean, web?: StableBrowser | null, moveToRight?: number, reportFolder?: string | null, initScripts?: InitScripts | null, storageState?: any | null) => Promise<
|
|
6
|
+
declare const getContext: (environment: Environment | null, headless: boolean | undefined, world: any, logger?: null, appName?: string | null, createStable?: boolean, web?: StableBrowser | null, moveToRight?: number, reportFolder?: string | null, initScripts?: InitScripts | null, storageState?: any | null) => Promise<any>;
|
|
8
7
|
declare const refreshBrowser: (web: any, sessionPath: string, world: any) => Promise<void>;
|
|
9
8
|
declare const closeBrowser: (browser?: Browser | PlaywrightBrowser) => Promise<void>;
|
|
10
9
|
export { getContext, closeBrowser, refreshBrowser };
|
package/lib/init_browser.js
CHANGED
|
@@ -5,135 +5,132 @@ import { browserManager } from "./browser_manager.js";
|
|
|
5
5
|
import { TestContext } from "./test_context.js";
|
|
6
6
|
import { StableBrowser } from "./stable_browser.js";
|
|
7
7
|
import { Api } from "./api.js";
|
|
8
|
-
|
|
8
|
+
import { measureAsync } from "./utils.js";
|
|
9
9
|
// init browser create context and page, if context and page are not null
|
|
10
10
|
const getContext = async function (environment, headless = false, world, logger, appName, createStable = true, web = null, moveToRight = -1, reportFolder = null, initScripts = null, storageState = null) {
|
|
11
|
-
|
|
12
|
-
environment
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
return measureAsync("browser Launch", async () => {
|
|
12
|
+
if (environment === null) {
|
|
13
|
+
environment = initEnvironment();
|
|
14
|
+
}
|
|
15
|
+
if (appName && !environment.apps && !environment.apps[appName]) {
|
|
16
|
+
throw new Error(`App ${appName} not found in environment`);
|
|
17
|
+
}
|
|
18
|
+
if (appName) {
|
|
19
|
+
environment = environment.apps[appName];
|
|
20
|
+
}
|
|
21
|
+
const { cookies, origins } = environment;
|
|
22
|
+
if (cookies) {
|
|
23
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
24
|
+
const cookie = cookies[i];
|
|
25
|
+
if (cookie.expires === "undefined") {
|
|
26
|
+
delete cookie.expires;
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
aiConfigFile = path.join(process.env.PROJECT_PATH, "ai_config.json");
|
|
36
|
-
}
|
|
37
|
-
let configuration = {};
|
|
38
|
-
if (fs.existsSync(aiConfigFile)) {
|
|
39
|
-
configuration = JSON.parse(fs.readFileSync(aiConfigFile, "utf8"));
|
|
40
|
-
if (configuration.userDataDirPath) {
|
|
41
|
-
userDataDirPath = configuration.userDataDirPath;
|
|
30
|
+
let extensionPath = undefined;
|
|
31
|
+
let userDataDirPath = undefined;
|
|
32
|
+
let userAgent = undefined;
|
|
33
|
+
let aiConfigFile = "ai_config.json";
|
|
34
|
+
let channel = undefined;
|
|
35
|
+
if (process.env.PROJECT_PATH) {
|
|
36
|
+
aiConfigFile = path.join(process.env.PROJECT_PATH, "ai_config.json");
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
let configuration = {};
|
|
39
|
+
if (fs.existsSync(aiConfigFile)) {
|
|
40
|
+
configuration = JSON.parse(fs.readFileSync(aiConfigFile, "utf8"));
|
|
41
|
+
if (configuration.userDataDirPath) {
|
|
42
|
+
userDataDirPath = configuration.userDataDirPath;
|
|
43
|
+
}
|
|
44
|
+
if (configuration.extensionPath) {
|
|
45
|
+
extensionPath = configuration.extensionPath;
|
|
46
|
+
}
|
|
47
|
+
if (configuration.useGoogleChrome === true) {
|
|
48
|
+
channel = "chrome";
|
|
49
|
+
}
|
|
50
|
+
else if (configuration.useMicrosoftEdge === true) {
|
|
51
|
+
channel = "msedge";
|
|
52
|
+
}
|
|
53
|
+
if (configuration.overrideUserAgent) {
|
|
54
|
+
userAgent = configuration.overrideUserAgent;
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
let usedStorageState = null;
|
|
58
|
+
usedStorageState = { cookies, origins };
|
|
59
|
+
let downloadsPath = "downloads";
|
|
60
|
+
if (reportFolder) {
|
|
61
|
+
downloadsPath = path.join(reportFolder, "downloads");
|
|
48
62
|
}
|
|
49
|
-
else if (
|
|
50
|
-
|
|
63
|
+
else if (web && web.context && web.context.reportFolder) {
|
|
64
|
+
reportFolder = web.context.reportFolder;
|
|
65
|
+
downloadsPath = path.join(web.context.reportFolder, "downloads");
|
|
51
66
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
67
|
+
if (world) {
|
|
68
|
+
world.downloadsPath = downloadsPath;
|
|
54
69
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (web && web.context) {
|
|
70
|
-
web.context.downloadsPath = downloadsPath;
|
|
71
|
-
}
|
|
72
|
-
// check if data.json exists in the report folder
|
|
73
|
-
// and if it contain storageState field, if so, use it
|
|
74
|
-
if (reportFolder) {
|
|
75
|
-
const dataFile = path.join(reportFolder, "data.json");
|
|
76
|
-
if (fs.existsSync(dataFile)) {
|
|
77
|
-
const data = fs.readFileSync(dataFile, "utf8");
|
|
78
|
-
const dataObject = JSON.parse(data);
|
|
79
|
-
if (dataObject.storageState) {
|
|
80
|
-
console.log("Init browser with storage state");
|
|
81
|
-
usedStorageState = dataObject.storageState;
|
|
70
|
+
if (web && web.context) {
|
|
71
|
+
web.context.downloadsPath = downloadsPath;
|
|
72
|
+
}
|
|
73
|
+
// check if data.json exists in the report folder
|
|
74
|
+
// and if it contain storageState field, if so, use it
|
|
75
|
+
if (reportFolder) {
|
|
76
|
+
const dataFile = path.join(reportFolder, "data.json");
|
|
77
|
+
if (fs.existsSync(dataFile)) {
|
|
78
|
+
const data = fs.readFileSync(dataFile, "utf8");
|
|
79
|
+
const dataObject = JSON.parse(data);
|
|
80
|
+
if (dataObject.storageState) {
|
|
81
|
+
console.log("Init browser with storage state");
|
|
82
|
+
usedStorageState = dataObject.storageState;
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// close cdp
|
|
133
|
-
await client.detach();
|
|
134
|
-
}
|
|
135
|
-
// await _initCookies(context);
|
|
136
|
-
return context;
|
|
86
|
+
if (storageState) {
|
|
87
|
+
usedStorageState = storageState;
|
|
88
|
+
}
|
|
89
|
+
let browser = await browserManager.createBrowser(headless, usedStorageState, extensionPath, userDataDirPath, reportFolder ? reportFolder : ".", userAgent, channel, configuration, initScripts);
|
|
90
|
+
let context = new TestContext();
|
|
91
|
+
context.browser = browser.browser;
|
|
92
|
+
context.browserObject = browser;
|
|
93
|
+
context.playContext = browser.context;
|
|
94
|
+
context.page = browser.page;
|
|
95
|
+
context.headless = headless;
|
|
96
|
+
context.environment = environment;
|
|
97
|
+
context.browserName = browser.browser ? browser.browser.browserType().name() : "unknown";
|
|
98
|
+
context.reportFolder = reportFolder;
|
|
99
|
+
context.initScripts = initScripts;
|
|
100
|
+
if (process.env.CDP_CONNECT_URL) {
|
|
101
|
+
// settin it to true will not navigate
|
|
102
|
+
context.navigate = true;
|
|
103
|
+
}
|
|
104
|
+
if (createStable) {
|
|
105
|
+
context.stable = new StableBrowser(context.browser, context.page, logger, context, world);
|
|
106
|
+
context.web = context.stable;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
context.stable = web;
|
|
110
|
+
context.web = web;
|
|
111
|
+
}
|
|
112
|
+
context.api = new Api(logger);
|
|
113
|
+
if (moveToRight === -1) {
|
|
114
|
+
moveToRight = parseInt(process.env.CHROME_POSITION || "-1", 10);
|
|
115
|
+
}
|
|
116
|
+
if (moveToRight > 0 && context.browserName === "chromium") {
|
|
117
|
+
const playContext = context.playContext;
|
|
118
|
+
const client = await playContext.newCDPSession(context.page);
|
|
119
|
+
const { windowId } = await client.send("Browser.getWindowForTarget");
|
|
120
|
+
const window = await client.send("Browser.getWindowBounds", {
|
|
121
|
+
windowId,
|
|
122
|
+
});
|
|
123
|
+
await client.send("Browser.setWindowBounds", {
|
|
124
|
+
windowId,
|
|
125
|
+
bounds: {
|
|
126
|
+
left: window.bounds.left + moveToRight,
|
|
127
|
+
top: 0,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
await client.detach();
|
|
131
|
+
}
|
|
132
|
+
return context;
|
|
133
|
+
});
|
|
137
134
|
};
|
|
138
135
|
const refreshBrowser = async function (web, sessionPath, world) {
|
|
139
136
|
await web.context.browserObject.close();
|
|
@@ -147,7 +144,6 @@ const refreshBrowser = async function (web, sessionPath, world) {
|
|
|
147
144
|
storageState = JSON.parse(data).storageState;
|
|
148
145
|
}
|
|
149
146
|
const newContext = await getContext(web.context.environment, web.context.headless, world, null, web.context.appName, false, web, -1, web.context.reportFolder, web.context.initScripts, storageState);
|
|
150
|
-
// clone all the new context properties to the old context
|
|
151
147
|
web.context.browser = newContext.browser;
|
|
152
148
|
web.context.browserObject = newContext.browserObject;
|
|
153
149
|
web.context.playContext = newContext.playContext;
|
|
@@ -165,7 +161,6 @@ const closeBrowser = async function (browser) {
|
|
|
165
161
|
await browserManager.closeBrowser(browser);
|
|
166
162
|
};
|
|
167
163
|
const initEnvironment = function () {
|
|
168
|
-
// if (environment === null) {
|
|
169
164
|
const environment = new Environment();
|
|
170
165
|
try {
|
|
171
166
|
let envFile = "";
|
|
@@ -189,22 +184,23 @@ const initEnvironment = function () {
|
|
|
189
184
|
}
|
|
190
185
|
}
|
|
191
186
|
}
|
|
192
|
-
// check if the envFile is not empty and exists
|
|
193
187
|
if (!envFile || !fs.existsSync(envFile)) {
|
|
194
188
|
throw new Error(envFile + " not found");
|
|
195
189
|
}
|
|
196
190
|
const data = fs.readFileSync(envFile, "utf8");
|
|
197
|
-
//console.log("data", data);
|
|
198
191
|
const envObject = JSON.parse(data);
|
|
199
|
-
//console.log("envObject", envObject);
|
|
200
192
|
Object.assign(environment, envObject);
|
|
201
|
-
|
|
193
|
+
if (process.env.FAST_MODE === "true") {
|
|
194
|
+
console.log("Fast mode enabled");
|
|
195
|
+
}
|
|
196
|
+
if (process.env.SCREENSHOT_ON_FAILURE_ONLY === "true") {
|
|
197
|
+
console.log("Screenshot on failure only mode enabled");
|
|
198
|
+
}
|
|
202
199
|
console.log("Base url: " + environment.baseUrl);
|
|
203
200
|
}
|
|
204
201
|
catch (err) {
|
|
205
202
|
console.error("Error reading env.json", err);
|
|
206
203
|
}
|
|
207
|
-
// }
|
|
208
204
|
return environment;
|
|
209
205
|
};
|
|
210
206
|
const checkForEnvArg = function () {
|