@empiricalrun/playwright-utils 0.20.1 → 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.
Files changed (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/overlay-tests/click.spec.js +14 -0
  3. package/dist/test/scripts/agent-capabilities.d.ts +3 -2
  4. package/dist/test/scripts/agent-capabilities.d.ts.map +1 -1
  5. package/dist/test/scripts/index.d.ts +3 -2
  6. package/dist/test/scripts/index.d.ts.map +1 -1
  7. package/dist/test/scripts/index.js +1 -1
  8. package/dist/test/scripts/locator-highlights.d.ts +2 -1
  9. package/dist/test/scripts/locator-highlights.d.ts.map +1 -1
  10. package/dist/test/scripts/locator-highlights.js +5 -5
  11. package/dist/test/scripts/pw-locator-patch/highlight/expect.d.ts.map +1 -1
  12. package/dist/test/scripts/pw-locator-patch/highlight/expect.js +2 -21
  13. package/dist/test/scripts/pw-locator-patch/highlight/hover.d.ts +2 -1
  14. package/dist/test/scripts/pw-locator-patch/highlight/hover.d.ts.map +1 -1
  15. package/dist/test/scripts/pw-locator-patch/highlight/hover.js +17 -17
  16. package/dist/test/scripts/pw-locator-patch/highlight/inner-text.d.ts.map +1 -1
  17. package/dist/test/scripts/pw-locator-patch/highlight/inner-text.js +2 -21
  18. package/dist/test/scripts/pw-locator-patch/highlight/input-value.d.ts.map +1 -1
  19. package/dist/test/scripts/pw-locator-patch/highlight/input-value.js +2 -21
  20. package/dist/test/scripts/pw-locator-patch/highlight/is-checked.d.ts.map +1 -1
  21. package/dist/test/scripts/pw-locator-patch/highlight/is-checked.js +2 -21
  22. package/dist/test/scripts/pw-locator-patch/highlight/is-disabled.d.ts.map +1 -1
  23. package/dist/test/scripts/pw-locator-patch/highlight/is-disabled.js +2 -21
  24. package/dist/test/scripts/pw-locator-patch/highlight/is-editable.d.ts.map +1 -1
  25. package/dist/test/scripts/pw-locator-patch/highlight/is-editable.js +2 -21
  26. package/dist/test/scripts/pw-locator-patch/highlight/text-content.d.ts.map +1 -1
  27. package/dist/test/scripts/pw-locator-patch/highlight/text-content.js +3 -22
  28. package/dist/test/scripts/pw-locator-patch/utils/index.d.ts +5 -0
  29. package/dist/test/scripts/pw-locator-patch/utils/index.d.ts.map +1 -0
  30. package/dist/test/scripts/pw-locator-patch/utils/index.js +65 -0
  31. package/dist/test/scripts/types.d.ts +3 -0
  32. package/dist/test/scripts/types.d.ts.map +1 -0
  33. package/dist/test/scripts/types.js +2 -0
  34. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
9
+ ## 0.20.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 1e3466d: fix: shared highlight method for all patch methods
14
+
3
15
  ## 0.20.1
4
16
 
5
17
  ### 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 +1 @@
1
- {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,WAAW,CAAC,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAuC1E"}
1
+ {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,WAAW,CAAC,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAmB1E"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchExpect = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isExpectPatched = new WeakMap();
7
6
  function patchExpect(LocatorClass) {
8
7
  if (isExpectPatched.get(LocatorClass)) {
@@ -15,25 +14,7 @@ function patchExpect(LocatorClass) {
15
14
  LocatorClass.prototype._expect = async function (expression, options) {
16
15
  const result = await originalExpect.apply(this, [expression, options]);
17
16
  if (result.matches) {
18
- try {
19
- await this.evaluate((node) => {
20
- if (node.scrollIntoViewIfNeeded) {
21
- node.scrollIntoViewIfNeeded();
22
- }
23
- else {
24
- node.scrollIntoView();
25
- }
26
- node.classList.add("empirical-element-grab-highlight");
27
- setTimeout(() => {
28
- if (node && node.isConnected && node.classList) {
29
- node.classList.remove("empirical-element-grab-highlight");
30
- }
31
- }, 2000);
32
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
33
- }
34
- catch (e) {
35
- logger_1.logger.debug("Failed to add highlight for locator method: _expect");
36
- }
17
+ await (0, utils_1.scrollAndHighlight)(this);
37
18
  }
38
19
  return result;
39
20
  };
@@ -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;AAOhD,wBAAgB,UAAU,CAAC,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAyBzE"}
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"}
@@ -1,29 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchHover = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isHoverPatched = new WeakMap();
7
- function patchHover(LocatorClass) {
6
+ function patchHover(LocatorClass, testFn) {
8
7
  if (isHoverPatched.get(LocatorClass)) {
9
8
  return;
10
9
  }
11
10
  const originalHover = LocatorClass.prototype.hover;
12
11
  LocatorClass.prototype.hover = async function (options) {
13
- await originalHover.apply(this, [options]);
14
- try {
15
- await this.evaluate((node) => {
16
- node.classList.add("empirical-element-grab-highlight");
17
- setTimeout(() => {
18
- if (node && node.isConnected && node.classList) {
19
- node.classList.remove("empirical-element-grab-highlight");
20
- }
21
- }, 2000);
22
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
23
- }
24
- catch (e) {
25
- logger_1.logger.debug("Failed to add highlight for locator method: hover");
26
- }
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;
27
27
  };
28
28
  isHoverPatched.set(LocatorClass, true);
29
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inner-text.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/inner-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,cAAc,CAC5B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiChD"}
1
+ {"version":3,"file":"inner-text.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/inner-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,cAAc,CAC5B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAahD"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchInnerText = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isInnerTextPatched = new WeakMap();
7
6
  function patchInnerText(LocatorClass) {
8
7
  if (isInnerTextPatched.get(LocatorClass)) {
@@ -12,25 +11,7 @@ function patchInnerText(LocatorClass) {
12
11
  //ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L251
13
12
  LocatorClass.prototype.innerText = async function (options) {
14
13
  const result = await originalInnerText.apply(this, [options]);
15
- try {
16
- await this.evaluate((node) => {
17
- if (node.scrollIntoViewIfNeeded) {
18
- node.scrollIntoViewIfNeeded();
19
- }
20
- else {
21
- node.scrollIntoView();
22
- }
23
- node.classList.add("empirical-element-grab-highlight");
24
- setTimeout(() => {
25
- if (node && node.isConnected && node.classList) {
26
- node.classList.remove("empirical-element-grab-highlight");
27
- }
28
- }, 2000);
29
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
30
- }
31
- catch (e) {
32
- logger_1.logger.debug("Failed to add highlight for locator method: innerText");
33
- }
14
+ await (0, utils_1.scrollAndHighlight)(this);
34
15
  return result;
35
16
  };
36
17
  isInnerTextPatched.set(LocatorClass, true);
@@ -1 +1 @@
1
- {"version":3,"file":"input-value.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/input-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiChD"}
1
+ {"version":3,"file":"input-value.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/input-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAahD"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchInputValue = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isInputValuePatched = new WeakMap();
7
6
  function patchInputValue(LocatorClass) {
8
7
  if (isInputValuePatched.get(LocatorClass)) {
@@ -12,25 +11,7 @@ function patchInputValue(LocatorClass) {
12
11
  //ref: github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L255
13
12
  LocatorClass.prototype.inputValue = async function (options) {
14
13
  const result = await originalInputValue.apply(this, [options]);
15
- try {
16
- await this.evaluate((node) => {
17
- if (node.scrollIntoViewIfNeeded) {
18
- node.scrollIntoViewIfNeeded();
19
- }
20
- else {
21
- node.scrollIntoView();
22
- }
23
- node.classList.add("empirical-element-grab-highlight");
24
- setTimeout(() => {
25
- if (node && node.isConnected && node.classList) {
26
- node.classList.remove("empirical-element-grab-highlight");
27
- }
28
- }, 2000);
29
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
30
- }
31
- catch (e) {
32
- logger_1.logger.debug("Failed to add highlight for locator method: inputValue");
33
- }
14
+ await (0, utils_1.scrollAndHighlight)(this);
34
15
  return result;
35
16
  };
36
17
  isInputValuePatched.set(LocatorClass, true);
@@ -1 +1 @@
1
- {"version":3,"file":"is-checked.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-checked.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,cAAc,CAC5B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiChD"}
1
+ {"version":3,"file":"is-checked.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-checked.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,cAAc,CAC5B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAahD"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchIsChecked = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isIsCheckedPatched = new WeakMap();
7
6
  function patchIsChecked(LocatorClass) {
8
7
  if (isIsCheckedPatched.get(LocatorClass)) {
@@ -12,25 +11,7 @@ function patchIsChecked(LocatorClass) {
12
11
  LocatorClass.prototype.isChecked = async function (options) {
13
12
  // ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L259
14
13
  const result = await originalIsChecked.apply(this, [options]);
15
- try {
16
- await this.evaluate((node) => {
17
- if (node.scrollIntoViewIfNeeded) {
18
- node.scrollIntoViewIfNeeded();
19
- }
20
- else {
21
- node.scrollIntoView();
22
- }
23
- node.classList.add("empirical-element-grab-highlight");
24
- setTimeout(() => {
25
- if (node && node.isConnected && node.classList) {
26
- node.classList.remove("empirical-element-grab-highlight");
27
- }
28
- }, 2000);
29
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
30
- }
31
- catch (e) {
32
- logger_1.logger.debug("Failed to add highlight for locator method: isChecked");
33
- }
14
+ await (0, utils_1.scrollAndHighlight)(this);
34
15
  return result;
35
16
  };
36
17
  isIsCheckedPatched.set(LocatorClass, true);
@@ -1 +1 @@
1
- {"version":3,"file":"is-disabled.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiChD"}
1
+ {"version":3,"file":"is-disabled.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAahD"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchIsDisabled = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isIsDisabledPatched = new WeakMap();
7
6
  function patchIsDisabled(LocatorClass) {
8
7
  if (isIsDisabledPatched.get(LocatorClass)) {
@@ -12,25 +11,7 @@ function patchIsDisabled(LocatorClass) {
12
11
  LocatorClass.prototype.isDisabled = async function (options) {
13
12
  // ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L263
14
13
  const result = await originalIsDisabled.apply(this, [options]);
15
- try {
16
- await this.evaluate((node) => {
17
- if (node.scrollIntoViewIfNeeded) {
18
- node.scrollIntoViewIfNeeded();
19
- }
20
- else {
21
- node.scrollIntoView();
22
- }
23
- node.classList.add("empirical-element-grab-highlight");
24
- setTimeout(() => {
25
- if (node && node.isConnected && node.classList) {
26
- node.classList.remove("empirical-element-grab-highlight");
27
- }
28
- }, 2000);
29
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
30
- }
31
- catch (e) {
32
- logger_1.logger.debug("Failed to add highlight for locator method: isDisabled");
33
- }
14
+ await (0, utils_1.scrollAndHighlight)(this);
34
15
  return result;
35
16
  };
36
17
  isIsDisabledPatched.set(LocatorClass, true);
@@ -1 +1 @@
1
- {"version":3,"file":"is-editable.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-editable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAgChD"}
1
+ {"version":3,"file":"is-editable.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/is-editable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAYhD"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchIsEditable = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isIsEditablePatched = new WeakMap();
7
6
  function patchIsEditable(LocatorClass) {
8
7
  if (isIsEditablePatched.get(LocatorClass)) {
@@ -11,25 +10,7 @@ function patchIsEditable(LocatorClass) {
11
10
  const originalIsEditable = LocatorClass.prototype.isEditable;
12
11
  LocatorClass.prototype.isEditable = async function (options) {
13
12
  const result = await originalIsEditable.apply(this, [options]);
14
- try {
15
- await this.evaluate((node) => {
16
- if (node.scrollIntoViewIfNeeded) {
17
- node.scrollIntoViewIfNeeded();
18
- }
19
- else {
20
- node.scrollIntoView();
21
- }
22
- node.classList.add("empirical-element-grab-highlight");
23
- setTimeout(() => {
24
- if (node && node.isConnected && node.classList) {
25
- node.classList.remove("empirical-element-grab-highlight");
26
- }
27
- }, 2000);
28
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
29
- }
30
- catch (e) {
31
- logger_1.logger.debug("Failed to add highlight for locator method: isEditable");
32
- }
13
+ await (0, utils_1.scrollAndHighlight)(this);
33
14
  return result;
34
15
  };
35
16
  isIsEditablePatched.set(LocatorClass, true);
@@ -1 +1 @@
1
- {"version":3,"file":"text-content.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/text-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiChD"}
1
+ {"version":3,"file":"text-content.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/highlight/text-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAahD"}
@@ -1,36 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.patchTextContent = void 0;
4
- const logger_1 = require("../../../../logger");
5
- const constants_1 = require("../../../constants");
4
+ const utils_1 = require("../utils");
6
5
  const isTextContentPatched = new WeakMap();
7
6
  function patchTextContent(LocatorClass) {
8
7
  if (isTextContentPatched.get(LocatorClass)) {
9
8
  return;
10
9
  }
11
10
  const originalTextContent = LocatorClass.prototype.textContent;
12
- //ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L318
11
+ // ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L318
13
12
  LocatorClass.prototype.textContent = async function (options) {
14
13
  const result = await originalTextContent.apply(this, [options]);
15
- try {
16
- await this.evaluate((node) => {
17
- if (node.scrollIntoViewIfNeeded) {
18
- node.scrollIntoViewIfNeeded();
19
- }
20
- else {
21
- node.scrollIntoView();
22
- }
23
- node.classList.add("empirical-element-grab-highlight");
24
- setTimeout(() => {
25
- if (node && node.isConnected && node.classList) {
26
- node.classList.remove("empirical-element-grab-highlight");
27
- }
28
- }, 2000);
29
- }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
30
- }
31
- catch (e) {
32
- logger_1.logger.debug("Failed to add highlight for locator method: textContent");
33
- }
14
+ await (0, utils_1.scrollAndHighlight)(this);
34
15
  return result;
35
16
  };
36
17
  isTextContentPatched.set(LocatorClass, true);
@@ -0,0 +1,5 @@
1
+ import { Locator } from "playwright-core";
2
+ export declare function description(locator: Locator): string;
3
+ export declare function scrollAndHighlight(locator: Locator): Promise<void>;
4
+ export declare function highlight(locator: Locator): Promise<void>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,UA0B3C;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,iBAsBxD;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,iBAiB/C"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.highlight = exports.scrollAndHighlight = exports.description = void 0;
4
+ const logger_1 = require("../../../../logger");
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;
28
+ async function scrollAndHighlight(locator) {
29
+ try {
30
+ await locator.evaluate((node) => {
31
+ if (node.scrollIntoViewIfNeeded) {
32
+ node.scrollIntoViewIfNeeded();
33
+ }
34
+ else {
35
+ node.scrollIntoView();
36
+ }
37
+ node.classList.add("empirical-element-grab-highlight");
38
+ setTimeout(() => {
39
+ if (node && node.isConnected && node.classList) {
40
+ node.classList.remove("empirical-element-grab-highlight");
41
+ }
42
+ }, 2000);
43
+ }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
44
+ }
45
+ catch (e) {
46
+ logger_1.logger.debug("Failed to scroll and highlight for locator method");
47
+ }
48
+ }
49
+ exports.scrollAndHighlight = scrollAndHighlight;
50
+ async function highlight(locator) {
51
+ try {
52
+ await locator.evaluate((node) => {
53
+ node.classList.add("empirical-element-grab-highlight");
54
+ setTimeout(() => {
55
+ if (node && node.isConnected && node.classList) {
56
+ node.classList.remove("empirical-element-grab-highlight");
57
+ }
58
+ }, 2000);
59
+ }, undefined, { timeout: constants_1.DEFAULT_SCRIPT_EXECUTION_TIMEOUT });
60
+ }
61
+ catch (e) {
62
+ logger_1.logger.debug("Failed to add highlight for locator method");
63
+ }
64
+ }
65
+ exports.highlight = highlight;
@@ -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.1",
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",