@empiricalrun/playwright-utils 0.22.0 → 0.22.2
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/CHANGELOG.md +15 -0
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/cache.d.ts +10 -3
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/cache.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/cache.js +17 -12
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.js +10 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @empiricalrun/playwright-utils
|
|
2
2
|
|
|
3
|
+
## 0.22.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [cce1c90]
|
|
8
|
+
- @empiricalrun/test-gen@0.46.5
|
|
9
|
+
|
|
10
|
+
## 0.22.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 8e4bf9d: fix: text content for dismissed overlay is undefined
|
|
15
|
+
- Updated dependencies [0c29798]
|
|
16
|
+
- @empiricalrun/test-gen@0.46.4
|
|
17
|
+
|
|
3
18
|
## 0.22.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { Page } from "@playwright/test";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare function setCodeToCache({ dom, text, code, }: {
|
|
3
|
+
dom: string | undefined;
|
|
4
|
+
text: string | undefined;
|
|
5
|
+
code: string;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export declare function executeFromCache({ page, dom, text, }: {
|
|
8
|
+
page: Page;
|
|
9
|
+
dom: string | undefined;
|
|
10
|
+
text: string | undefined;
|
|
11
|
+
}): Promise<{
|
|
5
12
|
success: boolean;
|
|
6
13
|
}>;
|
|
7
14
|
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAsB7C,wBAAsB,cAAc,CAAC,EACnC,GAAG,EACH,IAAI,EACJ,IAAI,GACL,EAAE;IACD,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,iBAiCA;AAED,wBAAsB,gBAAgB,CAAC,EACrC,IAAI,EACJ,GAAG,EACH,IAAI,GACL,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAkChC"}
|
|
@@ -6,14 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.executeFromCache = exports.setCodeToCache = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
9
|
const CACHE_FILE = path_1.default.join(process.cwd(), ".empiricalrun", `overlay-cache.json`);
|
|
11
10
|
function isCacheSupported(code) {
|
|
12
11
|
// Current release only supports caching for code that contains 1 `click` only
|
|
13
12
|
return code.includes("click") && code.trim().split("\n").length <= 1;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
function normalizeString(str) {
|
|
15
|
+
// Replace all whitespace sequences with a single space
|
|
16
|
+
return str.replace(/\s+/g, " ").trim();
|
|
17
|
+
}
|
|
18
|
+
async function setCodeToCache({ dom, text, code, }) {
|
|
19
|
+
if (!dom && !text) {
|
|
20
|
+
// At least one of the two is required
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
23
|
if (!isCacheSupported(code)) {
|
|
@@ -21,8 +25,8 @@ async function setCodeToCache(pageRef, element, code) {
|
|
|
21
25
|
}
|
|
22
26
|
const obj = {
|
|
23
27
|
element: {
|
|
24
|
-
dom:
|
|
25
|
-
textContent: (
|
|
28
|
+
dom: dom || "",
|
|
29
|
+
textContent: normalizeString(text || ""),
|
|
26
30
|
},
|
|
27
31
|
code,
|
|
28
32
|
};
|
|
@@ -47,29 +51,30 @@ async function setCodeToCache(pageRef, element, code) {
|
|
|
47
51
|
fs_1.default.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
48
52
|
}
|
|
49
53
|
exports.setCodeToCache = setCodeToCache;
|
|
50
|
-
async function executeFromCache(
|
|
51
|
-
if (!
|
|
54
|
+
async function executeFromCache({ page, dom, text, }) {
|
|
55
|
+
if (!dom && !text) {
|
|
56
|
+
// At least one of the two is required
|
|
52
57
|
return { success: false };
|
|
53
58
|
}
|
|
54
59
|
try {
|
|
55
60
|
const cache = JSON.parse(fs_1.default.readFileSync(CACHE_FILE, "utf8"));
|
|
56
|
-
const text = (await (0, utils_1.textContent)(pageRef, element))?.trim() || "";
|
|
57
61
|
const match = cache.data.find((c) => {
|
|
58
|
-
return (c.element.dom ===
|
|
62
|
+
return (c.element.dom === (dom || "") &&
|
|
63
|
+
c.element.textContent === normalizeString(text || ""));
|
|
59
64
|
});
|
|
60
65
|
if (!match) {
|
|
61
66
|
return { success: false };
|
|
62
67
|
}
|
|
63
68
|
try {
|
|
64
|
-
console.log(`Executing
|
|
69
|
+
console.log(`Executing "${match.code}" for element: ${dom}`);
|
|
65
70
|
// Ref: https://davidwalsh.name/async-function-class
|
|
66
71
|
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
67
72
|
const exec = new AsyncFunction("page", match.code);
|
|
68
|
-
await exec(
|
|
73
|
+
await exec(page);
|
|
69
74
|
return { success: true };
|
|
70
75
|
}
|
|
71
76
|
catch (err) {
|
|
72
|
-
console.log(`Failed
|
|
77
|
+
console.log(`Failed in "${match.code}" for element: ${dom}`);
|
|
73
78
|
return { success: false };
|
|
74
79
|
}
|
|
75
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,cAAc,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,cAAc,GAAG,SAAS,iBAyDpC;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GACnB,cAAc,GAAG,SAAS,CAiC5B"}
|
|
@@ -48,7 +48,11 @@ Don't reattempt the click on Target element, your job is done after the first cl
|
|
|
48
48
|
: ``;
|
|
49
49
|
task += `${promptAddition}`;
|
|
50
50
|
}
|
|
51
|
-
const { success } = await (0, cache_1.executeFromCache)(
|
|
51
|
+
const { success } = await (0, cache_1.executeFromCache)({
|
|
52
|
+
page: pageRef,
|
|
53
|
+
dom: element?.interceptor,
|
|
54
|
+
text,
|
|
55
|
+
});
|
|
52
56
|
if (success) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
@@ -59,7 +63,11 @@ Don't reattempt the click on Target element, your job is done after the first cl
|
|
|
59
63
|
useActionSpecificAnnotations: true,
|
|
60
64
|
},
|
|
61
65
|
});
|
|
62
|
-
await (0, cache_1.setCodeToCache)(
|
|
66
|
+
await (0, cache_1.setCodeToCache)({
|
|
67
|
+
dom: element?.interceptor,
|
|
68
|
+
text,
|
|
69
|
+
code: result.code,
|
|
70
|
+
});
|
|
63
71
|
}
|
|
64
72
|
exports.runAgentOnOverlay = runAgentOnOverlay;
|
|
65
73
|
function extractInterceptingElement(errorMessage) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"rimraf": "^6.0.1",
|
|
45
45
|
"@empiricalrun/llm": "^0.9.35",
|
|
46
46
|
"@empiricalrun/r2-uploader": "^0.3.8",
|
|
47
|
-
"@empiricalrun/test-gen": "^0.46.
|
|
47
|
+
"@empiricalrun/test-gen": "^0.46.5"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"dev": "tsc --build --watch",
|