@empiricalrun/playwright-utils 0.20.2 → 0.20.3

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.20.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb0496f: fix: hover failure error stack should not contain patch method
8
+
3
9
  ## 0.20.2
4
10
 
5
11
  ### Patch Changes
@@ -64,3 +64,17 @@ test_1.test.beforeEach(async ({ page }) => {
64
64
  await (0, test_1.expect)(page.getByText("This is a toast message")).not.toBeVisible();
65
65
  await (0, test_1.expect)(page.getByRole("button", { name: "Close" })).toBeVisible();
66
66
  });
67
+ (0, test_1.test)("should not return patch method in error stack", async ({ page }) => {
68
+ await page.goto(`http://localhost:${PORT}/tos.html`);
69
+ let error;
70
+ try {
71
+ await page.locator("div.some-random-class-name").hover();
72
+ }
73
+ catch (e) {
74
+ error = e;
75
+ }
76
+ (0, test_1.expect)(error).toBeDefined();
77
+ (0, test_1.expect)(error.stack).toBeDefined();
78
+ (0, test_1.expect)(error.stack).not.toContain("hover.ts");
79
+ (0, test_1.expect)(error.stack).toContain("overlay-tests/click.spec.ts:83");
80
+ });
@@ -1,3 +1,4 @@
1
- import type { Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
2
- export declare function addAgentCapabilities(page: Page, testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>): void;
1
+ import type { Page } from "@playwright/test";
2
+ import { TestFn } from "./types";
3
+ export declare function addAgentCapabilities(page: Page, testFn: TestFn): void;
3
4
  //# sourceMappingURL=agent-capabilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-capabilities.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/agent-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAe1B,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,QAAQ,CACd,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,QAMF"}
1
+ {"version":3,"file":"agent-capabilities.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/agent-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAK9D"}
@@ -1,4 +1,5 @@
1
- import type { Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
1
+ import type { Page } from "@playwright/test";
2
2
  import { HighlighterOpts } from "../types";
3
- export declare function injectLocatorHighlightScripts(page: Page, testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts): void;
3
+ import { TestFn } from "./types";
4
+ export declare function injectLocatorHighlightScripts(page: Page, testFn: TestFn, options?: HighlighterOpts): void;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAa3C,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,QAAQ,CACd,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,EACD,OAAO,GAAE,eAAgC,QAsB1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAK3C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AASjC,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAgC,QAsB1C"}
@@ -22,7 +22,7 @@ function injectLocatorHighlightScripts(page, testFn, options = defaultOptions) {
22
22
  (0, mouse_pointer_1.addMousePointerHighlighter)(page);
23
23
  }
24
24
  if (opts.locatorHighlighter) {
25
- (0, locator_highlights_1.addLocatorHighlights)(page);
25
+ (0, locator_highlights_1.addLocatorHighlights)(page, testFn);
26
26
  }
27
27
  if (opts.visionMethods) {
28
28
  (0, locator_vision_1.addLocatorVisionMethods)(page);
@@ -1,3 +1,4 @@
1
1
  import type { Page } from "@playwright/test";
2
- export declare function addLocatorHighlights(page: Page): void;
2
+ import { TestFn } from "./types";
3
+ export declare function addLocatorHighlights(page: Page, testFn: TestFn): void;
3
4
  //# sourceMappingURL=locator-highlights.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locator-highlights.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/locator-highlights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAW7C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,QAK9C"}
1
+ {"version":3,"file":"locator-highlights.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/locator-highlights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAU7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAK9D"}
@@ -9,21 +9,21 @@ const is_checked_1 = require("./pw-locator-patch/highlight/is-checked");
9
9
  const is_disabled_1 = require("./pw-locator-patch/highlight/is-disabled");
10
10
  const is_editable_1 = require("./pw-locator-patch/highlight/is-editable");
11
11
  const text_content_1 = require("./pw-locator-patch/highlight/text-content");
12
- function addLocatorHighlights(page) {
13
- applyHighlights(page);
12
+ function addLocatorHighlights(page, testFn) {
13
+ applyHighlights(page, testFn);
14
14
  page.context().on("page", async (newPage) => {
15
- applyHighlights(newPage);
15
+ applyHighlights(newPage, testFn);
16
16
  });
17
17
  }
18
18
  exports.addLocatorHighlights = addLocatorHighlights;
19
- function applyHighlights(page) {
19
+ function applyHighlights(page, testFn) {
20
20
  const LocatorClass = page.locator("").constructor;
21
+ (0, hover_1.patchHover)(LocatorClass, testFn);
21
22
  (0, expect_1.patchExpect)(LocatorClass);
22
23
  (0, input_value_1.patchInputValue)(LocatorClass);
23
24
  (0, is_checked_1.patchIsChecked)(LocatorClass);
24
25
  (0, is_editable_1.patchIsEditable)(LocatorClass);
25
26
  (0, is_disabled_1.patchIsDisabled)(LocatorClass);
26
- (0, hover_1.patchHover)(LocatorClass);
27
27
  (0, inner_text_1.patchInnerText)(LocatorClass);
28
28
  (0, text_content_1.patchTextContent)(LocatorClass);
29
29
  }
@@ -1,5 +1,6 @@
1
1
  import type { Locator } from "@playwright/test";
2
+ import { TestFn } from "../../types";
2
3
  export declare function patchHover(LocatorClass: Function & {
3
4
  prototype: Locator;
4
- }): void;
5
+ }, testFn: TestFn): void;
5
6
  //# sourceMappingURL=hover.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,UAAU,CAAC,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAUzE"}
1
+ {"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKrC,wBAAgB,UAAU,CACxB,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,EAC/C,MAAM,EAAE,MAAM,QA2Bf"}
@@ -3,14 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchHover = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const isHoverPatched = new WeakMap();
6
- function patchHover(LocatorClass) {
6
+ function patchHover(LocatorClass, testFn) {
7
7
  if (isHoverPatched.get(LocatorClass)) {
8
8
  return;
9
9
  }
10
10
  const originalHover = LocatorClass.prototype.hover;
11
11
  LocatorClass.prototype.hover = async function (options) {
12
- await originalHover.apply(this, [options]);
13
- await (0, utils_1.highlight)(this);
12
+ let result;
13
+ const stepName = `locator.hover(${(0, utils_1.description)(this)})`;
14
+ await testFn.step(stepName, async () => {
15
+ try {
16
+ result = await originalHover.apply(this, [options]);
17
+ }
18
+ catch (error) {
19
+ if (error instanceof Error) {
20
+ Error.captureStackTrace(error, LocatorClass.prototype.hover);
21
+ }
22
+ throw error;
23
+ }
24
+ await (0, utils_1.highlight)(this);
25
+ }, { box: true });
26
+ return result;
14
27
  };
15
28
  isHoverPatched.set(LocatorClass, true);
16
29
  }
@@ -1,4 +1,5 @@
1
1
  import { Locator } from "playwright-core";
2
+ export declare function description(locator: Locator): string;
2
3
  export declare function scrollAndHighlight(locator: Locator): Promise<void>;
3
4
  export declare function highlight(locator: Locator): Promise<void>;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,iBAsBxD;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,iBAiB/C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,UA0B3C;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,iBAsBxD;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,iBAiB/C"}
@@ -1,8 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.highlight = exports.scrollAndHighlight = void 0;
3
+ exports.highlight = exports.scrollAndHighlight = exports.description = void 0;
4
4
  const logger_1 = require("../../../../logger");
5
5
  const constants_1 = require("../../../constants");
6
+ function description(locator) {
7
+ const fallbackDescription = locator.toString();
8
+ try {
9
+ let cleanedDescription = fallbackDescription;
10
+ if (fallbackDescription.startsWith("locator(") &&
11
+ fallbackDescription.endsWith(")")) {
12
+ cleanedDescription = fallbackDescription
13
+ .substring(8, fallbackDescription.length - 1)
14
+ .trim();
15
+ if ((cleanedDescription.startsWith("'") &&
16
+ cleanedDescription.endsWith("'")) ||
17
+ (cleanedDescription.startsWith('"') && cleanedDescription.endsWith('"'))) {
18
+ cleanedDescription = cleanedDescription.substring(1, cleanedDescription.length - 1);
19
+ }
20
+ }
21
+ return cleanedDescription;
22
+ }
23
+ catch (e) {
24
+ return fallbackDescription;
25
+ }
26
+ }
27
+ exports.description = description;
6
28
  async function scrollAndHighlight(locator) {
7
29
  try {
8
30
  await locator.evaluate((node) => {
@@ -0,0 +1,3 @@
1
+ import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
2
+ export type TestFn = TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,MAAM,GAAG,QAAQ,CAC3B,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.20.2",
3
+ "version": "0.20.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -43,8 +43,8 @@
43
43
  "puppeteer-extra-plugin-recaptcha": "^3.6.8",
44
44
  "rimraf": "^6.0.1",
45
45
  "@empiricalrun/llm": "^0.9.35",
46
- "@empiricalrun/test-gen": "^0.43.0",
47
- "@empiricalrun/r2-uploader": "^0.3.8"
46
+ "@empiricalrun/r2-uploader": "^0.3.8",
47
+ "@empiricalrun/test-gen": "^0.43.0"
48
48
  },
49
49
  "scripts": {
50
50
  "dev": "tsc --build --watch",