@empiricalrun/playwright-utils 0.15.3 → 0.15.5

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.15.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 5715b75: fix: type errors in playwright utils
8
+
9
+ ## 0.15.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 6865143: fix: all the pages should be highlighted automatically
14
+
3
15
  ## 0.15.3
4
16
 
5
17
  ### Patch Changes
@@ -5,4 +5,8 @@ declare module "playwright-core" {
5
5
  interface Locator extends EnhancedLocator {
6
6
  }
7
7
  }
8
+ declare module "@playwright/test" {
9
+ interface Locator extends EnhancedLocator {
10
+ }
11
+ }
8
12
  //# sourceMappingURL=playwright-extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"playwright-extensions.d.ts","sourceRoot":"","sources":["../src/playwright-extensions.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,OAAQ,SAAQ,eAAe;KAAG;CAC7C"}
1
+ {"version":3,"file":"playwright-extensions.d.ts","sourceRoot":"","sources":["../src/playwright-extensions.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,OAAQ,SAAQ,eAAe;KAAG;CAC7C;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC,UAAU,OAAQ,SAAQ,eAAe;KAAG;CAC7C"}
@@ -1,7 +1,7 @@
1
- import type { PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
1
+ import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
2
2
  import { injectLocatorHighlightScripts } from "./scripts";
3
- import { EnhancedPlaywrightTestArgs, HighlighterOpts } from "./types";
4
- export declare const baseTestFixture: (testFn: TestType<EnhancedPlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts) => TestType<EnhancedPlaywrightTestArgs & PlaywrightTestOptions & {
3
+ import { HighlighterOpts } from "./types";
4
+ export declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & {
5
5
  [key: string]: any;
6
6
  }, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
7
7
  export { injectLocatorHighlightScripts };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEtE,eAAO,MAAM,eAAe,WAClB,SACN,0BAA0B,GAAG,qBAAqB,EAClD,oBAAoB,GAAG,uBAAuB,CAC/C,YACQ,eAAe;;kDAYzB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,eAAe,WAClB,SACN,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,YACQ,eAAe;;kDAYzB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
@@ -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,QAU9C"}
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"}
@@ -10,6 +10,13 @@ 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
12
  function addLocatorHighlights(page) {
13
+ applyHighlights(page);
14
+ page.context().on("page", async (newPage) => {
15
+ applyHighlights(newPage);
16
+ });
17
+ }
18
+ exports.addLocatorHighlights = addLocatorHighlights;
19
+ function applyHighlights(page) {
13
20
  const LocatorClass = page.locator("").constructor;
14
21
  (0, expect_1.patchExpect)(LocatorClass);
15
22
  (0, input_value_1.patchInputValue)(LocatorClass);
@@ -20,4 +27,3 @@ function addLocatorHighlights(page) {
20
27
  (0, inner_text_1.patchInnerText)(LocatorClass);
21
28
  (0, text_content_1.patchTextContent)(LocatorClass);
22
29
  }
23
- exports.addLocatorHighlights = addLocatorHighlights;
@@ -1 +1 @@
1
- {"version":3,"file":"locator-vision.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/locator-vision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAI7C,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,QAGjD"}
1
+ {"version":3,"file":"locator-vision.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/locator-vision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAI7C,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,QAQjD"}
@@ -5,5 +5,9 @@ const query_1 = require("./pw-locator-patch/vision/query");
5
5
  function addLocatorVisionMethods(page) {
6
6
  const LocatorClass = page.locator("").constructor;
7
7
  (0, query_1.patchQuery)(LocatorClass);
8
+ page.context().on("page", async (newPage) => {
9
+ const NewPageLocatorClass = newPage.locator("").constructor;
10
+ (0, query_1.patchQuery)(NewPageLocatorClass);
11
+ });
8
12
  }
9
13
  exports.addLocatorVisionMethods = addLocatorVisionMethods;
@@ -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;AAI7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,QAoGpD"}
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;AAI7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,QA0MpD"}
@@ -82,5 +82,86 @@ function addMousePointerHighlighter(page) {
82
82
  logger_1.logger.debug(`Error adding mouse pointer highlighter`, e);
83
83
  }
84
84
  });
85
+ page.context().on("page", async (newPage) => {
86
+ newPage?.on("load", async () => {
87
+ try {
88
+ await newPage?.evaluate(() => {
89
+ const box = document.createElement("div");
90
+ box.classList.add("empirical-mouse-pointer");
91
+ const styleElement = document.createElement("style");
92
+ styleElement.textContent = `
93
+ .empirical-mouse-pointer {
94
+ pointer-events: none;
95
+ position: absolute;
96
+ top: 0;
97
+ z-index: 10000;
98
+ left: 0;
99
+ width: 20px;
100
+ height: 20px;
101
+ background: rgba(0,0,0,.4);
102
+ border: 1px dashed #FF000D;
103
+ border-radius: 10px;
104
+ margin: -10px 0 0 -10px;
105
+ padding: 0;
106
+ transition: background .2s, border-radius .2s, border-color .2s;
107
+ }
108
+ .empirical-mouse-pointer.button-1 {
109
+ transition: none;
110
+ background: rgba(0,0,0,0.9);
111
+ }
112
+ .empirical-mouse-pointer.button-2 {
113
+ transition: none;
114
+ border-color: rgba(0,0,255,0.9);
115
+ }
116
+ .empirical-mouse-pointer.button-3 {
117
+ transition: none;
118
+ border-radius: 4px;
119
+ }
120
+ .empirical-mouse-pointer.button-4 {
121
+ transition: none;
122
+ border-color: rgba(255,0,0,0.9);
123
+ }
124
+ .empirical-mouse-pointer.button-5 {
125
+ transition: none;
126
+ border-color: rgba(0,255,0,0.9);
127
+ }
128
+ .empirical-element-grab-highlight {
129
+ outline: 2px dashed cyan !important;
130
+ }
131
+ *:focus {
132
+ outline: 2px dashed #FF000D !important;
133
+ }
134
+ *:focus-visible {
135
+ outline: 2px dashed #FF000D !important;
136
+ }
137
+ `;
138
+ document.head.appendChild(styleElement);
139
+ document.body.appendChild(box);
140
+ document.addEventListener("mousemove", (event) => {
141
+ box.style.left = `${event.pageX}px`;
142
+ box.style.top = `${event.pageY}px`;
143
+ updateButtons(event.buttons);
144
+ }, true);
145
+ document.addEventListener("mousedown", (event) => {
146
+ updateButtons(event.buttons);
147
+ box.classList.add(`button-${event.button + 1}`);
148
+ }, true);
149
+ document.addEventListener("mouseup", (event) => {
150
+ updateButtons(event.buttons);
151
+ box.classList.remove(`button-${event.button + 1}`);
152
+ }, true);
153
+ // @ts-ignore
154
+ function updateButtons(buttons) {
155
+ for (let i = 0; i < 5; i++) {
156
+ box.classList.toggle(`button-${i + 1}`, (buttons / Math.pow(2, i)) % 2 >= 1);
157
+ }
158
+ }
159
+ });
160
+ }
161
+ catch (e) {
162
+ logger_1.logger.debug(`Error adding mouse pointer highlighter`, e);
163
+ }
164
+ });
165
+ });
85
166
  }
86
167
  exports.addMousePointerHighlighter = addMousePointerHighlighter;
@@ -1,49 +1,6 @@
1
- import type { Locator, Page, PlaywrightTestArgs } from "@playwright/test";
2
1
  export type HighlighterOpts = {
3
2
  mousePointerHighlighter?: boolean;
4
3
  locatorHighlighter?: boolean;
5
4
  visionMethods?: boolean;
6
5
  };
7
- interface EnhancedLocator extends Locator {
8
- query(instruction: string): Promise<string>;
9
- }
10
- interface EnhancedPage extends Page {
11
- locator(selector: string, options?: {
12
- has?: Locator;
13
- hasNot?: Locator;
14
- hasNotText?: string | RegExp;
15
- hasText?: string | RegExp;
16
- }): EnhancedLocator;
17
- getByRole(role: "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "deletion" | "dialog" | "directory" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "meter" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "paragraph" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem", options?: {
18
- checked?: boolean;
19
- disabled?: boolean;
20
- exact?: boolean;
21
- expanded?: boolean;
22
- includeHidden?: boolean;
23
- level?: number;
24
- name?: string | RegExp;
25
- pressed?: boolean;
26
- selected?: boolean;
27
- }): EnhancedLocator;
28
- getByLabel(text: string | RegExp, options?: {
29
- exact?: boolean;
30
- }): EnhancedLocator;
31
- getByPlaceholder(text: string | RegExp, options?: {
32
- exact?: boolean;
33
- }): EnhancedLocator;
34
- getByText(text: string | RegExp, options?: {
35
- exact?: boolean;
36
- }): EnhancedLocator;
37
- getByTestId(testId: string | RegExp): EnhancedLocator;
38
- getByAltText(text: string | RegExp, options?: {
39
- exact?: boolean;
40
- }): EnhancedLocator;
41
- getByTitle(text: string | RegExp, options?: {
42
- exact?: boolean;
43
- }): EnhancedLocator;
44
- }
45
- export interface EnhancedPlaywrightTestArgs extends PlaywrightTestArgs {
46
- page: EnhancedPage;
47
- }
48
- export {};
49
6
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/test/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE1E,MAAM,MAAM,eAAe,GAAG;IAC5B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,UAAU,eAAgB,SAAQ,OAAO;IACvC,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,UAAU,YAAa,SAAQ,IAAI;IAEjC,OAAO,CACL,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;QACd,MAAM,CAAC,EAA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,EAAE,OAAO,CAAC;CACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.15.3",
3
+ "version": "0.15.5",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"