@empiricalrun/playwright-utils 0.5.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - de76cd6: fix: wrap mouse-pointer highlighter in try/catch
8
+
9
+ ## 0.6.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 59206d0: feat: add highlighter support for textContent
14
+
3
15
  ## 0.5.0
4
16
 
5
17
  ### Minor Changes
@@ -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;AAU7C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,QAS9C"}
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,QAU9C"}
@@ -8,6 +8,7 @@ const input_value_1 = require("./pw-locator-patch/input-value");
8
8
  const is_checked_1 = require("./pw-locator-patch/is-checked");
9
9
  const is_disabled_1 = require("./pw-locator-patch/is-disabled");
10
10
  const is_editable_1 = require("./pw-locator-patch/is-editable");
11
+ const text_content_1 = require("./pw-locator-patch/text-content");
11
12
  function addLocatorHighlights(page) {
12
13
  const LocatorClass = page.locator("").constructor;
13
14
  (0, expect_1.patchExpect)(LocatorClass);
@@ -17,5 +18,6 @@ function addLocatorHighlights(page) {
17
18
  (0, is_disabled_1.patchIsDisabled)(LocatorClass);
18
19
  (0, hover_1.patchHover)(LocatorClass);
19
20
  (0, inner_text_1.patchInnerText)(LocatorClass);
21
+ (0, text_content_1.patchTextContent)(LocatorClass);
20
22
  }
21
23
  exports.addLocatorHighlights = addLocatorHighlights;
@@ -1 +1 @@
1
- {"version":3,"file":"mouse-pointer.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/mouse-pointer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,QAgGpD"}
1
+ {"version":3,"file":"mouse-pointer.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/mouse-pointer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,QAoGpD"}
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addMousePointerHighlighter = void 0;
4
4
  function addMousePointerHighlighter(page) {
5
5
  page.on("load", async () => {
6
- await page?.evaluate(() => {
7
- const box = document.createElement("div");
8
- box.classList.add("empirical-mouse-pointer");
9
- const styleElement = document.createElement("style");
10
- styleElement.textContent = `
6
+ try {
7
+ await page?.evaluate(() => {
8
+ const box = document.createElement("div");
9
+ box.classList.add("empirical-mouse-pointer");
10
+ const styleElement = document.createElement("style");
11
+ styleElement.textContent = `
11
12
  .empirical-mouse-pointer {
12
13
  pointer-events: none;
13
14
  position: absolute;
@@ -53,28 +54,32 @@ function addMousePointerHighlighter(page) {
53
54
  outline: 2px dashed #FF000D !important;
54
55
  }
55
56
  `;
56
- document.head.appendChild(styleElement);
57
- document.body.appendChild(box);
58
- document.addEventListener("mousemove", (event) => {
59
- box.style.left = `${event.pageX}px`;
60
- box.style.top = `${event.pageY}px`;
61
- updateButtons(event.buttons);
62
- }, true);
63
- document.addEventListener("mousedown", (event) => {
64
- updateButtons(event.buttons);
65
- box.classList.add(`button-${event.button + 1}`);
66
- }, true);
67
- document.addEventListener("mouseup", (event) => {
68
- updateButtons(event.buttons);
69
- box.classList.remove(`button-${event.button + 1}`);
70
- }, true);
71
- // @ts-ignore
72
- function updateButtons(buttons) {
73
- for (let i = 0; i < 5; i++) {
74
- box.classList.toggle(`button-${i + 1}`, (buttons / Math.pow(2, i)) % 2 >= 1);
57
+ document.head.appendChild(styleElement);
58
+ document.body.appendChild(box);
59
+ document.addEventListener("mousemove", (event) => {
60
+ box.style.left = `${event.pageX}px`;
61
+ box.style.top = `${event.pageY}px`;
62
+ updateButtons(event.buttons);
63
+ }, true);
64
+ document.addEventListener("mousedown", (event) => {
65
+ updateButtons(event.buttons);
66
+ box.classList.add(`button-${event.button + 1}`);
67
+ }, true);
68
+ document.addEventListener("mouseup", (event) => {
69
+ updateButtons(event.buttons);
70
+ box.classList.remove(`button-${event.button + 1}`);
71
+ }, true);
72
+ // @ts-ignore
73
+ function updateButtons(buttons) {
74
+ for (let i = 0; i < 5; i++) {
75
+ box.classList.toggle(`button-${i + 1}`, (buttons / Math.pow(2, i)) % 2 >= 1);
76
+ }
75
77
  }
76
- }
77
- });
78
+ });
79
+ }
80
+ catch (e) {
81
+ console.log(`Error adding mouse pointer highlighter`, e);
82
+ }
78
83
  });
79
84
  }
80
85
  exports.addMousePointerHighlighter = addMousePointerHighlighter;
@@ -1 +1 @@
1
- {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,WAAW,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAyB/D"}
1
+ {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,WAAW,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QA2B/D"}
@@ -14,7 +14,9 @@ function patchExpect(LocatorClass) {
14
14
  await this.evaluate((node) => {
15
15
  node.classList.add("empirical-element-grab-highlight");
16
16
  setTimeout(() => {
17
- node.classList.remove("empirical-element-grab-highlight");
17
+ if (node.isConnected) {
18
+ node.classList.remove("empirical-element-grab-highlight");
19
+ }
18
20
  }, 2000);
19
21
  });
20
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,UAAU,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAiB9D"}
1
+ {"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,UAAU,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAmB9D"}
@@ -11,7 +11,9 @@ function patchHover(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inner-text.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/inner-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,cAAc,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAkBlE"}
1
+ {"version":3,"file":"inner-text.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/inner-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,cAAc,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBlE"}
@@ -11,7 +11,9 @@ function patchInnerText(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"input-value.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/input-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAkBnE"}
1
+ {"version":3,"file":"input-value.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/input-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBnE"}
@@ -11,7 +11,9 @@ function patchInputValue(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"is-checked.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-checked.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,cAAc,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAkBlE"}
1
+ {"version":3,"file":"is-checked.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-checked.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,cAAc,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBlE"}
@@ -11,7 +11,9 @@ function patchIsChecked(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"is-disabled.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAkBnE"}
1
+ {"version":3,"file":"is-disabled.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBnE"}
@@ -11,7 +11,9 @@ function patchIsDisabled(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"is-editable.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-editable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAkBnE"}
1
+ {"version":3,"file":"is-editable.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/is-editable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,eAAe,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBnE"}
@@ -11,7 +11,9 @@ function patchIsEditable(LocatorClass) {
11
11
  await this.evaluate((node) => {
12
12
  node.classList.add("empirical-element-grab-highlight");
13
13
  setTimeout(() => {
14
- node.classList.remove("empirical-element-grab-highlight");
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
15
17
  }, 2000);
16
18
  });
17
19
  }
@@ -0,0 +1,5 @@
1
+ import type { Locator } from "@playwright/test";
2
+ export declare function patchTextContent(LocatorClass: {
3
+ prototype: Locator;
4
+ }): void;
5
+ //# sourceMappingURL=text-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-content.d.ts","sourceRoot":"","sources":["../../../../src/test/scripts/pw-locator-patch/text-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,QAoBpE"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchTextContent = void 0;
4
+ function patchTextContent(LocatorClass) {
5
+ const originalTextContent = LocatorClass.prototype.textContent;
6
+ //ref: https://github.com/microsoft/playwright/blob/69287f26bc514b740eac40160503d6fac8185d37/packages/playwright-core/src/client/locator.ts#L318
7
+ LocatorClass.prototype.textContent = async function (options) {
8
+ const result = await originalTextContent.apply(this, [options]);
9
+ try {
10
+ await this.scrollIntoViewIfNeeded();
11
+ await this.evaluate((node) => {
12
+ node.classList.add("empirical-element-grab-highlight");
13
+ setTimeout(() => {
14
+ if (node.isConnected) {
15
+ node.classList.remove("empirical-element-grab-highlight");
16
+ }
17
+ }, 2000);
18
+ });
19
+ }
20
+ catch (e) {
21
+ console.log("Failed to add highlight for locator method: textContent", e);
22
+ }
23
+ return result;
24
+ };
25
+ }
26
+ exports.patchTextContent = patchTextContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"