@empiricalrun/playwright-utils 0.70.3 → 0.71.0
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 +14 -0
- package/dist/api-worker-client.d.ts +5 -1
- package/dist/api-worker-client.d.ts.map +1 -1
- package/dist/api-worker-client.js +15 -0
- package/dist/generated/api-worker-openapi.d.ts +306 -211
- package/dist/generated/api-worker-openapi.d.ts.map +1 -1
- package/dist/overlay-test-expectations.d.ts +10 -0
- package/dist/overlay-test-expectations.d.ts.map +1 -0
- package/dist/overlay-test-expectations.js +51 -0
- package/dist/overlay-tests/click.spec.js +26 -94
- package/dist/overlay-tests/dropdown.spec.js +10 -9
- package/dist/overlay-tests/fixtures.d.ts +1 -0
- package/dist/overlay-tests/fixtures.d.ts.map +1 -1
- package/dist/overlay-tests/fixtures.js +24 -0
- package/dist/overlay-tests/visual.spec.js +1 -11
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +10 -0
- package/dist/test/locator-handler-log.spec.d.ts +2 -0
- package/dist/test/locator-handler-log.spec.d.ts.map +1 -0
- package/dist/test/locator-handler-log.spec.js +44 -0
- package/dist/test/scripts/locator-handler-log.d.ts +23 -0
- package/dist/test/scripts/locator-handler-log.d.ts.map +1 -0
- package/dist/test/scripts/locator-handler-log.js +105 -0
- package/dist/test/scripts/pw-locator-patch/actions/click.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/actions/click.js +17 -34
- package/dist/test/scripts/pw-locator-patch/actions/hover.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/actions/hover.js +11 -25
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts +21 -4
- 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 +113 -18
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts +2 -3
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.js +6 -52
- package/dist/webhook.d.ts +1 -6
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +12 -124
- package/package.json +3 -3
- package/playwright.config.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/overlay-tests/typesafe-hit-check.spec.d.ts +0 -2
- package/dist/overlay-tests/typesafe-hit-check.spec.d.ts.map +0 -1
- package/dist/overlay-tests/typesafe-hit-check.spec.js +0 -57
- package/dist/overlay-tests/typesafe.spec.d.ts +0 -2
- package/dist/overlay-tests/typesafe.spec.d.ts.map +0 -1
- package/dist/overlay-tests/typesafe.spec.js +0 -88
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts +0 -38
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts.map +0 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.js +0 -159
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/actions/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,wBAAgB,UAAU,CACxB,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,EAC/C,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/actions/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,wBAAgB,UAAU,CACxB,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,EAC/C,MAAM,EAAE,MAAM,QA+Bf"}
|
|
@@ -14,32 +14,18 @@ function patchHover(LocatorClass, testFn) {
|
|
|
14
14
|
LocatorClass.prototype.hover = async function (options) {
|
|
15
15
|
const stepName = `locator.hover(${(0, utils_2.description)(this)})`;
|
|
16
16
|
return await testFn.step(stepName, async () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const overlayDismiss = new dismiss_overlays_1.OverlayDismissAgent(this._frame._page);
|
|
20
|
-
while (overlayAttemptsRemaining >= 0) {
|
|
21
|
-
overlayAttemptsRemaining--;
|
|
22
|
-
try {
|
|
23
|
-
let result = await originalHover.apply(this, [options]);
|
|
24
|
-
await overlayDismiss.saveToCache();
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
originalError = error;
|
|
29
|
-
if (originalError instanceof Error) {
|
|
30
|
-
Error.captureStackTrace(originalError, LocatorClass.prototype.hover);
|
|
31
|
-
}
|
|
32
|
-
if (options?.isExecutingForOverlayDismiss) {
|
|
33
|
-
throw originalError;
|
|
34
|
-
}
|
|
35
|
-
if (!(0, dismiss_overlays_1.isErrorSupported)(originalError.message)) {
|
|
36
|
-
throw originalError;
|
|
37
|
-
}
|
|
38
|
-
await overlayDismiss.run(originalError, reporter, testFn);
|
|
39
|
-
reporter(`Overlay dismissal attempted, retrying original action.`);
|
|
40
|
-
}
|
|
17
|
+
if (options?.isExecutingForOverlayDismiss) {
|
|
18
|
+
return await originalHover.apply(this, [options]);
|
|
41
19
|
}
|
|
42
|
-
|
|
20
|
+
return await (0, dismiss_overlays_1.withOverlayDismissal)({
|
|
21
|
+
page: this._frame._page,
|
|
22
|
+
action: "hover",
|
|
23
|
+
target: this,
|
|
24
|
+
act: (extra) => originalHover.apply(this, [{ ...options, ...extra }]),
|
|
25
|
+
reporter,
|
|
26
|
+
testFn,
|
|
27
|
+
stackFrom: LocatorClass.prototype.hover,
|
|
28
|
+
});
|
|
43
29
|
}, { box: true });
|
|
44
30
|
};
|
|
45
31
|
isHoverPatched.set(LocatorClass, true);
|
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import { type ClickMode } from "@empiricalrun/cua";
|
|
2
|
-
import { Page } from "@playwright/test";
|
|
1
|
+
import { type BlockedStep, type ClickMode, type ComputerUseModel } from "@empiricalrun/cua";
|
|
2
|
+
import type { Locator, Page } from "@playwright/test";
|
|
3
3
|
import type { TestFn } from "../../types";
|
|
4
4
|
import type { OverlayElement } from "./types";
|
|
5
5
|
export declare function overlayClickMode(): ClickMode;
|
|
6
|
+
export declare function overlayAgentModel(): ComputerUseModel;
|
|
6
7
|
export declare function isErrorSupported(errorMessage: string | undefined): boolean;
|
|
8
|
+
type ActOptions = Parameters<BlockedStep["retry"]>[0];
|
|
9
|
+
type DismissOutcome = "dismissed" | "action_done";
|
|
10
|
+
export declare function withOverlayDismissal<T>({ page, action, target, act, reporter, testFn, stackFrom, }: {
|
|
11
|
+
page: Page;
|
|
12
|
+
action: BlockedStep["action"];
|
|
13
|
+
target: Locator;
|
|
14
|
+
act: (options?: ActOptions) => Promise<T>;
|
|
15
|
+
reporter: (description: string) => void;
|
|
16
|
+
testFn: TestFn;
|
|
17
|
+
stackFrom: Function;
|
|
18
|
+
}): Promise<T | undefined>;
|
|
7
19
|
export declare class OverlayDismissAgent {
|
|
8
20
|
private readonly page;
|
|
21
|
+
private readonly blocked?;
|
|
9
22
|
private cachingCandidates;
|
|
10
|
-
|
|
23
|
+
private cacheTried;
|
|
24
|
+
private lastActionError;
|
|
25
|
+
constructor(page: Page, blocked?: BlockedStep | undefined);
|
|
11
26
|
saveToCache(): Promise<void>;
|
|
12
|
-
run(originalError: any, reporter: (description: string) => void, testFn: TestFn): Promise<
|
|
27
|
+
run(originalError: any, reporter: (description: string) => void, testFn: TestFn): Promise<DismissOutcome>;
|
|
13
28
|
private dismiss;
|
|
29
|
+
private runInvestigator;
|
|
14
30
|
private runAgent;
|
|
15
31
|
}
|
|
16
32
|
export declare function extractInterceptingElement(errorMessage: string): OverlayElement | undefined;
|
|
33
|
+
export {};
|
|
17
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EAGtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAOtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C,wBAAgB,gBAAgB,IAAI,SAAS,CAI5C;AAED,wBAAgB,iBAAiB,IAAI,gBAAgB,CAIpD;AAQD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,KAAK,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtD,KAAK,cAAc,GAAG,WAAW,GAAG,aAAa,CAAC;AAElD,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,EAC5C,IAAI,EACJ,MAAM,EACN,MAAM,EACN,GAAG,EACH,QAAQ,EACR,MAAM,EACN,SAAS,GACV,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1C,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,CAAC;CACrB,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAiCzB;AAED,qBAAa,mBAAmB;IAY5B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAZ3B,OAAO,CAAC,iBAAiB,CAIhB;IAET,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,eAAe,CAAU;IAEjC,YACmB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,WAAW,YAAA,EACpC;IAEE,WAAW,kBAIhB;IAEK,GAAG,CACP,aAAa,EAAE,GAAG,EAClB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,CAAC,CAUzB;YAEa,OAAO;YAsEP,eAAe;YAmDf,QAAQ;CAkCvB;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GACnB,cAAc,GAAG,SAAS,CAiC5B"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OverlayDismissAgent = void 0;
|
|
4
4
|
exports.overlayClickMode = overlayClickMode;
|
|
5
|
+
exports.overlayAgentModel = overlayAgentModel;
|
|
5
6
|
exports.isErrorSupported = isErrorSupported;
|
|
7
|
+
exports.withOverlayDismissal = withOverlayDismissal;
|
|
6
8
|
exports.extractInterceptingElement = extractInterceptingElement;
|
|
7
9
|
const cua_1 = require("@empiricalrun/cua");
|
|
8
10
|
const api_worker_client_1 = require("../../../../api-worker-client");
|
|
@@ -16,17 +18,66 @@ function overlayClickMode() {
|
|
|
16
18
|
? "dispatch"
|
|
17
19
|
: "mouse";
|
|
18
20
|
}
|
|
21
|
+
function overlayAgentModel() {
|
|
22
|
+
return process.env.EMPIRICALRUN_OVERLAY_MODEL === "claude-haiku-5-5"
|
|
23
|
+
? "claude-haiku-5-5"
|
|
24
|
+
: "gpt-5.4";
|
|
25
|
+
}
|
|
26
|
+
function llmClientConfig(model) {
|
|
27
|
+
return model === "claude-haiku-5-5"
|
|
28
|
+
? { anthropicClientConfig: (0, api_worker_client_1.llmProxyAnthropicConfig)() }
|
|
29
|
+
: { openAIClientConfig: (0, api_worker_client_1.llmProxyOpenAIConfig)() };
|
|
30
|
+
}
|
|
19
31
|
function isErrorSupported(errorMessage) {
|
|
20
32
|
if (!errorMessage) {
|
|
21
33
|
return false;
|
|
22
34
|
}
|
|
23
35
|
return errorMessage.includes(ERROR_SUBSTRING_INTERCEPTION);
|
|
24
36
|
}
|
|
37
|
+
async function withOverlayDismissal({ page, action, target, act, reporter, testFn, stackFrom, }) {
|
|
38
|
+
const overlayDismiss = new OverlayDismissAgent(page, {
|
|
39
|
+
action,
|
|
40
|
+
target,
|
|
41
|
+
retry: async (options) => {
|
|
42
|
+
await act(options);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
for (let attemptsLeft = 2;; attemptsLeft--) {
|
|
46
|
+
let error;
|
|
47
|
+
try {
|
|
48
|
+
const result = await act();
|
|
49
|
+
await overlayDismiss.saveToCache();
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
catch (caught) {
|
|
53
|
+
error = caught;
|
|
54
|
+
}
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
Error.captureStackTrace(error, stackFrom);
|
|
57
|
+
}
|
|
58
|
+
// TODO: Playwright actionability checks have precedence: if an overlay blocks a
|
|
59
|
+
// disabled button, the error will not show interception -- it will focus on "not enabled".
|
|
60
|
+
// This will cause our overlay dismissal to not run.
|
|
61
|
+
if (attemptsLeft === 0 || !isErrorSupported(error?.message)) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
const outcome = await overlayDismiss.run(error, reporter, testFn);
|
|
65
|
+
if (outcome === "action_done") {
|
|
66
|
+
await overlayDismiss.saveToCache();
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
reporter(`Overlay dismissal attempted, retrying original action.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
25
72
|
class OverlayDismissAgent {
|
|
26
73
|
page;
|
|
74
|
+
blocked;
|
|
27
75
|
cachingCandidates = [];
|
|
28
|
-
|
|
76
|
+
cacheTried = false;
|
|
77
|
+
lastActionError;
|
|
78
|
+
constructor(page, blocked) {
|
|
29
79
|
this.page = page;
|
|
80
|
+
this.blocked = blocked;
|
|
30
81
|
}
|
|
31
82
|
async saveToCache() {
|
|
32
83
|
for (const candidate of this.cachingCandidates) {
|
|
@@ -39,7 +90,7 @@ class OverlayDismissAgent {
|
|
|
39
90
|
element = extractInterceptingElement(originalError.message);
|
|
40
91
|
}
|
|
41
92
|
catch { }
|
|
42
|
-
await testFn.step((0, utils_1.dismissOverlayStepTitle)(element), () => this.dismiss(element, originalError, reporter, testFn), { box: true });
|
|
93
|
+
return await testFn.step((0, utils_1.dismissOverlayStepTitle)(element), () => this.dismiss(element, originalError, reporter, testFn), { box: true });
|
|
43
94
|
}
|
|
44
95
|
async dismiss(element, originalError, reporter, testFn) {
|
|
45
96
|
const startTime = Date.now();
|
|
@@ -54,21 +105,27 @@ class OverlayDismissAgent {
|
|
|
54
105
|
original: originalFailingLocator(originalError.message),
|
|
55
106
|
};
|
|
56
107
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await (0, telemetry_1.trackOverlayDismissed)({
|
|
64
|
-
...eventProps,
|
|
65
|
-
cache: true,
|
|
66
|
-
success: true,
|
|
67
|
-
durationMs: Date.now() - startTime,
|
|
108
|
+
if (!this.cacheTried) {
|
|
109
|
+
this.cacheTried = true;
|
|
110
|
+
const { success } = await (0, cache_1.executeFromCache)({
|
|
111
|
+
page: this.page,
|
|
112
|
+
dom: element?.interceptor,
|
|
113
|
+
text,
|
|
68
114
|
});
|
|
69
|
-
|
|
115
|
+
if (success) {
|
|
116
|
+
await (0, telemetry_1.trackOverlayDismissed)({
|
|
117
|
+
...eventProps,
|
|
118
|
+
cache: true,
|
|
119
|
+
success: true,
|
|
120
|
+
durationMs: Date.now() - startTime,
|
|
121
|
+
});
|
|
122
|
+
return "dismissed";
|
|
123
|
+
}
|
|
70
124
|
}
|
|
71
|
-
const
|
|
125
|
+
const investigates = process.env.EMPIRICALRUN_OVERLAY_AGENT === "investigator";
|
|
126
|
+
const usage = investigates
|
|
127
|
+
? await this.runInvestigator(element, text, originalError, reporter, testFn)
|
|
128
|
+
: await this.runAgent(element, text, testFn);
|
|
72
129
|
await (0, telemetry_1.trackOverlayDismissed)({
|
|
73
130
|
...eventProps,
|
|
74
131
|
cache: false,
|
|
@@ -77,6 +134,7 @@ class OverlayDismissAgent {
|
|
|
77
134
|
cost: usage.cost,
|
|
78
135
|
durationMs: Date.now() - startTime,
|
|
79
136
|
});
|
|
137
|
+
return investigates ? "action_done" : "dismissed";
|
|
80
138
|
}
|
|
81
139
|
catch (agentError) {
|
|
82
140
|
reporter(`Error during overlay dismissal agent execution: ${agentError.toString()}`);
|
|
@@ -86,11 +144,47 @@ class OverlayDismissAgent {
|
|
|
86
144
|
success: false,
|
|
87
145
|
durationMs: Date.now() - startTime,
|
|
88
146
|
});
|
|
89
|
-
throw originalError;
|
|
147
|
+
throw this.lastActionError ?? originalError;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async runInvestigator(element, text, originalError, reporter, testFn) {
|
|
151
|
+
const info = testFn.info();
|
|
152
|
+
const original = this.blocked;
|
|
153
|
+
const blocked = original && {
|
|
154
|
+
...original,
|
|
155
|
+
retry: async (options) => {
|
|
156
|
+
try {
|
|
157
|
+
await original.retry(options);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
this.lastActionError = error;
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
const { finish, action, code, usage } = await testFn.step(utils_1.DISMISSAL_AGENT_STEP, () => (0, cua_1.investigateBlocker)({
|
|
166
|
+
page: this.page,
|
|
167
|
+
blocked,
|
|
168
|
+
originalError,
|
|
169
|
+
test: { titlePath: info.titlePath, file: info.file },
|
|
170
|
+
testSuiteRoot: process.env.EMPIRICALRUN_OVERLAY_INVESTIGATOR_ROOT ?? process.cwd(),
|
|
171
|
+
anthropicClientConfig: (0, api_worker_client_1.llmProxyAnthropicConfig)(),
|
|
172
|
+
log: console.log,
|
|
173
|
+
}));
|
|
174
|
+
if (finish) {
|
|
175
|
+
reporter(`Blocker: ${finish.kind}. ${finish.diagnosis} Action: ${finish.summary}`);
|
|
176
|
+
}
|
|
177
|
+
if (!action.done) {
|
|
178
|
+
throw new Error(finish?.diagnosis ?? "Investigator did not finish");
|
|
179
|
+
}
|
|
180
|
+
if (code && !action.position) {
|
|
181
|
+
this.cachingCandidates.push({ dom: element?.interceptor, text, code });
|
|
90
182
|
}
|
|
183
|
+
return usage;
|
|
91
184
|
}
|
|
92
185
|
async runAgent(element, text, testFn) {
|
|
93
|
-
const task =
|
|
186
|
+
const task = (0, prompt_1.getTask)(element, text);
|
|
187
|
+
const model = overlayAgentModel();
|
|
94
188
|
const result = await testFn.step(utils_1.DISMISSAL_AGENT_STEP, () => (0, cua_1.createTestUsingComputerUseAgent)({
|
|
95
189
|
page: this.page,
|
|
96
190
|
task,
|
|
@@ -102,7 +196,8 @@ class OverlayDismissAgent {
|
|
|
102
196
|
// Ran into this here: https://empirical.run/quizizz-tests/sessions/2825
|
|
103
197
|
prefersElementFromPointCodegen: true,
|
|
104
198
|
includePageGotoTool: false,
|
|
105
|
-
|
|
199
|
+
model,
|
|
200
|
+
...llmClientConfig(model),
|
|
106
201
|
clickMode: overlayClickMode(),
|
|
107
202
|
}));
|
|
108
203
|
this.cachingCandidates.push({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function getTask(page: Page, element: OverlayElement | undefined, text: string | undefined): Promise<string>;
|
|
1
|
+
import type { OverlayElement } from "./types";
|
|
2
|
+
export declare function getTask(element: OverlayElement | undefined, text: string | undefined): string;
|
|
4
3
|
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/prompt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,wBAAgB,OAAO,CACrB,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,IAAI,EAAE,MAAM,GAAG,SAAS,UAMzB"}
|
|
@@ -1,57 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTask = getTask;
|
|
4
|
+
const cua_1 = require("@empiricalrun/cua");
|
|
4
5
|
const utils_1 = require("./utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
?
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<popup_text_content>
|
|
11
|
-
${text}
|
|
12
|
-
</popup_text_content>
|
|
13
|
-
`
|
|
14
|
-
: "";
|
|
15
|
-
if ((0, utils_1.isProductFruitsOverlay)(element)) {
|
|
16
|
-
promptAddition = promptForPFScenario(text);
|
|
17
|
-
}
|
|
18
|
-
let task = `
|
|
19
|
-
# General instructions for your task
|
|
20
|
-
|
|
21
|
-
Find a way to dismiss the popup. If the popup is non dismissible or there is no popup then return immediately.
|
|
22
|
-
Do all actions required to dismiss the popup - don't ask for user confirmation.
|
|
23
|
-
|
|
24
|
-
Note that you just need to dismiss popup and DO NOTHING ELSE. If you do more steps, the remainder
|
|
25
|
-
of the workflow will fail, because ONLY the popup is expected to be dismissed by your actions.
|
|
26
|
-
|
|
27
|
-
Examples of typical popups:
|
|
28
|
-
1. Feature announcements, which can be generally dismissed by close/dismiss buttons.
|
|
29
|
-
2. Product tours which might require going through the tour steps.
|
|
30
|
-
3. Consents for cookies or updated terms of service, which can be dismissed by clicking on the accept/continue button.
|
|
31
|
-
4. Forms that capture traffic sources or persona information. Make up content for the input fields, if that's required to dismiss the popup.
|
|
32
|
-
5. Anything else that can be dismissed by taking a few user actions.
|
|
33
|
-
|
|
34
|
-
# Instructions for this specific scenario
|
|
35
|
-
|
|
36
|
-
${promptAddition}`;
|
|
37
|
-
return task;
|
|
38
|
-
}
|
|
39
|
-
function promptForPFScenario(text) {
|
|
40
|
-
const promptAddition = text
|
|
41
|
-
? `The Overlapper element can be identifed with the following text content:
|
|
42
|
-
|
|
43
|
-
<overlapper_element_text_content>
|
|
44
|
-
${text}
|
|
45
|
-
</overlapper_element_text_content>`
|
|
46
|
-
: "";
|
|
47
|
-
return `
|
|
48
|
-
We are attempting to do a click action on Target element.
|
|
49
|
-
|
|
50
|
-
This action is failing because our Target element is covered with another element (called Overlapper).
|
|
51
|
-
${promptAddition}
|
|
52
|
-
|
|
53
|
-
The only way to work around this is to Click on some other sidebar link element.
|
|
54
|
-
|
|
55
|
-
Don't reattempt the click on Target element, your job is done after the first click.
|
|
56
|
-
`;
|
|
6
|
+
function getTask(element, text) {
|
|
7
|
+
const scenario = (0, utils_1.isProductFruitsOverlay)(element)
|
|
8
|
+
? cua_1.overlayTaskPrompts.productFruits(text)
|
|
9
|
+
: cua_1.overlayTaskPrompts.popupText(text);
|
|
10
|
+
return cua_1.overlayTaskPrompts.task(scenario);
|
|
57
11
|
}
|
package/dist/webhook.d.ts
CHANGED
|
@@ -13,11 +13,6 @@ export type WebhookRequest = {
|
|
|
13
13
|
created_at: string;
|
|
14
14
|
updated_at: string;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
export declare function getWebhookUrl(options?: {
|
|
18
|
-
expiry?: number | null;
|
|
19
|
-
provider?: WebhookProvider;
|
|
20
|
-
}): Promise<string>;
|
|
16
|
+
export declare function getWebhookUrl(): Promise<string>;
|
|
21
17
|
export declare function queryWebhookRequests(webhookUrl: string, content: string | string[]): Promise<WebhookRequest[]>;
|
|
22
|
-
export {};
|
|
23
18
|
//# sourceMappingURL=webhook.d.ts.map
|
package/dist/webhook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAgDF,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAGrD;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GACzB,OAAO,CAAC,cAAc,EAAE,CAAC,CAQ3B"}
|
package/dist/webhook.js
CHANGED
|
@@ -3,101 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getWebhookUrl = getWebhookUrl;
|
|
4
4
|
exports.queryWebhookRequests = queryWebhookRequests;
|
|
5
5
|
const api_worker_client_1 = require("./api-worker-client");
|
|
6
|
-
const WEBHOOK_SITE_BASE_URL = "https://webhook.site";
|
|
7
|
-
const DEFAULT_TOKEN_EXPIRY = 604800;
|
|
8
|
-
function escapeQueryTerm(term) {
|
|
9
|
-
return term.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
10
|
-
}
|
|
11
|
-
function buildContentQuery(content) {
|
|
12
|
-
const terms = Array.isArray(content) ? content : [content];
|
|
13
|
-
if (terms.length === 0 || terms.some((t) => t.length === 0)) {
|
|
14
|
-
throw new Error("content must be a non-empty string or string[]");
|
|
15
|
-
}
|
|
16
|
-
return terms.map((t) => `content:"${escapeQueryTerm(t)}"`).join(" AND ");
|
|
17
|
-
}
|
|
18
|
-
async function webhookSiteGetUrl(options) {
|
|
19
|
-
const expiry = options.expiry === undefined ? DEFAULT_TOKEN_EXPIRY : options.expiry;
|
|
20
|
-
if (process.env.EMPIRICALRUN_API_KEY) {
|
|
21
|
-
const apiClient = new api_worker_client_1.ApiWorkerClient();
|
|
22
|
-
const result = await apiClient.postProviderProxy("/api/webhook-site/proxy", {
|
|
23
|
-
method: "POST",
|
|
24
|
-
path: "/token",
|
|
25
|
-
body: { expiry },
|
|
26
|
-
});
|
|
27
|
-
const tokenData = result.data;
|
|
28
|
-
return `${WEBHOOK_SITE_BASE_URL}/${tokenData.uuid}`;
|
|
29
|
-
}
|
|
30
|
-
const apiKey = process.env.WEBHOOK_SITE_API_KEY;
|
|
31
|
-
if (!apiKey) {
|
|
32
|
-
throw new Error("Either EMPIRICALRUN_API_KEY or WEBHOOK_SITE_API_KEY must be set");
|
|
33
|
-
}
|
|
34
|
-
const response = await fetch(`${WEBHOOK_SITE_BASE_URL}/token`, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: {
|
|
37
|
-
"Api-Key": apiKey,
|
|
38
|
-
"Content-Type": "application/json",
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify({ expiry }),
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
const body = await response.text().catch(() => "");
|
|
44
|
-
throw new Error(`webhook.site error [${response.status} ${response.statusText}]: ${body}`);
|
|
45
|
-
}
|
|
46
|
-
const { uuid } = await response.json();
|
|
47
|
-
return `${WEBHOOK_SITE_BASE_URL}/${uuid}`;
|
|
48
|
-
}
|
|
49
|
-
async function webhookSiteQueryViaProxy(token, content) {
|
|
50
|
-
const apiClient = new api_worker_client_1.ApiWorkerClient();
|
|
51
|
-
const params = new URLSearchParams({
|
|
52
|
-
query: buildContentQuery(content),
|
|
53
|
-
sorting: "newest",
|
|
54
|
-
per_page: "20",
|
|
55
|
-
});
|
|
56
|
-
const result = await apiClient.postProviderProxy("/api/webhook-site/proxy", {
|
|
57
|
-
method: "GET",
|
|
58
|
-
path: `/token/${token}/requests?${params.toString()}`,
|
|
59
|
-
});
|
|
60
|
-
const webhookResponse = result.data;
|
|
61
|
-
if (!webhookResponse ||
|
|
62
|
-
!webhookResponse.data ||
|
|
63
|
-
!Array.isArray(webhookResponse.data)) {
|
|
64
|
-
throw new Error("webhook.site proxy response missing 'data' array");
|
|
65
|
-
}
|
|
66
|
-
return webhookResponse.data;
|
|
67
|
-
}
|
|
68
|
-
async function webhookSiteQueryDirect(token, content) {
|
|
69
|
-
const apiKey = process.env.WEBHOOK_SITE_API_KEY;
|
|
70
|
-
if (!apiKey) {
|
|
71
|
-
throw new Error("Either EMPIRICALRUN_API_KEY or WEBHOOK_SITE_API_KEY must be set");
|
|
72
|
-
}
|
|
73
|
-
const params = new URLSearchParams({
|
|
74
|
-
query: buildContentQuery(content),
|
|
75
|
-
sorting: "newest",
|
|
76
|
-
per_page: "20",
|
|
77
|
-
});
|
|
78
|
-
const rawResponse = await fetch(`https://webhook.site/token/${token}/requests?${params.toString()}`, {
|
|
79
|
-
headers: {
|
|
80
|
-
"Api-Key": apiKey,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
if (!rawResponse.ok) {
|
|
84
|
-
const body = await rawResponse.text().catch(() => "");
|
|
85
|
-
throw new Error(`webhook.site error [${rawResponse.status} ${rawResponse.statusText}]: ${body}`);
|
|
86
|
-
}
|
|
87
|
-
const json = await rawResponse.json().catch((e) => {
|
|
88
|
-
throw new Error(`webhook.site returned invalid JSON: ${String(e)}`);
|
|
89
|
-
});
|
|
90
|
-
if (!json || !Array.isArray(json.data)) {
|
|
91
|
-
throw new Error("webhook.site response missing 'data' array");
|
|
92
|
-
}
|
|
93
|
-
return json.data;
|
|
94
|
-
}
|
|
95
|
-
async function webhookSiteQuery(token, content) {
|
|
96
|
-
if (process.env.EMPIRICALRUN_API_KEY) {
|
|
97
|
-
return webhookSiteQueryViaProxy(token, content);
|
|
98
|
-
}
|
|
99
|
-
return webhookSiteQueryDirect(token, content);
|
|
100
|
-
}
|
|
101
6
|
function captureToWebhookRequest(capture) {
|
|
102
7
|
const headers = Object.fromEntries(Object.entries(capture.headers).map(([key, value]) => [key, [value]]));
|
|
103
8
|
return {
|
|
@@ -118,18 +23,6 @@ function captureToWebhookRequest(capture) {
|
|
|
118
23
|
updated_at: capture.received_at,
|
|
119
24
|
};
|
|
120
25
|
}
|
|
121
|
-
async function inboxGetUrl() {
|
|
122
|
-
const { url } = await new api_worker_client_1.ApiWorkerClient().createWebhookCapture();
|
|
123
|
-
return url;
|
|
124
|
-
}
|
|
125
|
-
async function inboxQuery(token, content) {
|
|
126
|
-
const captures = await new api_worker_client_1.ApiWorkerClient().listWebhookCaptures(token, {
|
|
127
|
-
content: Array.isArray(content) ? content : [content],
|
|
128
|
-
order: "newest",
|
|
129
|
-
limit: 20,
|
|
130
|
-
});
|
|
131
|
-
return captures.map(captureToWebhookRequest);
|
|
132
|
-
}
|
|
133
26
|
function extractToken(webhookUrl) {
|
|
134
27
|
let url;
|
|
135
28
|
try {
|
|
@@ -138,6 +31,9 @@ function extractToken(webhookUrl) {
|
|
|
138
31
|
catch {
|
|
139
32
|
throw new Error(`Invalid webhook URL: ${webhookUrl}`);
|
|
140
33
|
}
|
|
34
|
+
if (url.hostname === "webhook.site") {
|
|
35
|
+
throw new Error(`webhook.site URLs are no longer supported: use getWebhookUrl() for an Empirical inbox URL (${webhookUrl})`);
|
|
36
|
+
}
|
|
141
37
|
const parts = url.pathname.split("/").filter(Boolean);
|
|
142
38
|
const token = parts[parts.length - 1];
|
|
143
39
|
if (!token) {
|
|
@@ -145,24 +41,16 @@ function extractToken(webhookUrl) {
|
|
|
145
41
|
}
|
|
146
42
|
return token;
|
|
147
43
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
return "inbox";
|
|
153
|
-
}
|
|
154
|
-
async function getWebhookUrl(options = {}) {
|
|
155
|
-
const provider = options.provider || "webhook-site";
|
|
156
|
-
if (provider === "webhook-site") {
|
|
157
|
-
return webhookSiteGetUrl(options);
|
|
158
|
-
}
|
|
159
|
-
return inboxGetUrl();
|
|
44
|
+
async function getWebhookUrl() {
|
|
45
|
+
const { url } = await new api_worker_client_1.ApiWorkerClient().createWebhookCapture();
|
|
46
|
+
return url;
|
|
160
47
|
}
|
|
161
48
|
async function queryWebhookRequests(webhookUrl, content) {
|
|
162
49
|
const token = extractToken(webhookUrl);
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
50
|
+
const captures = await new api_worker_client_1.ApiWorkerClient().listWebhookCaptures(token, {
|
|
51
|
+
content: Array.isArray(content) ? content : [content],
|
|
52
|
+
order: "newest",
|
|
53
|
+
limit: 20,
|
|
54
|
+
});
|
|
55
|
+
return captures.map(captureToWebhookRequest);
|
|
168
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"openapi-fetch": "0.14.1",
|
|
63
63
|
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
|
64
64
|
"ts-morph": "^28.0.0",
|
|
65
|
-
"@empiricalrun/cua": "^0.
|
|
66
|
-
"@empiricalrun/r2-uploader": "^0.
|
|
65
|
+
"@empiricalrun/cua": "^0.7.0",
|
|
66
|
+
"@empiricalrun/r2-uploader": "^0.12.0",
|
|
67
67
|
"@empiricalrun/reporter": "^0.30.6"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
package/playwright.config.ts
CHANGED