@empiricalrun/test-gen 0.79.4 → 0.79.6
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 +20 -0
- package/dist/agent/base/index.d.ts +2 -2
- package/dist/agent/base/index.d.ts.map +1 -1
- package/dist/agent/base/index.js +38 -7
- package/dist/agent/browsing/run.d.ts +1 -1
- package/dist/agent/browsing/run.d.ts.map +1 -1
- package/dist/agent/browsing/utils.d.ts +0 -7
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +9 -59
- package/dist/agent/chat/exports.d.ts +1 -1
- package/dist/agent/chat/exports.d.ts.map +1 -1
- package/dist/agent/chat/exports.js +1 -2
- package/dist/agent/chat/index.d.ts.map +1 -1
- package/dist/agent/chat/index.js +5 -5
- package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
- package/dist/agent/chat/prompt/repo.js +24 -0
- package/dist/agent/chat/state.d.ts +0 -1
- package/dist/agent/chat/state.d.ts.map +1 -1
- package/dist/agent/chat/state.js +0 -28
- package/dist/agent/master/browser-tests/cua.spec.js +3 -3
- package/dist/agent/master/browser-tests/index.spec.js +2 -111
- package/dist/agent/master/run.d.ts +0 -1
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +1 -3
- package/dist/bin/index.js +0 -12
- package/dist/dashboard/client.d.ts +2 -45
- package/dist/dashboard/client.d.ts.map +1 -1
- package/dist/dashboard/client.js +4 -217
- package/dist/dashboard/index.d.ts +2 -4
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +10 -13
- package/dist/dashboard/tool-response-from-sandbox.d.ts +1 -4
- package/dist/dashboard/tool-response-from-sandbox.d.ts.map +1 -1
- package/dist/dashboard/tool-response-from-sandbox.js +4 -38
- package/dist/dashboard/tool-response.d.ts +1 -5
- package/dist/dashboard/tool-response.d.ts.map +1 -1
- package/dist/dashboard/tool-response.js +5 -87
- package/dist/dashboard/types.d.ts +1 -8
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/dashboard/types.js +4 -14
- package/dist/file/server.d.ts +1 -1
- package/dist/file/server.d.ts.map +1 -1
- package/dist/file-info/adapters/github/reader.d.ts.map +1 -1
- package/dist/file-info/adapters/github/reader.js +10 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -32
- package/dist/recorder/index.d.ts.map +1 -1
- package/dist/recorder/index.js +3 -3
- package/dist/tools/api-client/index.d.ts +3 -0
- package/dist/tools/api-client/index.d.ts.map +1 -0
- package/dist/tools/api-client/index.js +73 -0
- package/dist/tools/create-pull-request/utils.d.ts +1 -1
- package/dist/tools/definitions/run-test.d.ts +2 -2
- package/dist/tools/definitions/run-test.d.ts.map +1 -1
- package/dist/tools/definitions/run-test.js +6 -5
- package/dist/tools/definitions/safe-bash.d.ts +1 -0
- package/dist/tools/definitions/safe-bash.d.ts.map +1 -1
- package/dist/tools/definitions/safe-bash.js +15 -6
- package/dist/tools/definitions/test-gen-browser.d.ts +2 -2
- package/dist/tools/definitions/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/definitions/test-gen-browser.js +4 -5
- package/dist/tools/delete-file/index.d.ts.map +1 -1
- package/dist/tools/delete-file/index.js +4 -5
- package/dist/tools/executor/index.d.ts.map +1 -1
- package/dist/tools/executor/index.js +0 -4
- package/dist/tools/fetch-file/index.d.ts.map +1 -1
- package/dist/tools/fetch-file/index.js +3 -7
- package/dist/tools/file-operations/create.js +4 -4
- package/dist/tools/file-operations/insert.js +5 -5
- package/dist/tools/file-operations/replace.js +5 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +0 -4
- package/dist/tools/issues-v1/utils.d.ts +1 -3
- package/dist/tools/issues-v1/utils.d.ts.map +1 -1
- package/dist/tools/issues-v1/utils.js +0 -16
- package/dist/tools/list-tests-and-projects/index.d.ts.map +1 -1
- package/dist/tools/list-tests-and-projects/index.js +1 -1
- package/dist/tools/rename-file/index.d.ts.map +1 -1
- package/dist/tools/rename-file/index.js +7 -4
- package/dist/tools/run-test.d.ts.map +1 -1
- package/dist/tools/run-test.js +33 -7
- package/dist/tools/safe-bash/index.d.ts.map +1 -1
- package/dist/tools/safe-bash/index.js +25 -10
- package/dist/tools/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/test-gen-browser.js +27 -8
- package/dist/tools/utils/validators.d.ts +7 -0
- package/dist/tools/utils/validators.d.ts.map +1 -0
- package/dist/tools/utils/validators.js +93 -0
- package/dist/video-core/index.d.ts.map +1 -1
- package/dist/video-core/index.js +5 -0
- package/package.json +10 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/agent/cua/computer.d.ts +0 -14
- package/dist/agent/cua/computer.d.ts.map +0 -1
- package/dist/agent/cua/computer.js +0 -191
- package/dist/agent/cua/index.d.ts +0 -22
- package/dist/agent/cua/index.d.ts.map +0 -1
- package/dist/agent/cua/index.js +0 -254
- package/dist/agent/cua/model.d.ts +0 -25
- package/dist/agent/cua/model.d.ts.map +0 -1
- package/dist/agent/cua/model.js +0 -66
- package/dist/agent/cua/pw-codegen/element-from-point.d.ts +0 -10
- package/dist/agent/cua/pw-codegen/element-from-point.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/element-from-point.js +0 -135
- package/dist/agent/cua/pw-codegen/factory.d.ts +0 -15
- package/dist/agent/cua/pw-codegen/factory.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/factory.js +0 -59
- package/dist/agent/cua/pw-codegen/index.d.ts +0 -7
- package/dist/agent/cua/pw-codegen/index.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/index.js +0 -14
- package/dist/agent/cua/pw-codegen/pw-event-sink/index.d.ts +0 -43
- package/dist/agent/cua/pw-codegen/pw-event-sink/index.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-event-sink/index.js +0 -250
- package/dist/agent/cua/pw-codegen/pw-pause/for-recorder.d.ts +0 -14
- package/dist/agent/cua/pw-codegen/pw-pause/for-recorder.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/for-recorder.js +0 -88
- package/dist/agent/cua/pw-codegen/pw-pause/index.d.ts +0 -17
- package/dist/agent/cua/pw-codegen/pw-pause/index.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/index.js +0 -117
- package/dist/agent/cua/pw-codegen/pw-pause/ipc.d.ts +0 -3
- package/dist/agent/cua/pw-codegen/pw-pause/ipc.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/ipc.js +0 -13
- package/dist/agent/cua/pw-codegen/pw-pause/patch.d.ts +0 -24
- package/dist/agent/cua/pw-codegen/pw-pause/patch.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/patch.js +0 -197
- package/dist/agent/cua/pw-codegen/pw-pause/types.d.ts +0 -14
- package/dist/agent/cua/pw-codegen/pw-pause/types.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/types.js +0 -2
- package/dist/agent/cua/pw-codegen/pw-pause/utils.d.ts +0 -2
- package/dist/agent/cua/pw-codegen/pw-pause/utils.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/pw-pause/utils.js +0 -6
- package/dist/agent/cua/pw-codegen/types.d.ts +0 -47
- package/dist/agent/cua/pw-codegen/types.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/types.js +0 -2
- package/dist/agent/cua/pw-codegen/version.d.ts +0 -25
- package/dist/agent/cua/pw-codegen/version.d.ts.map +0 -1
- package/dist/agent/cua/pw-codegen/version.js +0 -86
- package/dist/bin/environments.d.ts +0 -6
- package/dist/bin/environments.d.ts.map +0 -1
- package/dist/bin/environments.js +0 -99
- package/dist/tools/definitions/upgrade-packages.d.ts +0 -14
- package/dist/tools/definitions/upgrade-packages.d.ts.map +0 -1
- package/dist/tools/definitions/upgrade-packages.js +0 -21
- package/dist/tools/upgrade-packages/index.d.ts +0 -3
- package/dist/tools/upgrade-packages/index.d.ts.map +0 -1
- package/dist/tools/upgrade-packages/index.js +0 -134
- package/dist/tools/upgrade-packages/utils.d.ts +0 -28
- package/dist/tools/upgrade-packages/utils.d.ts.map +0 -1
- package/dist/tools/upgrade-packages/utils.js +0 -152
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ElementFromPointCodegen = void 0;
|
|
4
|
-
const utils_1 = require("../../browsing/utils");
|
|
5
|
-
async function getLocatorForClick(page, { x, y }) {
|
|
6
|
-
try {
|
|
7
|
-
const locator = await page.evaluate(([x, y]) => {
|
|
8
|
-
const element = document.elementFromPoint(x, y);
|
|
9
|
-
const bbox = element?.getBoundingClientRect();
|
|
10
|
-
return {
|
|
11
|
-
locator: window.playwright.generateLocator(element),
|
|
12
|
-
isIframe: element?.tagName === "IFRAME",
|
|
13
|
-
x0: bbox?.x,
|
|
14
|
-
y0: bbox?.y,
|
|
15
|
-
src: element?.getAttribute("src"),
|
|
16
|
-
id: element?.getAttribute("id"),
|
|
17
|
-
};
|
|
18
|
-
}, [x, y]);
|
|
19
|
-
if (!locator.isIframe) {
|
|
20
|
-
return locator.locator;
|
|
21
|
-
}
|
|
22
|
-
await (0, utils_1.injectPwLocatorGenerator)(page);
|
|
23
|
-
const relativeX = x - locator.x0;
|
|
24
|
-
const relativeY = y - locator.y0;
|
|
25
|
-
// TODO: Reuse locator.locator for the frameLocator.
|
|
26
|
-
let frameEl = locator.src
|
|
27
|
-
? page.locator(`[src="${locator.src}"]`)
|
|
28
|
-
: page.locator(`#${locator.id}`);
|
|
29
|
-
const frameLocator = locator.src
|
|
30
|
-
? `locator('[src="${locator.src}"]')`
|
|
31
|
-
: `locator('#${locator.id}')`;
|
|
32
|
-
const elementLocatorInsideFrame = await frameEl
|
|
33
|
-
.contentFrame()
|
|
34
|
-
.locator(":root")
|
|
35
|
-
.evaluate((rootElement, coords) => {
|
|
36
|
-
const xPos = coords[0];
|
|
37
|
-
const yPos = coords[1];
|
|
38
|
-
if (xPos === undefined || yPos === undefined) {
|
|
39
|
-
throw new Error("Coordinates are undefined in evaluate call");
|
|
40
|
-
}
|
|
41
|
-
const element = document.elementFromPoint(xPos, yPos);
|
|
42
|
-
return window.playwright.generateLocator(element);
|
|
43
|
-
}, [relativeX, relativeY]);
|
|
44
|
-
return `${frameLocator}.contentFrame().${elementLocatorInsideFrame}`;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
console.error(`Error generating locator for click: ${e.message || e.toString()}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function getLocatorForFill(page) {
|
|
51
|
-
try {
|
|
52
|
-
const locator = await page.evaluate(() => {
|
|
53
|
-
const element = document.activeElement;
|
|
54
|
-
return window.playwright.generateLocator(element);
|
|
55
|
-
});
|
|
56
|
-
return locator;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
console.error(`Error generating locator for fill: ${e.message || e.toString()}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
class ElementFromPointCodegen {
|
|
63
|
-
page;
|
|
64
|
-
codeForLastAction;
|
|
65
|
-
async initialize(page) {
|
|
66
|
-
this.page = page;
|
|
67
|
-
await (0, utils_1.injectPwLocatorGenerator)(page);
|
|
68
|
-
}
|
|
69
|
-
async recordAction(action) {
|
|
70
|
-
try {
|
|
71
|
-
if (action.type === "goto") {
|
|
72
|
-
this.codeForLastAction = `await page.goto("${action.url}");\n`;
|
|
73
|
-
}
|
|
74
|
-
if (action.type === "click") {
|
|
75
|
-
const { x, y } = action;
|
|
76
|
-
if (!this.page) {
|
|
77
|
-
throw new Error("Page is not initialized");
|
|
78
|
-
}
|
|
79
|
-
const locator = await getLocatorForClick(this.page, { x, y });
|
|
80
|
-
if (locator) {
|
|
81
|
-
this.codeForLastAction = `await page.${locator}.click();\n`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (action.type === "type") {
|
|
85
|
-
if (!this.page) {
|
|
86
|
-
throw new Error("Page is not initialized");
|
|
87
|
-
}
|
|
88
|
-
const locator = await getLocatorForFill(this.page);
|
|
89
|
-
if (locator) {
|
|
90
|
-
this.codeForLastAction = `await page.${locator}.fill("${action.text}");\n`;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (action.type === "back") {
|
|
94
|
-
this.codeForLastAction = `await page.goBack();\n`;
|
|
95
|
-
}
|
|
96
|
-
if (action.type === "forward") {
|
|
97
|
-
this.codeForLastAction = `await page.goForward();\n`;
|
|
98
|
-
}
|
|
99
|
-
if (action.type === "doubleclick") {
|
|
100
|
-
const { x, y } = action;
|
|
101
|
-
if (!this.page) {
|
|
102
|
-
throw new Error("Page is not initialized");
|
|
103
|
-
}
|
|
104
|
-
const locator = await getLocatorForClick(this.page, { x, y });
|
|
105
|
-
this.codeForLastAction = `await page.${locator}.dblclick();\n`;
|
|
106
|
-
}
|
|
107
|
-
if (action.type === "move") {
|
|
108
|
-
const { x, y } = action;
|
|
109
|
-
this.codeForLastAction = `await page.mouse.move(${x}, ${y});\n`;
|
|
110
|
-
}
|
|
111
|
-
if (action.type === "drag") {
|
|
112
|
-
// const { path } = action;
|
|
113
|
-
// TODO: This needs to be fixed
|
|
114
|
-
this.codeForLastAction = `No code generated: drag action not supported by code generation`;
|
|
115
|
-
}
|
|
116
|
-
if (action.type === "scroll") {
|
|
117
|
-
this.codeForLastAction = `No code to generate: will rely on Playwright's ability to auto-wait`;
|
|
118
|
-
}
|
|
119
|
-
if (action.type === "keypress") {
|
|
120
|
-
const { keys } = action;
|
|
121
|
-
this.codeForLastAction = `await page.keyboard.press("${keys.join("+")}");\n`;
|
|
122
|
-
}
|
|
123
|
-
if (action.type === "wait") {
|
|
124
|
-
this.codeForLastAction = `No code to generate: will rely on Playwright's ability to auto-wait`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
this.codeForLastAction = `Error generating code for action: ${e.message || e.toString()}`;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async getCodeForLastAction() {
|
|
132
|
-
return this.codeForLastAction || "No code generated for the last action";
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.ElementFromPointCodegen = ElementFromPointCodegen;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Factory for creating the appropriate Playwright codegen implementation
|
|
3
|
-
* based on the installed Playwright version.
|
|
4
|
-
*/
|
|
5
|
-
import type { BasePlaywrightCodegen } from "./types";
|
|
6
|
-
import { type CodegenApproach, type PlaywrightVersion } from "./version";
|
|
7
|
-
export type CodegenFactoryResult = {
|
|
8
|
-
codegen: BasePlaywrightCodegen;
|
|
9
|
-
approach: CodegenApproach;
|
|
10
|
-
version: PlaywrightVersion;
|
|
11
|
-
};
|
|
12
|
-
export declare function createPlaywrightCodegen(repoDir: string): Promise<CodegenFactoryResult>;
|
|
13
|
-
export declare function prepareCodegenIfNeeded(repoDir: string, approach: CodegenApproach): Promise<void>;
|
|
14
|
-
export { type CodegenApproach, type PlaywrightVersion };
|
|
15
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/agent/cua/pw-codegen/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,iBAAiB,EACvB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAoD/B;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPlaywrightCodegen = createPlaywrightCodegen;
|
|
4
|
-
exports.prepareCodegenIfNeeded = prepareCodegenIfNeeded;
|
|
5
|
-
/**
|
|
6
|
-
* Factory for creating the appropriate Playwright codegen implementation
|
|
7
|
-
* based on the installed Playwright version.
|
|
8
|
-
*/
|
|
9
|
-
const logger_1 = require("../../../logger");
|
|
10
|
-
const pw_event_sink_1 = require("./pw-event-sink");
|
|
11
|
-
const pw_pause_1 = require("./pw-pause");
|
|
12
|
-
const version_1 = require("./version");
|
|
13
|
-
async function createPlaywrightCodegen(repoDir) {
|
|
14
|
-
const version = await (0, version_1.detectPlaywrightVersion)(repoDir);
|
|
15
|
-
if (!version) {
|
|
16
|
-
throw new Error("Could not detect Playwright version. Make sure @playwright/test is installed.");
|
|
17
|
-
}
|
|
18
|
-
const approach = (0, version_1.getCodegenApproach)(version);
|
|
19
|
-
logger_1.logger.info(`Detected Playwright ${version.full}, using "${approach}" codegen approach`);
|
|
20
|
-
switch (approach) {
|
|
21
|
-
case "event-sink": {
|
|
22
|
-
const canUse = await (0, pw_event_sink_1.canUseEventSinkCodegen)();
|
|
23
|
-
if (!canUse) {
|
|
24
|
-
throw new Error("Cannot use event-sink codegen. Check that RUN_PLAYWRIGHT_HEADED=true.");
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
codegen: new pw_event_sink_1.PlaywrightEventSinkCodegen(),
|
|
28
|
-
approach,
|
|
29
|
-
version,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
case "patch": {
|
|
33
|
-
const canUse = await (0, pw_pause_1.canUsePauseCodegen)(repoDir);
|
|
34
|
-
if (!canUse) {
|
|
35
|
-
throw new Error("Cannot use patch-based codegen. Check requirements: " +
|
|
36
|
-
"RUN_PLAYWRIGHT_HEADED=true, PW_CODEGEN_NO_INSPECTOR=true, and patched recorder.");
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
codegen: new pw_pause_1.PlaywrightPauseCodegen(),
|
|
40
|
-
approach,
|
|
41
|
-
version,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
case "unsupported":
|
|
45
|
-
default:
|
|
46
|
-
throw new Error(`Unsupported Playwright version: ${version.full}. ` +
|
|
47
|
-
"Supported versions: 1.47.x, 1.53.x (patch), 1.57.0+ (event-sink).");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function prepareCodegenIfNeeded(repoDir, approach) {
|
|
51
|
-
if (approach === "patch") {
|
|
52
|
-
logger_1.logger.info("Preparing Playwright for patch-based codegen...");
|
|
53
|
-
await (0, pw_pause_1.preparePatchCodegen)(repoDir);
|
|
54
|
-
}
|
|
55
|
-
else if (approach === "event-sink") {
|
|
56
|
-
logger_1.logger.info("Preparing Playwright for event-sink codegen...");
|
|
57
|
-
await (0, pw_event_sink_1.prepareEventSinkCodegen)(repoDir);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Playwright Codegen - exports for external use
|
|
3
|
-
*/
|
|
4
|
-
export { type CodegenApproach, type CodegenFactoryResult, createPlaywrightCodegen, type PlaywrightVersion, prepareCodegenIfNeeded, } from "./factory";
|
|
5
|
-
export type { BasePlaywrightCodegen } from "./types";
|
|
6
|
-
export { detectPlaywrightVersion, getCodegenApproach, getPlaywrightVersionFromNpmList, parseVersion, } from "./version";
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agent/cua/pw-codegen/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,+BAA+B,EAC/B,YAAY,GACb,MAAM,WAAW,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseVersion = exports.getPlaywrightVersionFromNpmList = exports.getCodegenApproach = exports.detectPlaywrightVersion = exports.prepareCodegenIfNeeded = exports.createPlaywrightCodegen = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Playwright Codegen - exports for external use
|
|
6
|
-
*/
|
|
7
|
-
var factory_1 = require("./factory");
|
|
8
|
-
Object.defineProperty(exports, "createPlaywrightCodegen", { enumerable: true, get: function () { return factory_1.createPlaywrightCodegen; } });
|
|
9
|
-
Object.defineProperty(exports, "prepareCodegenIfNeeded", { enumerable: true, get: function () { return factory_1.prepareCodegenIfNeeded; } });
|
|
10
|
-
var version_1 = require("./version");
|
|
11
|
-
Object.defineProperty(exports, "detectPlaywrightVersion", { enumerable: true, get: function () { return version_1.detectPlaywrightVersion; } });
|
|
12
|
-
Object.defineProperty(exports, "getCodegenApproach", { enumerable: true, get: function () { return version_1.getCodegenApproach; } });
|
|
13
|
-
Object.defineProperty(exports, "getPlaywrightVersionFromNpmList", { enumerable: true, get: function () { return version_1.getPlaywrightVersionFromNpmList; } });
|
|
14
|
-
Object.defineProperty(exports, "parseVersion", { enumerable: true, get: function () { return version_1.parseVersion; } });
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Playwright Codegen using RecorderEventSink API (Playwright 1.57.0+)
|
|
3
|
-
*
|
|
4
|
-
* This implementation uses Playwright's internal RecorderEventSink interface
|
|
5
|
-
* to capture generated code without patching any files.
|
|
6
|
-
*
|
|
7
|
-
* How it works:
|
|
8
|
-
* 1. Call _enableRecorder() with mode: 'recording' and recorderMode: 'api'
|
|
9
|
-
* 2. Playwright's Recorder captures all user actions
|
|
10
|
-
* 3. Events flow to our eventSink callbacks with generated code
|
|
11
|
-
* 4. No inspector UI opens (recorderMode: 'api' skips UI)
|
|
12
|
-
*
|
|
13
|
-
* Requirements:
|
|
14
|
-
* - Playwright 1.57.0 or higher
|
|
15
|
-
* - RUN_PLAYWRIGHT_HEADED=true (recorder needs headed mode)
|
|
16
|
-
* - A small patch to recorderApp.js to allow recorderMode: 'api' with PW_CODEGEN_NO_INSPECTOR
|
|
17
|
-
*/
|
|
18
|
-
import type { BrowserContext, Page } from "playwright";
|
|
19
|
-
import type { BasePlaywrightCodegen } from "../types";
|
|
20
|
-
/**
|
|
21
|
-
* Prepares Playwright 1.57+ for event-sink codegen by patching recorderApp.js
|
|
22
|
-
* to allow recorderMode: 'api' even when PW_CODEGEN_NO_INSPECTOR is set.
|
|
23
|
-
*/
|
|
24
|
-
export declare function prepareEventSinkCodegen(repoDir: string): Promise<void>;
|
|
25
|
-
export declare function canUseEventSinkCodegen(): Promise<boolean>;
|
|
26
|
-
export declare function hasEventSinkSupport(context: BrowserContext): boolean;
|
|
27
|
-
export declare class PlaywrightEventSinkCodegen implements BasePlaywrightCodegen {
|
|
28
|
-
private page;
|
|
29
|
-
private codeBuffer;
|
|
30
|
-
private lastActionPromise;
|
|
31
|
-
private resolveLastAction;
|
|
32
|
-
private lastReturnedEntry;
|
|
33
|
-
private isGettingLastAction;
|
|
34
|
-
private eventSink;
|
|
35
|
-
private notifyActionReceived;
|
|
36
|
-
private waitForNextAction;
|
|
37
|
-
initialize(page: Page): Promise<void>;
|
|
38
|
-
recordAction(): Promise<void>;
|
|
39
|
-
getCodeForLastAction(): Promise<string>;
|
|
40
|
-
private waitForPendingSignals;
|
|
41
|
-
private wrapCodeWithSignals;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent/cua/pw-codegen/pw-event-sink/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AASvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAItD;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC5E;AA8CD,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC,CAa/D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAEpE;AAQD,qBAAa,0BAA2B,YAAW,qBAAqB;IACtE,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,mBAAmB,CAAS;IAEpC,OAAO,CAAC,SAAS,CAkDf;IAEF,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,iBAAiB;IASnB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BrC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;YAuD/B,qBAAqB;IAOnC,OAAO,CAAC,mBAAmB;CA0D5B"}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PlaywrightEventSinkCodegen = void 0;
|
|
7
|
-
exports.prepareEventSinkCodegen = prepareEventSinkCodegen;
|
|
8
|
-
exports.canUseEventSinkCodegen = canUseEventSinkCodegen;
|
|
9
|
-
exports.hasEventSinkSupport = hasEventSinkSupport;
|
|
10
|
-
/**
|
|
11
|
-
* Playwright Codegen using RecorderEventSink API (Playwright 1.57.0+)
|
|
12
|
-
*
|
|
13
|
-
* This implementation uses Playwright's internal RecorderEventSink interface
|
|
14
|
-
* to capture generated code without patching any files.
|
|
15
|
-
*
|
|
16
|
-
* How it works:
|
|
17
|
-
* 1. Call _enableRecorder() with mode: 'recording' and recorderMode: 'api'
|
|
18
|
-
* 2. Playwright's Recorder captures all user actions
|
|
19
|
-
* 3. Events flow to our eventSink callbacks with generated code
|
|
20
|
-
* 4. No inspector UI opens (recorderMode: 'api' skips UI)
|
|
21
|
-
*
|
|
22
|
-
* Requirements:
|
|
23
|
-
* - Playwright 1.57.0 or higher
|
|
24
|
-
* - RUN_PLAYWRIGHT_HEADED=true (recorder needs headed mode)
|
|
25
|
-
* - A small patch to recorderApp.js to allow recorderMode: 'api' with PW_CODEGEN_NO_INSPECTOR
|
|
26
|
-
*/
|
|
27
|
-
const fs_1 = __importDefault(require("fs"));
|
|
28
|
-
const logger_1 = require("../../../../logger");
|
|
29
|
-
const patch_1 = require("../pw-pause/patch");
|
|
30
|
-
const CUSTOM_PATCH_COMMENT = `// Custom patch code set by @empiricalrun/test-gen`;
|
|
31
|
-
/**
|
|
32
|
-
* Prepares Playwright 1.57+ for event-sink codegen by patching recorderApp.js
|
|
33
|
-
* to allow recorderMode: 'api' even when PW_CODEGEN_NO_INSPECTOR is set.
|
|
34
|
-
*/
|
|
35
|
-
async function prepareEventSinkCodegen(repoDir) {
|
|
36
|
-
const npmListOutput = await (0, patch_1.runNpmList)(repoDir);
|
|
37
|
-
if (!npmListOutput) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const pwCorePath = (0, patch_1.getPlaywrightCorePath)(npmListOutput);
|
|
41
|
-
const pathToRecorderApp = await (0, patch_1.getPathToRecorderApp)(pwCorePath);
|
|
42
|
-
const currentFileContents = fs_1.default.readFileSync(pathToRecorderApp, "utf-8");
|
|
43
|
-
// Check if already patched
|
|
44
|
-
if (currentFileContents.includes(CUSTOM_PATCH_COMMENT)) {
|
|
45
|
-
logger_1.logger.debug("Playwright recorder app already patched for event-sink");
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
// Patch RecorderApp.show() to allow recorderMode: 'api' with PW_CODEGEN_NO_INSPECTOR
|
|
49
|
-
const original = `if (process.env.PW_CODEGEN_NO_INSPECTOR)
|
|
50
|
-
return;`;
|
|
51
|
-
const replacement = `${CUSTOM_PATCH_COMMENT}
|
|
52
|
-
if (process.env.PW_CODEGEN_NO_INSPECTOR && params.recorderMode !== 'api')
|
|
53
|
-
return;`;
|
|
54
|
-
if (!currentFileContents.includes(original)) {
|
|
55
|
-
throw new Error("Could not find expected code pattern in recorderApp.js for 1.57+");
|
|
56
|
-
}
|
|
57
|
-
await (0, patch_1.createFileBackup)(pathToRecorderApp);
|
|
58
|
-
const newCode = currentFileContents.replace(original, replacement);
|
|
59
|
-
fs_1.default.writeFileSync(pathToRecorderApp, newCode);
|
|
60
|
-
logger_1.logger.debug(`Patched Playwright recorder app for event-sink at ${pathToRecorderApp}`);
|
|
61
|
-
}
|
|
62
|
-
async function canUseEventSinkCodegen() {
|
|
63
|
-
const isRunningHeaded = process.env.RUN_PLAYWRIGHT_HEADED &&
|
|
64
|
-
process.env.RUN_PLAYWRIGHT_HEADED === "true";
|
|
65
|
-
if (!isRunningHeaded) {
|
|
66
|
-
logger_1.logger.error("Cannot use event sink codegen because RUN_PLAYWRIGHT_HEADED is not true");
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
function hasEventSinkSupport(context) {
|
|
72
|
-
return typeof context._enableRecorder === "function";
|
|
73
|
-
}
|
|
74
|
-
class PlaywrightEventSinkCodegen {
|
|
75
|
-
page;
|
|
76
|
-
codeBuffer = [];
|
|
77
|
-
lastActionPromise;
|
|
78
|
-
resolveLastAction;
|
|
79
|
-
lastReturnedEntry;
|
|
80
|
-
isGettingLastAction = false;
|
|
81
|
-
eventSink = {
|
|
82
|
-
actionAdded: (_page, _action, code) => {
|
|
83
|
-
const actionData = _action;
|
|
84
|
-
const pageAlias = actionData.frame?.pageAlias || "page";
|
|
85
|
-
console.log(`[PlaywrightEventSinkCodegen] Received code from Playwright: ${code}`);
|
|
86
|
-
this.codeBuffer.push({ code, pageAlias, pendingSignals: [] });
|
|
87
|
-
this.notifyActionReceived();
|
|
88
|
-
},
|
|
89
|
-
actionUpdated: (_page, _action, code) => {
|
|
90
|
-
const actionData = _action;
|
|
91
|
-
const pageAlias = actionData.frame?.pageAlias || "page";
|
|
92
|
-
console.log(`[PlaywrightEventSinkCodegen] Updated code from Playwright: ${code}`);
|
|
93
|
-
const lastEntry = this.codeBuffer[this.codeBuffer.length - 1];
|
|
94
|
-
if (lastEntry) {
|
|
95
|
-
lastEntry.code = code;
|
|
96
|
-
lastEntry.pageAlias = pageAlias;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.codeBuffer.push({ code, pageAlias, pendingSignals: [] });
|
|
100
|
-
}
|
|
101
|
-
this.notifyActionReceived();
|
|
102
|
-
},
|
|
103
|
-
signalAdded: (_page, signalContext) => {
|
|
104
|
-
const { signal, frame } = signalContext;
|
|
105
|
-
console.log(`[PlaywrightEventSinkCodegen] Signal: ${signal.name}`);
|
|
106
|
-
if (signal.name === "popup" ||
|
|
107
|
-
signal.name === "download" ||
|
|
108
|
-
signal.name === "dialog") {
|
|
109
|
-
const signalPageAlias = frame.pageAlias;
|
|
110
|
-
// Find most recent action with matching pageAlias
|
|
111
|
-
const targetEntry = [...this.codeBuffer]
|
|
112
|
-
.reverse()
|
|
113
|
-
.find((e) => e.pageAlias === signalPageAlias) ||
|
|
114
|
-
(this.lastReturnedEntry?.pageAlias === signalPageAlias
|
|
115
|
-
? this.lastReturnedEntry
|
|
116
|
-
: undefined);
|
|
117
|
-
if (targetEntry) {
|
|
118
|
-
targetEntry.pendingSignals.push(signal);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
notifyActionReceived() {
|
|
124
|
-
if (this.resolveLastAction) {
|
|
125
|
-
this.resolveLastAction();
|
|
126
|
-
this.resolveLastAction = undefined;
|
|
127
|
-
this.lastActionPromise = undefined;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
waitForNextAction() {
|
|
131
|
-
if (!this.lastActionPromise) {
|
|
132
|
-
this.lastActionPromise = new Promise((resolve) => {
|
|
133
|
-
this.resolveLastAction = resolve;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return this.lastActionPromise;
|
|
137
|
-
}
|
|
138
|
-
async initialize(page) {
|
|
139
|
-
this.page = page;
|
|
140
|
-
this.codeBuffer = [];
|
|
141
|
-
const context = page.context();
|
|
142
|
-
if (!hasEventSinkSupport(context)) {
|
|
143
|
-
throw new Error("Playwright version does not support _enableRecorder API. " +
|
|
144
|
-
"This codegen requires Playwright 1.57.0 or higher.");
|
|
145
|
-
}
|
|
146
|
-
logger_1.logger.debug("[EventSinkCodegen] Enabling recorder with event sink");
|
|
147
|
-
await context._enableRecorder({
|
|
148
|
-
mode: "recording",
|
|
149
|
-
recorderMode: "api",
|
|
150
|
-
language: "javascript",
|
|
151
|
-
}, this.eventSink);
|
|
152
|
-
logger_1.logger.debug("[EventSinkCodegen] Recorder enabled, ready to capture actions");
|
|
153
|
-
}
|
|
154
|
-
async recordAction() {
|
|
155
|
-
// No-op: Playwright's recorder automatically captures actions
|
|
156
|
-
// when they are performed on the page
|
|
157
|
-
}
|
|
158
|
-
async getCodeForLastAction() {
|
|
159
|
-
// Guard against concurrent calls
|
|
160
|
-
if (this.isGettingLastAction) {
|
|
161
|
-
throw new Error("getCodeForLastAction must not be called concurrently");
|
|
162
|
-
}
|
|
163
|
-
this.isGettingLastAction = true;
|
|
164
|
-
try {
|
|
165
|
-
// If we already have code buffered, wait briefly for any signals that may arrive
|
|
166
|
-
if (this.codeBuffer.length > 0) {
|
|
167
|
-
const entry = this.codeBuffer.pop();
|
|
168
|
-
this.lastReturnedEntry = entry;
|
|
169
|
-
await this.waitForPendingSignals();
|
|
170
|
-
this.lastReturnedEntry = undefined;
|
|
171
|
-
const finalCode = this.wrapCodeWithSignals(entry);
|
|
172
|
-
console.log(`[PlaywrightEventSinkCodegen] Generated code:\n${finalCode}`);
|
|
173
|
-
return finalCode;
|
|
174
|
-
}
|
|
175
|
-
// Wait for an action to be recorded, with timeout
|
|
176
|
-
const timeoutMs = 5000;
|
|
177
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
178
|
-
setTimeout(() => reject(new Error("Timeout waiting for recorded action")), timeoutMs);
|
|
179
|
-
});
|
|
180
|
-
try {
|
|
181
|
-
await Promise.race([this.waitForNextAction(), timeoutPromise]);
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
throw new Error("No code for last action: " + error.message);
|
|
185
|
-
}
|
|
186
|
-
if (this.codeBuffer.length === 0) {
|
|
187
|
-
throw new Error("No code for last action");
|
|
188
|
-
}
|
|
189
|
-
const entry = this.codeBuffer.pop();
|
|
190
|
-
this.lastReturnedEntry = entry;
|
|
191
|
-
// Wait briefly for signals that may arrive after the action
|
|
192
|
-
await this.waitForPendingSignals();
|
|
193
|
-
this.lastReturnedEntry = undefined;
|
|
194
|
-
const finalCode = this.wrapCodeWithSignals(entry);
|
|
195
|
-
console.log(`[PlaywrightEventSinkCodegen] Generated code:\n${finalCode}`);
|
|
196
|
-
return finalCode;
|
|
197
|
-
}
|
|
198
|
-
finally {
|
|
199
|
-
this.isGettingLastAction = false;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async waitForPendingSignals() {
|
|
203
|
-
// Wait a fixed time window to capture signals that arrive after the action
|
|
204
|
-
// Signals typically arrive within a few hundred ms
|
|
205
|
-
const timeoutMs = 500;
|
|
206
|
-
await new Promise((resolve) => setTimeout(resolve, timeoutMs));
|
|
207
|
-
}
|
|
208
|
-
wrapCodeWithSignals(entry) {
|
|
209
|
-
const { code, pageAlias, pendingSignals } = entry;
|
|
210
|
-
if (pendingSignals.length === 0) {
|
|
211
|
-
return code;
|
|
212
|
-
}
|
|
213
|
-
const lines = [];
|
|
214
|
-
let popup;
|
|
215
|
-
let download;
|
|
216
|
-
let dialog;
|
|
217
|
-
for (const signal of pendingSignals) {
|
|
218
|
-
if (signal.name === "popup") {
|
|
219
|
-
popup = signal;
|
|
220
|
-
}
|
|
221
|
-
else if (signal.name === "download") {
|
|
222
|
-
download = signal;
|
|
223
|
-
}
|
|
224
|
-
else if (signal.name === "dialog") {
|
|
225
|
-
dialog = signal;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (dialog) {
|
|
229
|
-
lines.push(` ${pageAlias}.once('dialog', dialog => {
|
|
230
|
-
console.log(\`Dialog message: \${dialog.message()}\`);
|
|
231
|
-
dialog.dismiss().catch(() => {});
|
|
232
|
-
});`);
|
|
233
|
-
}
|
|
234
|
-
if (popup) {
|
|
235
|
-
lines.push(`const ${popup.popupAlias}Promise = ${pageAlias}.waitForEvent('popup');`);
|
|
236
|
-
}
|
|
237
|
-
if (download) {
|
|
238
|
-
lines.push(`const download${download.downloadAlias}Promise = ${pageAlias}.waitForEvent('download');`);
|
|
239
|
-
}
|
|
240
|
-
lines.push(code);
|
|
241
|
-
if (popup) {
|
|
242
|
-
lines.push(`const ${popup.popupAlias} = await ${popup.popupAlias}Promise;`);
|
|
243
|
-
}
|
|
244
|
-
if (download) {
|
|
245
|
-
lines.push(`const download${download.downloadAlias} = await download${download.downloadAlias}Promise;`);
|
|
246
|
-
}
|
|
247
|
-
return lines.join("\n");
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.PlaywrightEventSinkCodegen = PlaywrightEventSinkCodegen;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Page } from "playwright";
|
|
2
|
-
import { SourcesPayload } from "./types";
|
|
3
|
-
export declare class PlaywrightPauseCodegenForRecorder {
|
|
4
|
-
private sourcesCallback;
|
|
5
|
-
private port;
|
|
6
|
-
private page;
|
|
7
|
-
private server;
|
|
8
|
-
private codeForLastAction;
|
|
9
|
-
constructor(sourcesCallback: (code: SourcesPayload[]) => Promise<void>);
|
|
10
|
-
private saveCode;
|
|
11
|
-
initialize(page: Page): Promise<void>;
|
|
12
|
-
startPlaywrightCodegen(page: Page): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=for-recorder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"for-recorder.d.ts","sourceRoot":"","sources":["../../../../../src/agent/cua/pw-codegen/pw-pause/for-recorder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,qBAAa,iCAAiC;IAO1C,OAAO,CAAC,eAAe;IANzB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,MAAM,CAA4C;IAC1D,OAAO,CAAC,iBAAiB,CAAqB;gBAGpC,eAAe,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC;YAKtD,QAAQ;IAQhB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBrC,sBAAsB,CAAC,IAAI,EAAE,IAAI;CA0CxC"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PlaywrightPauseCodegenForRecorder = void 0;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const logger_1 = require("../../../../logger");
|
|
9
|
-
const ipc_1 = require("./ipc");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
class PlaywrightPauseCodegenForRecorder {
|
|
12
|
-
sourcesCallback;
|
|
13
|
-
port = 0;
|
|
14
|
-
page;
|
|
15
|
-
server;
|
|
16
|
-
codeForLastAction;
|
|
17
|
-
constructor(sourcesCallback) {
|
|
18
|
-
this.sourcesCallback = sourcesCallback;
|
|
19
|
-
this.port = ipc_1.PW_PAUSE_IPC_PORT;
|
|
20
|
-
}
|
|
21
|
-
async saveCode(code) {
|
|
22
|
-
const generatedCode = code.map((c) => c.actions.join("\n")).join("\n");
|
|
23
|
-
if (generatedCode) {
|
|
24
|
-
this.codeForLastAction = generatedCode;
|
|
25
|
-
await this.sourcesCallback(code);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async initialize(page) {
|
|
29
|
-
// Start server to receive generated code from patch
|
|
30
|
-
const app = (0, express_1.default)();
|
|
31
|
-
app.use(express_1.default.json());
|
|
32
|
-
app.post("/sources", async (req, res) => {
|
|
33
|
-
const { payload } = req.body;
|
|
34
|
-
await this.saveCode(JSON.parse(payload));
|
|
35
|
-
return res.send({ success: true });
|
|
36
|
-
});
|
|
37
|
-
await new Promise((resolve) => {
|
|
38
|
-
this.server = app.listen(this.port, () => resolve());
|
|
39
|
-
});
|
|
40
|
-
logger_1.logger.debug(`Server started on port ${this.port}`);
|
|
41
|
-
// Start page.pause experience in the page
|
|
42
|
-
this.page = page;
|
|
43
|
-
await this.startPlaywrightCodegen(page);
|
|
44
|
-
}
|
|
45
|
-
async startPlaywrightCodegen(page) {
|
|
46
|
-
// TODO: Merge this with the other page.pause oriented codegen
|
|
47
|
-
const browserContext = page.context();
|
|
48
|
-
await browserContext.addInitScript(() => {
|
|
49
|
-
let displayNoneSet = false;
|
|
50
|
-
function setDisplayNone() {
|
|
51
|
-
const glassPane = document.querySelector("x-pw-glass");
|
|
52
|
-
if (glassPane) {
|
|
53
|
-
const styles = glassPane.getAttribute("style") || "";
|
|
54
|
-
glassPane.setAttribute("style", styles + "; display: none;");
|
|
55
|
-
displayNoneSet = true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
let interval = setInterval(() => {
|
|
59
|
-
if (displayNoneSet) {
|
|
60
|
-
clearInterval(interval);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
setDisplayNone();
|
|
64
|
-
}, 100);
|
|
65
|
-
});
|
|
66
|
-
const pausePromise = page.pause();
|
|
67
|
-
await (0, utils_1.sleep)(5_000);
|
|
68
|
-
const startRecordingWithoutGlassPane = page.evaluate(() => {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
window["__pw_recorderSetMode"]("recording");
|
|
71
|
-
// Remove playwright's glass pane
|
|
72
|
-
/**
|
|
73
|
-
* x-pw-glass
|
|
74
|
-
* # inside shadow DOM (closed)
|
|
75
|
-
* |----> x-pw-overlay (controls)
|
|
76
|
-
* |----> x-pw-highlight (red highlight)
|
|
77
|
-
* |----> x-pw-tooltip
|
|
78
|
-
*/
|
|
79
|
-
const glassPane = document.querySelector("x-pw-glass");
|
|
80
|
-
if (glassPane) {
|
|
81
|
-
const styles = glassPane.getAttribute("style") || "";
|
|
82
|
-
glassPane.setAttribute("style", styles + "; display: none;");
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
await Promise.all([pausePromise, startRecordingWithoutGlassPane]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.PlaywrightPauseCodegenForRecorder = PlaywrightPauseCodegenForRecorder;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Page } from "playwright";
|
|
2
|
-
import { BasePlaywrightCodegen } from "../types";
|
|
3
|
-
export { createFileBackup, getPathToRecorderApp, getPlaywrightCorePath, preparePatchCodegen, revertToOriginalPwCode, runNpmList, } from "./patch";
|
|
4
|
-
export declare function canUsePauseCodegen(repoDir: string): Promise<boolean>;
|
|
5
|
-
export declare class PlaywrightPauseCodegen implements BasePlaywrightCodegen {
|
|
6
|
-
private port;
|
|
7
|
-
private page;
|
|
8
|
-
private server;
|
|
9
|
-
private codeForLastAction;
|
|
10
|
-
constructor();
|
|
11
|
-
private saveCode;
|
|
12
|
-
initialize(page: Page): Promise<void>;
|
|
13
|
-
startPlaywrightCodegen(page: Page): Promise<void>;
|
|
14
|
-
recordAction(): Promise<void>;
|
|
15
|
-
getCodeForLastAction(): Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|