@empiricalrun/playwright-utils 0.70.3 → 0.71.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/api-worker-client.d.ts +5 -1
  3. package/dist/api-worker-client.d.ts.map +1 -1
  4. package/dist/api-worker-client.js +15 -0
  5. package/dist/generated/api-worker-openapi.d.ts +609 -383
  6. package/dist/generated/api-worker-openapi.d.ts.map +1 -1
  7. package/dist/overlay-test-expectations.d.ts +10 -0
  8. package/dist/overlay-test-expectations.d.ts.map +1 -0
  9. package/dist/overlay-test-expectations.js +51 -0
  10. package/dist/overlay-tests/click.spec.js +26 -94
  11. package/dist/overlay-tests/dropdown.spec.js +10 -9
  12. package/dist/overlay-tests/fixtures.d.ts +1 -0
  13. package/dist/overlay-tests/fixtures.d.ts.map +1 -1
  14. package/dist/overlay-tests/fixtures.js +24 -0
  15. package/dist/overlay-tests/visual.spec.js +1 -11
  16. package/dist/test/cross-shard-locks.d.ts +1 -1
  17. package/dist/test/cross-shard-locks.d.ts.map +1 -1
  18. package/dist/test/cross-shard-locks.js +71 -25
  19. package/dist/test/index.d.ts +1 -0
  20. package/dist/test/index.d.ts.map +1 -1
  21. package/dist/test/index.js +10 -0
  22. package/dist/test/locator-handler-log.spec.d.ts +2 -0
  23. package/dist/test/locator-handler-log.spec.d.ts.map +1 -0
  24. package/dist/test/locator-handler-log.spec.js +44 -0
  25. package/dist/test/scripts/locator-handler-log.d.ts +23 -0
  26. package/dist/test/scripts/locator-handler-log.d.ts.map +1 -0
  27. package/dist/test/scripts/locator-handler-log.js +105 -0
  28. package/dist/test/scripts/pw-locator-patch/actions/click.d.ts.map +1 -1
  29. package/dist/test/scripts/pw-locator-patch/actions/click.js +17 -34
  30. package/dist/test/scripts/pw-locator-patch/actions/hover.d.ts.map +1 -1
  31. package/dist/test/scripts/pw-locator-patch/actions/hover.js +11 -25
  32. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts +21 -4
  33. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts.map +1 -1
  34. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.js +113 -18
  35. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts +2 -3
  36. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts.map +1 -1
  37. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.js +6 -52
  38. package/dist/webhook.d.ts +1 -6
  39. package/dist/webhook.d.ts.map +1 -1
  40. package/dist/webhook.js +12 -124
  41. package/package.json +3 -3
  42. package/playwright.config.ts +1 -1
  43. package/tsconfig.tsbuildinfo +1 -1
  44. package/dist/overlay-tests/typesafe-hit-check.spec.d.ts +0 -2
  45. package/dist/overlay-tests/typesafe-hit-check.spec.d.ts.map +0 -1
  46. package/dist/overlay-tests/typesafe-hit-check.spec.js +0 -57
  47. package/dist/overlay-tests/typesafe.spec.d.ts +0 -2
  48. package/dist/overlay-tests/typesafe.spec.d.ts.map +0 -1
  49. package/dist/overlay-tests/typesafe.spec.js +0 -88
  50. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts +0 -38
  51. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts.map +0 -1
  52. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.js +0 -159
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOCATOR_HANDLER_ATTACHMENT = exports.LOCATOR_HANDLER_ANNOTATION = void 0;
4
+ exports.patchLocatorHandlers = patchLocatorHandlers;
5
+ exports.locatorHandlerRecords = locatorHandlerRecords;
6
+ exports.summarizeLocatorHandler = summarizeLocatorHandler;
7
+ exports.attachLocatorHandlerLog = attachLocatorHandlerLog;
8
+ const utils_1 = require("./pw-locator-patch/utils");
9
+ exports.LOCATOR_HANDLER_ANNOTATION = "locator-handler";
10
+ exports.LOCATOR_HANDLER_ATTACHMENT = "locator-handlers";
11
+ const recordsByTest = new WeakMap();
12
+ const patchedPageClasses = new WeakSet();
13
+ function currentTestInfo(testFn) {
14
+ try {
15
+ return testFn.info();
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ }
21
+ function startRecord(testInfo, record) {
22
+ const records = recordsByTest.get(testInfo) ?? [];
23
+ records.push(record);
24
+ recordsByTest.set(testInfo, records);
25
+ }
26
+ function withRunLog(record, handler) {
27
+ return async (locator) => {
28
+ const startedAt = new Date();
29
+ const start = performance.now();
30
+ const finish = (error) => {
31
+ const run = {
32
+ startedAt: startedAt.toISOString(),
33
+ durationMs: Math.round(performance.now() - start),
34
+ };
35
+ if (error !== undefined) {
36
+ run.error = error instanceof Error ? error.message : String(error);
37
+ }
38
+ record.runs.push(run);
39
+ console.log(`[Locator handler]: ${record.locator} ran in ${run.durationMs}ms${run.error ? ` and failed: ${run.error}` : ""}`);
40
+ };
41
+ try {
42
+ const result = await handler(locator);
43
+ finish();
44
+ return result;
45
+ }
46
+ catch (error) {
47
+ finish(error);
48
+ throw error;
49
+ }
50
+ };
51
+ }
52
+ function patchLocatorHandlers(page, testFn) {
53
+ const PageClass = page.constructor;
54
+ if (patchedPageClasses.has(PageClass)) {
55
+ return;
56
+ }
57
+ patchedPageClasses.add(PageClass);
58
+ const originalAddLocatorHandler = PageClass.prototype.addLocatorHandler;
59
+ PageClass.prototype.addLocatorHandler = async function (locator, handler, options) {
60
+ const testInfo = currentTestInfo(testFn);
61
+ if (!testInfo) {
62
+ return await originalAddLocatorHandler.call(this, locator, handler, options);
63
+ }
64
+ const record = {
65
+ locator: (0, utils_1.description)(locator),
66
+ registeredAt: new Date().toISOString(),
67
+ runs: [],
68
+ ...(options && { options }),
69
+ };
70
+ startRecord(testInfo, record);
71
+ return await originalAddLocatorHandler.call(this, locator, withRunLog(record, handler), options);
72
+ };
73
+ }
74
+ function locatorHandlerRecords(testInfo) {
75
+ return recordsByTest.get(testInfo) ?? [];
76
+ }
77
+ function formatSeconds(ms) {
78
+ return `${(ms / 1000).toFixed(2)}s`;
79
+ }
80
+ function summarizeLocatorHandler(record) {
81
+ if (record.runs.length === 0) {
82
+ return `${record.locator}: registered, never ran`;
83
+ }
84
+ const totalMs = record.runs.reduce((sum, run) => sum + run.durationMs, 0);
85
+ const failed = record.runs.filter((run) => run.error !== undefined).length;
86
+ const times = record.runs.length === 1 ? "1 time" : `${record.runs.length} times`;
87
+ return `${record.locator}: ran ${times}, ${formatSeconds(totalMs)} total${failed ? `, ${failed} failed` : ""}`;
88
+ }
89
+ async function attachLocatorHandlerLog(testInfo) {
90
+ const records = locatorHandlerRecords(testInfo);
91
+ if (records.length === 0) {
92
+ return;
93
+ }
94
+ for (const record of records) {
95
+ testInfo.annotations.push({
96
+ type: exports.LOCATOR_HANDLER_ANNOTATION,
97
+ description: summarizeLocatorHandler(record),
98
+ });
99
+ }
100
+ await testInfo.attach(exports.LOCATOR_HANDLER_ATTACHMENT, {
101
+ body: JSON.stringify(records, null, 2),
102
+ contentType: "application/json",
103
+ });
104
+ recordsByTest.delete(testInfo);
105
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/actions/click.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC,wBAAgB,UAAU,CACxB,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,EAC/C,MAAM,EAAE,MAAM,QA+Df"}
1
+ {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/actions/click.ts"],"names":[],"mappings":"AACA,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,QA2Cf"}
@@ -16,42 +16,25 @@ function patchClick(LocatorClass, testFn) {
16
16
  LocatorClass.prototype.click = async function (options) {
17
17
  const stepName = `locator.click(${(0, utils_2.description)(this)})`;
18
18
  return await testFn.step(stepName, async () => {
19
- if (options?.isExecutingForOverlayDismiss &&
20
- (0, dismiss_overlays_1.overlayClickMode)() === "dispatch" &&
21
- !(await this.evaluate(cua_1.needsFocus, undefined, {
22
- timeout: options.timeout,
23
- }))) {
24
- return await this.dispatchEvent("click");
25
- }
26
- let overlayAttemptsRemaining = 2;
27
- let originalError;
28
- const overlayDismiss = new dismiss_overlays_1.OverlayDismissAgent(this._frame._page);
29
- while (overlayAttemptsRemaining >= 0) {
30
- overlayAttemptsRemaining--;
31
- try {
32
- let result = await originalClick.apply(this, [options]);
33
- await overlayDismiss.saveToCache();
34
- return result;
35
- }
36
- catch (error) {
37
- originalError = error;
38
- if (originalError instanceof Error) {
39
- Error.captureStackTrace(originalError, LocatorClass.prototype.click);
40
- }
41
- if (options?.isExecutingForOverlayDismiss) {
42
- throw originalError;
43
- }
44
- if (!(0, dismiss_overlays_1.isErrorSupported)(originalError.message)) {
45
- // TODO: Playwright actionability checks have precedence: if an overlay blocks a
46
- // disabled button, the error will not show interception -- it will focus on "not enabled".
47
- // This will cause our overlay dismissal to not run.
48
- throw originalError;
49
- }
50
- await overlayDismiss.run(originalError, reporter, testFn);
51
- reporter(`Overlay dismissal attempted, retrying original action.`);
19
+ if (options?.isExecutingForOverlayDismiss) {
20
+ if (!options.trial &&
21
+ (0, dismiss_overlays_1.overlayClickMode)() === "dispatch" &&
22
+ !(await this.evaluate(cua_1.needsFocus, undefined, {
23
+ timeout: options.timeout,
24
+ }))) {
25
+ return await this.dispatchEvent("click");
52
26
  }
27
+ return await originalClick.apply(this, [options]);
53
28
  }
54
- throw originalError;
29
+ return await (0, dismiss_overlays_1.withOverlayDismissal)({
30
+ page: this._frame._page,
31
+ action: "click",
32
+ target: this,
33
+ act: (extra) => originalClick.apply(this, [{ ...options, ...extra }]),
34
+ reporter,
35
+ testFn,
36
+ stackFrom: LocatorClass.prototype.click,
37
+ });
55
38
  }, { box: true });
56
39
  };
57
40
  isClickPatched.set(LocatorClass, true);
@@ -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,QAgDf"}
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
- let overlayAttemptsRemaining = 2;
18
- let originalError;
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
- throw originalError;
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
- constructor(page: Page);
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<void>;
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,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAIxC,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,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,qBAAa,mBAAmB;IAOlB,OAAO,CAAC,QAAQ,CAAC,IAAI;IANjC,OAAO,CAAC,iBAAiB,CAIhB;IAET,YAA6B,IAAI,EAAE,IAAI,EAAI;IAErC,WAAW,kBAIhB;IAEK,GAAG,CACP,aAAa,EAAE,GAAG,EAClB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAUf;YAEa,OAAO;YAwDP,QAAQ;CAgCvB;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GACnB,cAAc,G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AQ,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
- constructor(page) {
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
- const { success } = await (0, cache_1.executeFromCache)({
58
- page: this.page,
59
- dom: element?.interceptor,
60
- text,
61
- });
62
- if (success) {
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
- return;
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 usage = await this.runAgent(element, text, testFn);
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 = await (0, prompt_1.getTask)(this.page, element, text);
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
- openAIClientConfig: (0, api_worker_client_1.llmProxyOpenAIConfig)(),
199
+ model,
200
+ ...llmClientConfig(model),
106
201
  clickMode: overlayClickMode(),
107
202
  }));
108
203
  this.cachingCandidates.push({
@@ -1,4 +1,3 @@
1
- import type { Page } from "playwright-core";
2
- import { OverlayElement } from "./types";
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":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,wBAAsB,OAAO,CAC3B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,IAAI,EAAE,MAAM,GAAG,SAAS,mBAqCzB"}
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
- async function getTask(page, element, text) {
6
- let promptAddition = text
7
- ? `
8
- In this case, the popup can be identified with its text content:
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
- type WebhookProvider = "inbox" | "webhook-site";
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
@@ -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,M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