@atomic-testing/playwright 0.87.0 → 0.89.0
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/README.md +7 -0
- package/dist/index.cjs +213 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -29
- package/dist/index.d.mts +113 -29
- package/dist/index.mjs +215 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/PlaywrightInteractor.ts +257 -40
- package/src/index.ts +0 -1
- package/src/testRunnerAdapter.ts +0 -79
package/README.md
CHANGED
|
@@ -12,3 +12,10 @@ pnpm add @atomic-testing/playwright
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
See the [docs](https://atomic-testing.dev/) for configuration and usage details.
|
|
15
|
+
|
|
16
|
+
## Public API & stability
|
|
17
|
+
|
|
18
|
+
The stable surface of this package is its `.` barrel exports, frozen under
|
|
19
|
+
SemVer and machine-checked by the committed [API Extractor](https://api-extractor.com/)
|
|
20
|
+
report at [`etc/playwright.api.md`](etc/playwright.api.md). Exports tagged `@internal` are
|
|
21
|
+
not part of that guarantee. See the [1.0 API freeze & evolution policy](../../agent-docs/adr/006-1.0-api-freeze-and-evolution.md).
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _atomic_testing_core = require("@atomic-testing/core");
|
|
3
|
-
let _playwright_test = require("@playwright/test");
|
|
4
3
|
//#region src/PlaywrightInteractor.ts
|
|
5
4
|
/**
|
|
6
5
|
* Implementation of the {@link Interactor} interface using Playwright.
|
|
@@ -13,14 +12,138 @@ var PlaywrightInteractor = class PlaywrightInteractor {
|
|
|
13
12
|
this.page = page;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
15
|
+
* Run a Playwright mutation and normalize a "locator matched nothing" failure
|
|
16
|
+
* into {@link ElementNotFoundError}, so a missing element throws the same error
|
|
17
|
+
* class here as it does in `DOMInteractor`, regardless of environment (the
|
|
18
|
+
* unified contract ratified in ADR-006).
|
|
19
|
+
*
|
|
20
|
+
* Playwright auto-waits for actionability and then throws its own
|
|
21
|
+
* `TimeoutError`. We translate that to `ElementNotFoundError` ONLY when the
|
|
22
|
+
* element genuinely does not exist (count 0) and otherwise rethrow the original
|
|
23
|
+
* error — preserving Playwright's auto-wait for an element that exists but is
|
|
24
|
+
* briefly not actionable (covered, disabled, animating). The trade-off is that
|
|
25
|
+
* a truly-missing element waits out the page's action timeout before throwing;
|
|
26
|
+
* bound it with `page.setDefaultTimeout` when fast failure matters.
|
|
27
|
+
*
|
|
28
|
+
* @param locator - Locator the mutation targets
|
|
29
|
+
* @param action - Method name used in the error message (e.g. `'click'`)
|
|
30
|
+
* @param run - The Playwright action to execute
|
|
31
|
+
* @throws {ElementNotFoundError} If the action fails and the element is absent
|
|
32
|
+
*/
|
|
33
|
+
async runMutation(locator, action, run) {
|
|
34
|
+
try {
|
|
35
|
+
return await run();
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (await this.exists(locator) === false) throw new _atomic_testing_core.ElementNotFoundError(locator, action);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
16
42
|
* Select the given option values on a `<select>` element.
|
|
17
43
|
*
|
|
18
44
|
* @param locator - Locator to the `<select>` element.
|
|
19
45
|
* @param values - Values to select.
|
|
46
|
+
* @throws {ElementNotFoundError} If the element is not found
|
|
20
47
|
*/
|
|
21
48
|
async selectOptionValue(locator, values) {
|
|
22
49
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
23
|
-
await this.page.locator(cssLocator).selectOption(values);
|
|
50
|
+
await this.runMutation(locator, "selectOptionValue", () => this.page.locator(cssLocator).selectOption(values));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the selected files on a `<input type="file">` element.
|
|
54
|
+
*
|
|
55
|
+
* Playwright's native `setInputFiles` reads the given paths from disk and
|
|
56
|
+
* populates the input's `FileList`, firing the change event — the only way to
|
|
57
|
+
* fill a file input, whose value cannot be set programmatically.
|
|
58
|
+
*
|
|
59
|
+
* @param locator - Locator of the `<input type="file">` element
|
|
60
|
+
* @param files - One or more filesystem paths to upload
|
|
61
|
+
* @throws {ElementNotFoundError} If the element is not found
|
|
62
|
+
*/
|
|
63
|
+
async setInputFiles(locator, files) {
|
|
64
|
+
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
65
|
+
await this.runMutation(locator, "setInputFiles", () => this.page.locator(cssLocator).setInputFiles(files));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Scroll the located element into view, no-op if already visible.
|
|
69
|
+
*
|
|
70
|
+
* Delegates to Playwright's `scrollIntoViewIfNeeded`, which performs a real
|
|
71
|
+
* layout-aware scroll in the browser.
|
|
72
|
+
*
|
|
73
|
+
* @param locator - Locator of the element to scroll into view
|
|
74
|
+
* @throws {ElementNotFoundError} If the element is not found
|
|
75
|
+
*/
|
|
76
|
+
async scrollIntoView(locator) {
|
|
77
|
+
const css = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
78
|
+
await this.runMutation(locator, "scrollIntoView", () => this.page.locator(css).scrollIntoViewIfNeeded());
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Scroll the located element by the given pixel delta.
|
|
82
|
+
*
|
|
83
|
+
* The scroll is performed by evaluating `el.scrollBy(dx, dy)` on the element
|
|
84
|
+
* itself rather than `page.mouse.wheel`. A wheel event scrolls whatever sits
|
|
85
|
+
* under the pointer and is non-deterministic across chromium/firefox/webkit,
|
|
86
|
+
* whereas evaluating `scrollBy` on the resolved element scrolls exactly that
|
|
87
|
+
* element. This is a deliberate deviation from ADR 0001's per-engine table
|
|
88
|
+
* (which lists `page.mouse.wheel`), taking the alternative the step-5 prompt
|
|
89
|
+
* permits ("or evaluate el.scrollBy") for cross-browser determinism.
|
|
90
|
+
*
|
|
91
|
+
* @param locator - Locator of the scrollable element
|
|
92
|
+
* @param delta - Pixel offset to scroll by
|
|
93
|
+
* @throws {ElementNotFoundError} If the element is not found
|
|
94
|
+
*/
|
|
95
|
+
async scrollBy(locator, delta) {
|
|
96
|
+
const css = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
97
|
+
await this.runMutation(locator, "scrollBy", () => this.page.locator(css).evaluate((el, d) => el.scrollBy(d.x, d.y), {
|
|
98
|
+
x: delta.x,
|
|
99
|
+
y: delta.y
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Drag the source element and drop it onto the target element.
|
|
104
|
+
*
|
|
105
|
+
* Delegates to Playwright's native `Locator.dragTo`, which performs a real,
|
|
106
|
+
* layout-aware drag gesture in the browser.
|
|
107
|
+
*
|
|
108
|
+
* @param source - Locator of the element to drag
|
|
109
|
+
* @param target - Locator of the drop target
|
|
110
|
+
* @throws {ElementNotFoundError} If either the source or target is not found
|
|
111
|
+
*/
|
|
112
|
+
async dragTo(source, target) {
|
|
113
|
+
const srcCss = await _atomic_testing_core.locatorUtil.toCssSelector(source, this);
|
|
114
|
+
const tgtCss = await _atomic_testing_core.locatorUtil.toCssSelector(target, this);
|
|
115
|
+
try {
|
|
116
|
+
await this.page.locator(srcCss).dragTo(this.page.locator(tgtCss));
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (await this.exists(source) === false) throw new _atomic_testing_core.ElementNotFoundError(source, "dragTo");
|
|
119
|
+
if (await this.exists(target) === false) throw new _atomic_testing_core.ElementNotFoundError(target, "dragTo");
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Drag the located element by the given pixel delta from its center.
|
|
125
|
+
*
|
|
126
|
+
* The gesture is a single uninterrupted `move → down → move → up` sequence
|
|
127
|
+
* computed from the element's center. It deliberately does NOT reuse
|
|
128
|
+
* {@link mouseMove}/{@link mouseDown} — `mouseMove` resets the pointer with
|
|
129
|
+
* `page.mouse.move(0, 0)` after hovering, which would corrupt the drag path
|
|
130
|
+
* (see ADR 0001, option 5). The center comes from {@link getBoundingRect},
|
|
131
|
+
* which throws `ElementNotFoundError` when the element has no box, so this
|
|
132
|
+
* shares that "element not found" contract instead of re-deriving the box +
|
|
133
|
+
* guard here.
|
|
134
|
+
*
|
|
135
|
+
* @param locator - Locator of the element to drag
|
|
136
|
+
* @param delta - Pixel offset to drag by
|
|
137
|
+
* @throws {ElementNotFoundError} If the element has no bounding box
|
|
138
|
+
*/
|
|
139
|
+
async drag(locator, delta) {
|
|
140
|
+
const rect = await this.getBoundingRect(locator);
|
|
141
|
+
const cx = rect.x + rect.width / 2;
|
|
142
|
+
const cy = rect.y + rect.height / 2;
|
|
143
|
+
await this.page.mouse.move(cx, cy);
|
|
144
|
+
await this.page.mouse.down();
|
|
145
|
+
await this.page.mouse.move(cx + delta.x, cy + delta.y, { steps: 8 });
|
|
146
|
+
await this.page.mouse.up();
|
|
24
147
|
}
|
|
25
148
|
/**
|
|
26
149
|
* Get the value of an `<input>` element.
|
|
@@ -70,65 +193,105 @@ var PlaywrightInteractor = class PlaywrightInteractor {
|
|
|
70
193
|
}
|
|
71
194
|
async enterText(locator, text, option) {
|
|
72
195
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
196
|
+
await this.runMutation(locator, "enterText", async () => {
|
|
197
|
+
if (!option?.append) await this.page.locator(cssLocator).clear();
|
|
198
|
+
const type = await this.getAttribute(locator, "type") ?? "";
|
|
199
|
+
if (_atomic_testing_core.dateUtil.isHtmlDateInputType(type)) {
|
|
200
|
+
const result = _atomic_testing_core.dateUtil.validateHtmlDateInput(type, text);
|
|
201
|
+
if (!result.valid) throw new Error(`Invalid date format for type: ${type}, expected format: ${result.format}, example: ${result.example}`);
|
|
202
|
+
}
|
|
203
|
+
await this.page.locator(cssLocator).fill(text);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async setRangeValue(locator, value) {
|
|
207
|
+
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
208
|
+
await this.runMutation(locator, "setRangeValue", () => this.page.locator(cssLocator).evaluate((el, nextValue) => {
|
|
209
|
+
const input = el;
|
|
210
|
+
(Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(input, nextValue);
|
|
211
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
212
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
213
|
+
}, String(value)));
|
|
80
214
|
}
|
|
81
215
|
async click(locator, option) {
|
|
82
216
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
83
|
-
await this.page.locator(cssLocator).click({ position: option?.position });
|
|
217
|
+
await this.runMutation(locator, "click", () => this.page.locator(cssLocator).click({ position: option?.position }));
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Dispatch a right-click on the located element to open its context menu.
|
|
221
|
+
*
|
|
222
|
+
* Delegates to Playwright's native right-button click, which fires a real
|
|
223
|
+
* `contextmenu` event in the browser.
|
|
224
|
+
*
|
|
225
|
+
* @param locator - Locator of the element to right-click
|
|
226
|
+
* @throws {ElementNotFoundError} If the element is not found
|
|
227
|
+
*/
|
|
228
|
+
async contextMenu(locator) {
|
|
229
|
+
const css = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
230
|
+
await this.runMutation(locator, "contextMenu", () => this.page.locator(css).click({ button: "right" }));
|
|
84
231
|
}
|
|
85
232
|
async hover(locator, option) {
|
|
86
233
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
87
|
-
await this.page.locator(cssLocator).hover({ position: option?.position });
|
|
234
|
+
await this.runMutation(locator, "hover", () => this.page.locator(cssLocator).hover({ position: option?.position }));
|
|
88
235
|
}
|
|
89
236
|
async mouseMove(locator, option) {
|
|
90
|
-
await this.
|
|
91
|
-
|
|
237
|
+
await this.runMutation(locator, "mouseMove", async () => {
|
|
238
|
+
await this.hover(locator, { position: option?.position });
|
|
239
|
+
await this.page.mouse.move(0, 0);
|
|
240
|
+
});
|
|
92
241
|
}
|
|
93
242
|
async mouseDown(locator, option) {
|
|
94
|
-
await this.
|
|
95
|
-
|
|
243
|
+
await this.runMutation(locator, "mouseDown", async () => {
|
|
244
|
+
await this.hover(locator, { position: option?.position });
|
|
245
|
+
await this.page.mouse.down();
|
|
246
|
+
});
|
|
96
247
|
}
|
|
97
248
|
async mouseUp(locator, option) {
|
|
98
|
-
await this.
|
|
99
|
-
|
|
249
|
+
await this.runMutation(locator, "mouseUp", async () => {
|
|
250
|
+
await this.hover(locator, { position: option?.position });
|
|
251
|
+
await this.page.mouse.up();
|
|
252
|
+
});
|
|
100
253
|
}
|
|
101
254
|
async mouseOver(locator, option) {
|
|
102
|
-
|
|
255
|
+
await this.runMutation(locator, "mouseOver", () => this.hover(locator, option));
|
|
103
256
|
}
|
|
104
257
|
async mouseOut(locator, _option) {
|
|
105
258
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
106
|
-
await this.
|
|
107
|
-
|
|
259
|
+
await this.runMutation(locator, "mouseOut", async () => {
|
|
260
|
+
await this.page.locator(cssLocator).hover();
|
|
261
|
+
await this.page.locator(cssLocator).dispatchEvent("mouseout");
|
|
262
|
+
});
|
|
108
263
|
}
|
|
109
264
|
async mouseEnter(locator, _option) {
|
|
110
|
-
|
|
265
|
+
await this.runMutation(locator, "mouseEnter", () => this.hover(locator));
|
|
111
266
|
}
|
|
112
267
|
async mouseLeave(locator, _option) {
|
|
113
268
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
114
|
-
await this.
|
|
115
|
-
|
|
269
|
+
await this.runMutation(locator, "mouseLeave", async () => {
|
|
270
|
+
await this.page.locator(cssLocator).hover();
|
|
271
|
+
await this.page.locator(cssLocator).dispatchEvent("mouseout");
|
|
272
|
+
});
|
|
116
273
|
}
|
|
117
274
|
async focus(locator, _option) {
|
|
118
275
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
119
|
-
|
|
276
|
+
await this.runMutation(locator, "focus", () => this.page.focus(cssLocator));
|
|
120
277
|
}
|
|
121
278
|
async blur(locator, _option) {
|
|
122
279
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
123
|
-
await this.page.locator(cssLocator).blur();
|
|
280
|
+
await this.runMutation(locator, "blur", () => this.page.locator(cssLocator).blur());
|
|
124
281
|
}
|
|
125
|
-
async pressKey(locator, key,
|
|
282
|
+
async pressKey(locator, key, option) {
|
|
126
283
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
127
|
-
|
|
284
|
+
const modifiers = [];
|
|
285
|
+
if (option?.ctrl) modifiers.push("Control");
|
|
286
|
+
if (option?.alt) modifiers.push("Alt");
|
|
287
|
+
if (option?.shift) modifiers.push("Shift");
|
|
288
|
+
if (option?.meta) modifiers.push("Meta");
|
|
289
|
+
const chord = modifiers.length > 0 ? `${modifiers.join("+")}+${key}` : key;
|
|
290
|
+
await this.runMutation(locator, "pressKey", () => this.page.locator(cssLocator).press(chord));
|
|
128
291
|
}
|
|
129
292
|
async activate(locator) {
|
|
130
293
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
131
|
-
await this.page.locator(cssLocator).dispatchEvent("click");
|
|
294
|
+
await this.runMutation(locator, "activate", () => this.page.locator(cssLocator).dispatchEvent("click"));
|
|
132
295
|
}
|
|
133
296
|
wait(ms) {
|
|
134
297
|
return _atomic_testing_core.timingUtil.wait(ms);
|
|
@@ -157,6 +320,28 @@ var PlaywrightInteractor = class PlaywrightInteractor {
|
|
|
157
320
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
158
321
|
return await this.page.locator(cssLocator).textContent() ?? void 0;
|
|
159
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Get the located element's bounding rectangle.
|
|
325
|
+
*
|
|
326
|
+
* `boundingBox()` returns `null` for a detached/invisible element rather than
|
|
327
|
+
* auto-waiting, so this throws `ElementNotFoundError` directly (no auto-wait)
|
|
328
|
+
* — matching the unified "element not found" contract (ADR-006).
|
|
329
|
+
*
|
|
330
|
+
* @param locator - Locator of the element to measure
|
|
331
|
+
* @returns The element's bounding rectangle in CSS pixels
|
|
332
|
+
* @throws {ElementNotFoundError} If the element has no bounding box
|
|
333
|
+
*/
|
|
334
|
+
async getBoundingRect(locator) {
|
|
335
|
+
const css = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
336
|
+
const box = await this.page.locator(css).boundingBox();
|
|
337
|
+
if (box == null) throw new _atomic_testing_core.ElementNotFoundError(locator, "getBoundingRect");
|
|
338
|
+
return {
|
|
339
|
+
x: box.x,
|
|
340
|
+
y: box.y,
|
|
341
|
+
width: box.width,
|
|
342
|
+
height: box.height
|
|
343
|
+
};
|
|
344
|
+
}
|
|
160
345
|
async exists(locator) {
|
|
161
346
|
const cssLocator = await _atomic_testing_core.locatorUtil.toCssSelector(locator, this);
|
|
162
347
|
return await this.page.locator(cssLocator).count() > 0;
|
|
@@ -217,52 +402,7 @@ function createTestEngine(page, partDefinitions) {
|
|
|
217
402
|
return new _atomic_testing_core.TestEngine([], new PlaywrightInteractor(page), { parts: partDefinitions });
|
|
218
403
|
}
|
|
219
404
|
//#endregion
|
|
220
|
-
//#region src/testRunnerAdapter.ts
|
|
221
|
-
async function goto(url, fixture) {
|
|
222
|
-
await fixture.page.goto(url);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Create a {@link TestEngine} bound to the Playwright page in the given fixture.
|
|
226
|
-
*
|
|
227
|
-
* @param scenePart - Scene definition to drive.
|
|
228
|
-
* @param fixture - Fixture providing the Playwright page.
|
|
229
|
-
*/
|
|
230
|
-
function playwrightGetTestEngine(scenePart, fixture) {
|
|
231
|
-
const page = fixture.page;
|
|
232
|
-
return createTestEngine(page, scenePart);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Playwright adapter for the TestFrameworkMapper interface.
|
|
236
|
-
*/
|
|
237
|
-
const playWrightTestFrameworkMapper = {
|
|
238
|
-
assertEqual: (a, b) => (0, _playwright_test.expect)(a).toEqual(b),
|
|
239
|
-
assertNotEqual: (a, b) => (0, _playwright_test.expect)(a).not.toEqual(b),
|
|
240
|
-
assertTrue: (value) => (0, _playwright_test.expect)(value).toBe(true),
|
|
241
|
-
assertFalse: (value) => (0, _playwright_test.expect)(value).toBe(false),
|
|
242
|
-
assertApproxEqual: (actual, expected, tolerance) => (0, _playwright_test.expect)(Math.abs(actual - expected)).toBeLessThanOrEqual(tolerance),
|
|
243
|
-
describe: _playwright_test.test.describe,
|
|
244
|
-
beforeEach: _playwright_test.test.beforeEach,
|
|
245
|
-
afterEach: _playwright_test.test.afterEach,
|
|
246
|
-
beforeAll: _playwright_test.test.beforeAll,
|
|
247
|
-
afterAll: _playwright_test.test.afterAll,
|
|
248
|
-
test: _playwright_test.test,
|
|
249
|
-
it: _playwright_test.test
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Get a typed interface for running end-to-end tests with Playwright.
|
|
253
|
-
*/
|
|
254
|
-
function getTestRunnerInterface() {
|
|
255
|
-
return {
|
|
256
|
-
getTestEngine: playwrightGetTestEngine,
|
|
257
|
-
goto
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
//#endregion
|
|
261
405
|
exports.PlaywrightInteractor = PlaywrightInteractor;
|
|
262
406
|
exports.createTestEngine = createTestEngine;
|
|
263
|
-
exports.getTestRunnerInterface = getTestRunnerInterface;
|
|
264
|
-
exports.goto = goto;
|
|
265
|
-
exports.playWrightTestFrameworkMapper = playWrightTestFrameworkMapper;
|
|
266
|
-
exports.playwrightGetTestEngine = playwrightGetTestEngine;
|
|
267
407
|
|
|
268
408
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["locatorUtil","dateUtil","timingUtil","defaultWaitForOption","interactorUtil","TestEngine","test"],"sources":["../src/PlaywrightInteractor.ts","../src/createTestEngine.ts","../src/testRunnerAdapter.ts"],"sourcesContent":["import {\n BlurOption,\n byCssSelector,\n ClickOption,\n CssProperty,\n dateUtil,\n defaultWaitForOption,\n EnterTextOption,\n FocusOption,\n HoverOption,\n Interactor,\n interactorUtil,\n locatorUtil,\n MouseEnterOption,\n MouseLeaveOption,\n MouseOutOption,\n MouseDownOption,\n MouseMoveOption,\n MouseUpOption,\n Optional,\n PartLocator,\n PressKeyOption,\n timingUtil,\n WaitForOption,\n WaitUntilOption,\n} from '@atomic-testing/core';\nimport { Page } from '@playwright/test';\n\n/**\n * Implementation of the {@link Interactor} interface using Playwright.\n */\nexport class PlaywrightInteractor implements Interactor {\n /**\n * @param page - Playwright page instance used to drive the browser.\n */\n constructor(public readonly page: Page) {}\n\n /**\n * Select the given option values on a `<select>` element.\n *\n * @param locator - Locator to the `<select>` element.\n * @param values - Values to select.\n */\n async selectOptionValue(locator: PartLocator, values: string[]): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.page.locator(cssLocator).selectOption(values);\n }\n\n /**\n * Get the value of an `<input>` element.\n *\n * @param locator - Locator pointing to the input element.\n * @returns The current value of the input or `undefined` if not present.\n */\n async getInputValue(locator: PartLocator): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n return this.page.locator(cssLocator).inputValue();\n }\n\n /**\n * Retrieve the values of selected options within a `<select>` element.\n *\n * @param locator - Locator to the `<select>` element.\n * @returns Array of selected option values or `undefined` when no option is selected.\n */\n async getSelectValues(locator: PartLocator): Promise<Optional<readonly string[]>> {\n const optionLocator: PartLocator = byCssSelector('option:checked');\n const selectedOptionLocator = locatorUtil.append(locator, optionLocator);\n const cssLocator = await locatorUtil.toCssSelector(selectedOptionLocator, this);\n const allOptions = await this.page.locator(cssLocator).all();\n const values: string[] = [];\n for (const option of allOptions) {\n const value = await option.getAttribute('value');\n if (value != null) {\n values.push(value);\n }\n }\n return values;\n }\n\n async getSelectLabels(locator: PartLocator): Promise<Optional<readonly string[]>> {\n const optionLocator: PartLocator = byCssSelector('option:checked');\n const selectedOptionLocator = locatorUtil.append(locator, optionLocator);\n const cssLocator = await locatorUtil.toCssSelector(selectedOptionLocator, this);\n const allOptions = await this.page.locator(cssLocator).all();\n const labels: string[] = [];\n for (const option of allOptions) {\n const label = await option.textContent();\n if (label != null) {\n labels.push(label);\n }\n }\n return labels;\n }\n\n async getStyleValue(locator: PartLocator, propertyName: CssProperty): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const elLocator = this.page.locator(cssLocator);\n const value = await elLocator.evaluate((element, prop) => {\n return window.getComputedStyle(element).getPropertyValue(prop as string);\n }, propertyName);\n return value;\n }\n\n async enterText(locator: PartLocator, text: string, option?: Optional<Partial<EnterTextOption>>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n if (!option?.append) {\n await this.page.locator(cssLocator).clear();\n }\n\n // If it is a date, time or datetime-local input, validate the date format\n const type = (await this.getAttribute(locator, 'type')) ?? '';\n if (dateUtil.isHtmlDateInputType(type)) {\n const result = dateUtil.validateHtmlDateInput(type, text);\n if (!result.valid) {\n throw new Error(\n `Invalid date format for type: ${type}, expected format: ${result.format}, example: ${result.example}`\n );\n }\n }\n await this.page.locator(cssLocator).fill(text);\n }\n\n async click(locator: PartLocator, option?: Partial<ClickOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.page.locator(cssLocator).click({ position: option?.position });\n }\n\n async hover(locator: PartLocator, option?: Partial<HoverOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.page.locator(cssLocator).hover({ position: option?.position });\n }\n\n async mouseMove(locator: PartLocator, option?: Partial<MouseMoveOption>): Promise<void> {\n await this.hover(locator, {\n position: option?.position,\n });\n await this.page.mouse.move(0, 0);\n }\n\n async mouseDown(locator: PartLocator, option?: Partial<MouseDownOption>): Promise<void> {\n await this.hover(locator, {\n position: option?.position,\n });\n await this.page.mouse.down();\n }\n\n async mouseUp(locator: PartLocator, option?: Partial<MouseUpOption>): Promise<void> {\n await this.hover(locator, {\n position: option?.position,\n });\n await this.page.mouse.up();\n }\n\n async mouseOver(locator: PartLocator, option?: Partial<HoverOption>): Promise<void> {\n return this.hover(locator, option);\n }\n\n async mouseOut(locator: PartLocator, _option?: Partial<MouseOutOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // First hover over the element to trigger mouseenter/mouseover\n await this.page.locator(cssLocator).hover();\n // Then dispatch mouseout event directly for cross-browser reliability\n await this.page.locator(cssLocator).dispatchEvent('mouseout');\n }\n\n async mouseEnter(locator: PartLocator, _option?: Partial<MouseEnterOption>): Promise<void> {\n return this.hover(locator);\n }\n\n async mouseLeave(locator: PartLocator, _option?: Partial<MouseLeaveOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // First hover over the element to trigger mouseenter/mouseover\n await this.page.locator(cssLocator).hover();\n // Dispatch mouseout which triggers both mouseout and mouseleave handlers in React\n await this.page.locator(cssLocator).dispatchEvent('mouseout');\n }\n\n async focus(locator: PartLocator, _option?: Partial<FocusOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n return this.page.focus(cssLocator);\n }\n\n async blur(locator: PartLocator, _option?: Partial<BlurOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.page.locator(cssLocator).blur();\n }\n\n async pressKey(locator: PartLocator, key: string, _option?: Partial<PressKeyOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // locator.press auto-focuses the element, then dispatches a real, trusted\n // KeyboardEvent — the browser equivalent of the DOM focus-first keyDown/keyUp.\n await this.page.locator(cssLocator).press(key);\n }\n\n async activate(locator: PartLocator): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // Geometry-free activation mirrors the mouseout dispatch precedent above: it\n // bypasses hit-testing to actuate a covered or zero-size input that\n // locator.click() (a real geometry hit-test) cannot reach.\n await this.page.locator(cssLocator).dispatchEvent('click');\n }\n\n //#region wait conditions\n wait(ms: number): Promise<void> {\n return timingUtil.wait(ms);\n }\n\n async waitUntilComponentState(\n locator: PartLocator,\n option: Partial<Readonly<WaitForOption>> = defaultWaitForOption\n ): Promise<void> {\n return interactorUtil.interactorWaitUtil(locator, this, option);\n }\n\n waitUntil<T>(option: WaitUntilOption<T>): Promise<T> {\n return timingUtil.waitUntil(option);\n }\n //#endregion\n\n async getAttribute(locator: PartLocator, name: string, isMultiple: true): Promise<readonly string[]>;\n async getAttribute(locator: PartLocator, name: string, isMultiple: false): Promise<Optional<string>>;\n async getAttribute(locator: PartLocator, name: string): Promise<Optional<string>>;\n async getAttribute(\n locator: PartLocator,\n name: string,\n isMultiple?: boolean\n ): Promise<Optional<string> | readonly string[]> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const elLocator = this.page.locator(cssLocator);\n if (isMultiple) {\n const locators = await elLocator.all();\n const values: string[] = [];\n for (const locator of locators) {\n const value = await locator.getAttribute(name);\n if (value != null) {\n values.push(value);\n }\n }\n return values;\n }\n const value = await elLocator.getAttribute(name);\n return value ?? undefined;\n }\n\n async getText(locator: PartLocator): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const text = await this.page.locator(cssLocator).textContent();\n return text ?? undefined;\n }\n\n async exists(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const count = await this.page.locator(cssLocator).count();\n return count > 0;\n }\n\n async isChecked(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const checked = await this.page.locator(cssLocator).isChecked();\n return checked;\n }\n\n async isDisabled(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const isDisabled = await this.page.locator(cssLocator).isDisabled();\n return isDisabled;\n }\n\n async isReadonly(locator: PartLocator): Promise<boolean> {\n const readonly = await this.getAttribute(locator, 'readonly');\n return readonly != null;\n }\n\n async isVisible(locator: PartLocator): Promise<boolean> {\n const exists = await this.exists(locator);\n if (!exists) {\n return false;\n }\n\n async function checkCssVisibility(\n prop: CssProperty,\n invisibleValue: string,\n interactor: PlaywrightInteractor\n ): Promise<boolean> {\n try {\n const value = await interactor.getStyleValue(locator, prop);\n return value !== invisibleValue;\n } catch (e) {\n // Element may disappear or detached while being checked because of animation\n // when it happens, an error is thrown. In this case, if indeed the element\n // is not visible, we return false. Otherwise, we re-throw the error.\n if ((await interactor.exists(locator)) === false) {\n return false;\n }\n throw e;\n }\n }\n\n if ((await checkCssVisibility('opacity', '0', this)) === false) {\n return false;\n }\n\n if ((await checkCssVisibility('visibility', 'hidden', this)) === false) {\n return false;\n }\n\n if ((await checkCssVisibility('display', 'none', this)) === false) {\n return false;\n }\n\n return true;\n }\n\n async hasCssClass(locator: PartLocator, className: string): Promise<boolean> {\n const classNames = await this.getAttribute(locator, 'class');\n if (classNames == null) {\n return false;\n }\n\n const names = classNames.split(/\\s+/);\n return names.includes(className);\n }\n\n async hasAttribute(locator: PartLocator, name: string): Promise<boolean> {\n const attrValue = await this.getAttribute(locator, name);\n return attrValue != null;\n }\n\n //#region\n async innerHTML(locator: PartLocator): Promise<string> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n return this.page.locator(cssLocator).innerHTML();\n }\n //#endregion\n\n clone(): Interactor {\n return new PlaywrightInteractor(this.page);\n }\n}\n","import { ScenePart, TestEngine } from '@atomic-testing/core';\nimport { Page } from '@playwright/test';\n\nimport { PlaywrightInteractor } from './PlaywrightInteractor';\n\n/**\n * Create a {@link TestEngine} instance backed by Playwright.\n *\n * @param page - Playwright page used for interaction.\n * @param partDefinitions - Scene part definitions describing the scene\n * structure for the engine.\n * @returns A configured {@link TestEngine} ready for use.\n */\nexport function createTestEngine<T extends ScenePart>(page: Page, partDefinitions: T): TestEngine<T> {\n const engine = new TestEngine([], new PlaywrightInteractor(page), {\n parts: partDefinitions,\n });\n\n return engine;\n}\n","import { ScenePart, TestEngine } from '@atomic-testing/core';\nimport {\n E2eTestInterface,\n E2eTestRunEnvironmentFixture,\n TestFrameworkMapper,\n} from '@atomic-testing/internal-test-runner';\nimport { expect, Page, test } from '@playwright/test';\n\nimport { createTestEngine } from './createTestEngine';\n\n/**\n * Navigate the current Playwright page to the provided URL.\n *\n * @param url - Destination URL to load.\n * @param fixture - Optional test fixture supplying the Playwright page.\n */\nexport async function goto(url: string): Promise<void>;\nexport async function goto(url: string, fixture: E2eTestRunEnvironmentFixture): Promise<void>;\nexport async function goto(url: string, fixture?: E2eTestRunEnvironmentFixture): Promise<void> {\n const page = fixture!.page as Page;\n await page.goto(url);\n}\n\n/**\n * Create a {@link TestEngine} bound to the Playwright page in the given fixture.\n *\n * @param scenePart - Scene definition to drive.\n * @param fixture - Fixture providing the Playwright page.\n */\nexport function playwrightGetTestEngine<T extends ScenePart>(\n scenePart: T,\n fixture: E2eTestRunEnvironmentFixture\n): TestEngine<T> {\n const page = fixture.page as Page;\n return createTestEngine(page, scenePart);\n}\n\n/**\n * Playwright adapter for the TestFrameworkMapper interface.\n */\nexport const playWrightTestFrameworkMapper: TestFrameworkMapper = {\n /*\n * INTENTIONAL @ts-expect-error comments: Playwright's test functions have different type\n * signatures than the normalized TestFrameworkMapper interface. Playwright uses fixture-based\n * callbacks with destructuring ({ page, browser }) while our interface uses a union type for\n * Jest compatibility (done callback or fixture object). The functions are compatible at runtime\n * but TypeScript cannot verify this due to these fundamental signature differences.\n */\n\n assertEqual: (a, b) => expect(a).toEqual(b),\n assertNotEqual: (a, b) => expect(a).not.toEqual(b),\n assertTrue: value => expect(value).toBe(true),\n assertFalse: value => expect(value).toBe(false),\n assertApproxEqual: (actual, expected, tolerance) =>\n expect(Math.abs(actual - expected)).toBeLessThanOrEqual(tolerance),\n // @ts-expect-error - Playwright describe signature differs from TestFrameworkMapper.Describe\n describe: test.describe,\n\n beforeEach: test.beforeEach,\n afterEach: test.afterEach,\n beforeAll: test.beforeAll,\n afterAll: test.afterAll,\n\n // @ts-expect-error - Playwright test signature differs from TestFrameworkMapper.Test\n test: test,\n\n // @ts-expect-error - Playwright test signature differs from TestFrameworkMapper.Test\n it: test,\n};\n\n/**\n * Get a typed interface for running end-to-end tests with Playwright.\n */\nexport function getTestRunnerInterface<T extends ScenePart>(): E2eTestInterface<T> {\n return {\n getTestEngine: playwrightGetTestEngine,\n goto,\n };\n}\n"],"mappings":";;;;;;;AA+BA,IAAa,uBAAb,MAAa,qBAA2C;;;;CAItD,YAAY,MAA4B;EAAZ,KAAA,OAAA;CAAa;;;;;;;CAQzC,MAAM,kBAAkB,SAAsB,QAAiC;EAC7E,MAAM,aAAa,MAAMA,qBAAAA,YAAY,cAAc,SAAS,IAAI;EAChE,MAAM,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,aAAa,MAAM;CACzD;;;;;;;CAQA,MAAM,cAAc,SAAiD;EACnE,MAAM,aAAa,MAAMA,qBAAAA,YAAY,cAAc,SAAS,IAAI;EAChE,OAAO,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,WAAW;CAClD;;;;;;;CAQA,MAAM,gBAAgB,SAA4D;EAChF,MAAM,iBAAA,GAAA,qBAAA,cAAA,CAA2C,gBAAgB;EACjE,MAAM,wBAAwBA,qBAAAA,YAAY,OAAO,SAAS,aAAa;EACvE,MAAM,aAAa,MAAMA,qBAAAA,YAAY,cAAc,uBAAuB,IAAI;EAC9E,MAAM,aAAa,MAAM,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,IAAI;EAC3D,MAAM,SAAmB,CAAC;EAC1B,KAAK,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AAC,CAAC,KAAK,IAAI;CAC5C,cAAa,WAAA,GAAA,iBAAA,OAAA,CAAgB,KAAK,CAAC,CAAC,KAAK,KAAK;CAC9C,oBAAoB,QAAQ,UAAU,eAAA,GAAA,iBAAA,OAAA,CAC7B,KAAK,IAAI,SAAS,QAAQ,CAAC,CAAC,CAAC,oBAAoB,SAAS;CAEnE,UAAUC,iBAAAA,KAAK;CAEf,YAAYA,iBAAAA,KAAK;CACjB,WAAWA,iBAAAA,KAAK;CAChB,WAAWA,iBAAAA,KAAK;CAChB,UAAUA,iBAAAA,KAAK;CAGf,MAAMA,iBAAAA;CAGN,IAAIA,iBAAAA;AACN;;;;AAKA,SAAgB,yBAAmE;CACjF,OAAO;EACL,eAAe;EACf;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ElementNotFoundError","locatorUtil","dateUtil","timingUtil","defaultWaitForOption","interactorUtil","TestEngine"],"sources":["../src/PlaywrightInteractor.ts","../src/createTestEngine.ts"],"sourcesContent":["import {\n BlurOption,\n BoundingRect,\n byCssSelector,\n ClickOption,\n CssProperty,\n dateUtil,\n defaultWaitForOption,\n ElementNotFoundError,\n EnterTextOption,\n FocusOption,\n HoverOption,\n Interactor,\n interactorUtil,\n locatorUtil,\n MouseEnterOption,\n MouseLeaveOption,\n MouseOutOption,\n MouseDownOption,\n MouseMoveOption,\n MouseUpOption,\n Optional,\n PartLocator,\n Point,\n PressKeyOption,\n timingUtil,\n WaitForOption,\n WaitUntilOption,\n} from '@atomic-testing/core';\nimport { Page } from '@playwright/test';\n\n/**\n * Implementation of the {@link Interactor} interface using Playwright.\n */\nexport class PlaywrightInteractor implements Interactor {\n /**\n * @param page - Playwright page instance used to drive the browser.\n */\n constructor(public readonly page: Page) {}\n\n /**\n * Run a Playwright mutation and normalize a \"locator matched nothing\" failure\n * into {@link ElementNotFoundError}, so a missing element throws the same error\n * class here as it does in `DOMInteractor`, regardless of environment (the\n * unified contract ratified in ADR-006).\n *\n * Playwright auto-waits for actionability and then throws its own\n * `TimeoutError`. We translate that to `ElementNotFoundError` ONLY when the\n * element genuinely does not exist (count 0) and otherwise rethrow the original\n * error — preserving Playwright's auto-wait for an element that exists but is\n * briefly not actionable (covered, disabled, animating). The trade-off is that\n * a truly-missing element waits out the page's action timeout before throwing;\n * bound it with `page.setDefaultTimeout` when fast failure matters.\n *\n * @param locator - Locator the mutation targets\n * @param action - Method name used in the error message (e.g. `'click'`)\n * @param run - The Playwright action to execute\n * @throws {ElementNotFoundError} If the action fails and the element is absent\n */\n private async runMutation<T>(locator: PartLocator, action: string, run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (e) {\n if ((await this.exists(locator)) === false) {\n throw new ElementNotFoundError(locator, action);\n }\n throw e;\n }\n }\n\n /**\n * Select the given option values on a `<select>` element.\n *\n * @param locator - Locator to the `<select>` element.\n * @param values - Values to select.\n * @throws {ElementNotFoundError} If the element is not found\n */\n async selectOptionValue(locator: PartLocator, values: string[]): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'selectOptionValue', () => this.page.locator(cssLocator).selectOption(values));\n }\n\n /**\n * Set the selected files on a `<input type=\"file\">` element.\n *\n * Playwright's native `setInputFiles` reads the given paths from disk and\n * populates the input's `FileList`, firing the change event — the only way to\n * fill a file input, whose value cannot be set programmatically.\n *\n * @param locator - Locator of the `<input type=\"file\">` element\n * @param files - One or more filesystem paths to upload\n * @throws {ElementNotFoundError} If the element is not found\n */\n async setInputFiles(locator: PartLocator, files: string | string[]): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'setInputFiles', () => this.page.locator(cssLocator).setInputFiles(files));\n }\n\n /**\n * Scroll the located element into view, no-op if already visible.\n *\n * Delegates to Playwright's `scrollIntoViewIfNeeded`, which performs a real\n * layout-aware scroll in the browser.\n *\n * @param locator - Locator of the element to scroll into view\n * @throws {ElementNotFoundError} If the element is not found\n */\n async scrollIntoView(locator: PartLocator): Promise<void> {\n const css = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'scrollIntoView', () => this.page.locator(css).scrollIntoViewIfNeeded());\n }\n\n /**\n * Scroll the located element by the given pixel delta.\n *\n * The scroll is performed by evaluating `el.scrollBy(dx, dy)` on the element\n * itself rather than `page.mouse.wheel`. A wheel event scrolls whatever sits\n * under the pointer and is non-deterministic across chromium/firefox/webkit,\n * whereas evaluating `scrollBy` on the resolved element scrolls exactly that\n * element. This is a deliberate deviation from ADR 0001's per-engine table\n * (which lists `page.mouse.wheel`), taking the alternative the step-5 prompt\n * permits (\"or evaluate el.scrollBy\") for cross-browser determinism.\n *\n * @param locator - Locator of the scrollable element\n * @param delta - Pixel offset to scroll by\n * @throws {ElementNotFoundError} If the element is not found\n */\n async scrollBy(locator: PartLocator, delta: Point): Promise<void> {\n const css = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'scrollBy', () =>\n this.page.locator(css).evaluate((el, d) => el.scrollBy(d.x, d.y), { x: delta.x, y: delta.y })\n );\n }\n\n /**\n * Drag the source element and drop it onto the target element.\n *\n * Delegates to Playwright's native `Locator.dragTo`, which performs a real,\n * layout-aware drag gesture in the browser.\n *\n * @param source - Locator of the element to drag\n * @param target - Locator of the drop target\n * @throws {ElementNotFoundError} If either the source or target is not found\n */\n async dragTo(source: PartLocator, target: PartLocator): Promise<void> {\n const srcCss = await locatorUtil.toCssSelector(source, this);\n const tgtCss = await locatorUtil.toCssSelector(target, this);\n try {\n await this.page.locator(srcCss).dragTo(this.page.locator(tgtCss));\n } catch (e) {\n if ((await this.exists(source)) === false) {\n throw new ElementNotFoundError(source, 'dragTo');\n }\n if ((await this.exists(target)) === false) {\n throw new ElementNotFoundError(target, 'dragTo');\n }\n throw e;\n }\n }\n\n /**\n * Drag the located element by the given pixel delta from its center.\n *\n * The gesture is a single uninterrupted `move → down → move → up` sequence\n * computed from the element's center. It deliberately does NOT reuse\n * {@link mouseMove}/{@link mouseDown} — `mouseMove` resets the pointer with\n * `page.mouse.move(0, 0)` after hovering, which would corrupt the drag path\n * (see ADR 0001, option 5). The center comes from {@link getBoundingRect},\n * which throws `ElementNotFoundError` when the element has no box, so this\n * shares that \"element not found\" contract instead of re-deriving the box +\n * guard here.\n *\n * @param locator - Locator of the element to drag\n * @param delta - Pixel offset to drag by\n * @throws {ElementNotFoundError} If the element has no bounding box\n */\n async drag(locator: PartLocator, delta: Point): Promise<void> {\n const rect = await this.getBoundingRect(locator);\n const cx = rect.x + rect.width / 2;\n const cy = rect.y + rect.height / 2;\n await this.page.mouse.move(cx, cy);\n await this.page.mouse.down();\n await this.page.mouse.move(cx + delta.x, cy + delta.y, { steps: 8 });\n await this.page.mouse.up();\n }\n\n /**\n * Get the value of an `<input>` element.\n *\n * @param locator - Locator pointing to the input element.\n * @returns The current value of the input or `undefined` if not present.\n */\n async getInputValue(locator: PartLocator): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n return this.page.locator(cssLocator).inputValue();\n }\n\n /**\n * Retrieve the values of selected options within a `<select>` element.\n *\n * @param locator - Locator to the `<select>` element.\n * @returns Array of selected option values or `undefined` when no option is selected.\n */\n async getSelectValues(locator: PartLocator): Promise<Optional<readonly string[]>> {\n const optionLocator: PartLocator = byCssSelector('option:checked');\n const selectedOptionLocator = locatorUtil.append(locator, optionLocator);\n const cssLocator = await locatorUtil.toCssSelector(selectedOptionLocator, this);\n const allOptions = await this.page.locator(cssLocator).all();\n const values: string[] = [];\n for (const option of allOptions) {\n const value = await option.getAttribute('value');\n if (value != null) {\n values.push(value);\n }\n }\n return values;\n }\n\n async getSelectLabels(locator: PartLocator): Promise<Optional<readonly string[]>> {\n const optionLocator: PartLocator = byCssSelector('option:checked');\n const selectedOptionLocator = locatorUtil.append(locator, optionLocator);\n const cssLocator = await locatorUtil.toCssSelector(selectedOptionLocator, this);\n const allOptions = await this.page.locator(cssLocator).all();\n const labels: string[] = [];\n for (const option of allOptions) {\n const label = await option.textContent();\n if (label != null) {\n labels.push(label);\n }\n }\n return labels;\n }\n\n async getStyleValue(locator: PartLocator, propertyName: CssProperty): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const elLocator = this.page.locator(cssLocator);\n const value = await elLocator.evaluate((element, prop) => {\n return window.getComputedStyle(element).getPropertyValue(prop as string);\n }, propertyName);\n return value;\n }\n\n async enterText(locator: PartLocator, text: string, option?: Optional<Partial<EnterTextOption>>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'enterText', async () => {\n if (!option?.append) {\n await this.page.locator(cssLocator).clear();\n }\n\n // If it is a date, time or datetime-local input, validate the date format\n const type = (await this.getAttribute(locator, 'type')) ?? '';\n if (dateUtil.isHtmlDateInputType(type)) {\n const result = dateUtil.validateHtmlDateInput(type, text);\n if (!result.valid) {\n throw new Error(\n `Invalid date format for type: ${type}, expected format: ${result.format}, example: ${result.example}`\n );\n }\n }\n await this.page.locator(cssLocator).fill(text);\n });\n }\n\n async setRangeValue(locator: PartLocator, value: number): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // Playwright's `fill` rejects `<input type=\"range\">` (it is not a fillable\n // text control), so set the value in-page through the native value setter.\n // Calling the prototype setter both sanitizes the value to the input's step\n // (the browser snaps an off-step target to the nearest valid step) and lets\n // React's value tracker observe the change; the dispatched input/change\n // events then drive a controlled component (e.g. MUI Slider) to re-render.\n await this.runMutation(locator, 'setRangeValue', () =>\n this.page.locator(cssLocator).evaluate((el, nextValue) => {\n const input = el as HTMLInputElement;\n const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;\n setter?.call(input, nextValue);\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, String(value))\n );\n }\n\n async click(locator: PartLocator, option?: Partial<ClickOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'click', () => this.page.locator(cssLocator).click({ position: option?.position }));\n }\n\n /**\n * Dispatch a right-click on the located element to open its context menu.\n *\n * Delegates to Playwright's native right-button click, which fires a real\n * `contextmenu` event in the browser.\n *\n * @param locator - Locator of the element to right-click\n * @throws {ElementNotFoundError} If the element is not found\n */\n async contextMenu(locator: PartLocator): Promise<void> {\n const css = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'contextMenu', () => this.page.locator(css).click({ button: 'right' }));\n }\n\n async hover(locator: PartLocator, option?: Partial<HoverOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'hover', () => this.page.locator(cssLocator).hover({ position: option?.position }));\n }\n\n async mouseMove(locator: PartLocator, option?: Partial<MouseMoveOption>): Promise<void> {\n await this.runMutation(locator, 'mouseMove', async () => {\n await this.hover(locator, { position: option?.position });\n await this.page.mouse.move(0, 0);\n });\n }\n\n async mouseDown(locator: PartLocator, option?: Partial<MouseDownOption>): Promise<void> {\n await this.runMutation(locator, 'mouseDown', async () => {\n await this.hover(locator, { position: option?.position });\n await this.page.mouse.down();\n });\n }\n\n async mouseUp(locator: PartLocator, option?: Partial<MouseUpOption>): Promise<void> {\n await this.runMutation(locator, 'mouseUp', async () => {\n await this.hover(locator, { position: option?.position });\n await this.page.mouse.up();\n });\n }\n\n async mouseOver(locator: PartLocator, option?: Partial<HoverOption>): Promise<void> {\n await this.runMutation(locator, 'mouseOver', () => this.hover(locator, option));\n }\n\n async mouseOut(locator: PartLocator, _option?: Partial<MouseOutOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'mouseOut', async () => {\n // First hover over the element to trigger mouseenter/mouseover\n await this.page.locator(cssLocator).hover();\n // Then dispatch mouseout event directly for cross-browser reliability\n await this.page.locator(cssLocator).dispatchEvent('mouseout');\n });\n }\n\n async mouseEnter(locator: PartLocator, _option?: Partial<MouseEnterOption>): Promise<void> {\n await this.runMutation(locator, 'mouseEnter', () => this.hover(locator));\n }\n\n async mouseLeave(locator: PartLocator, _option?: Partial<MouseLeaveOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'mouseLeave', async () => {\n // First hover over the element to trigger mouseenter/mouseover\n await this.page.locator(cssLocator).hover();\n // Dispatch mouseout which triggers both mouseout and mouseleave handlers in React\n await this.page.locator(cssLocator).dispatchEvent('mouseout');\n });\n }\n\n async focus(locator: PartLocator, _option?: Partial<FocusOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'focus', () => this.page.focus(cssLocator));\n }\n\n async blur(locator: PartLocator, _option?: Partial<BlurOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n await this.runMutation(locator, 'blur', () => this.page.locator(cssLocator).blur());\n }\n\n async pressKey(locator: PartLocator, key: string, option?: Partial<PressKeyOption>): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // Compose Playwright's chord syntax — modifiers joined to the key by `+`, in\n // Playwright's accepted Control+Alt+Shift+Meta order — so the browser holds\n // those modifiers across the keypress and the event carries ctrlKey/etc.\n const modifiers: string[] = [];\n if (option?.ctrl) {\n modifiers.push('Control');\n }\n if (option?.alt) {\n modifiers.push('Alt');\n }\n if (option?.shift) {\n modifiers.push('Shift');\n }\n if (option?.meta) {\n modifiers.push('Meta');\n }\n const chord = modifiers.length > 0 ? `${modifiers.join('+')}+${key}` : key;\n // locator.press auto-focuses the element, then dispatches a real, trusted\n // KeyboardEvent — the browser equivalent of the DOM focus-first keyDown/keyUp.\n // Caveat: for Shift + a printable key the browser case-folds `event.key`\n // (`Shift+a` → `'A'`) whereas the jsdom path keeps `'a'` — only the modifier\n // flags are delivered identically across engines (see #924).\n await this.runMutation(locator, 'pressKey', () => this.page.locator(cssLocator).press(chord));\n }\n\n async activate(locator: PartLocator): Promise<void> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n // Geometry-free activation mirrors the mouseout dispatch precedent above: it\n // bypasses hit-testing to actuate a covered or zero-size input that\n // locator.click() (a real geometry hit-test) cannot reach.\n await this.runMutation(locator, 'activate', () => this.page.locator(cssLocator).dispatchEvent('click'));\n }\n\n //#region wait conditions\n wait(ms: number): Promise<void> {\n return timingUtil.wait(ms);\n }\n\n async waitUntilComponentState(\n locator: PartLocator,\n option: Partial<Readonly<WaitForOption>> = defaultWaitForOption\n ): Promise<void> {\n return interactorUtil.interactorWaitUtil(locator, this, option);\n }\n\n waitUntil<T>(option: WaitUntilOption<T>): Promise<T> {\n return timingUtil.waitUntil(option);\n }\n //#endregion\n\n async getAttribute(locator: PartLocator, name: string, isMultiple: true): Promise<readonly string[]>;\n async getAttribute(locator: PartLocator, name: string, isMultiple: false): Promise<Optional<string>>;\n async getAttribute(locator: PartLocator, name: string): Promise<Optional<string>>;\n async getAttribute(\n locator: PartLocator,\n name: string,\n isMultiple?: boolean\n ): Promise<Optional<string> | readonly string[]> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const elLocator = this.page.locator(cssLocator);\n if (isMultiple) {\n const locators = await elLocator.all();\n const values: string[] = [];\n for (const locator of locators) {\n const value = await locator.getAttribute(name);\n if (value != null) {\n values.push(value);\n }\n }\n return values;\n }\n const value = await elLocator.getAttribute(name);\n return value ?? undefined;\n }\n\n async getText(locator: PartLocator): Promise<Optional<string>> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const text = await this.page.locator(cssLocator).textContent();\n return text ?? undefined;\n }\n\n /**\n * Get the located element's bounding rectangle.\n *\n * `boundingBox()` returns `null` for a detached/invisible element rather than\n * auto-waiting, so this throws `ElementNotFoundError` directly (no auto-wait)\n * — matching the unified \"element not found\" contract (ADR-006).\n *\n * @param locator - Locator of the element to measure\n * @returns The element's bounding rectangle in CSS pixels\n * @throws {ElementNotFoundError} If the element has no bounding box\n */\n async getBoundingRect(locator: PartLocator): Promise<BoundingRect> {\n const css = await locatorUtil.toCssSelector(locator, this);\n const box = await this.page.locator(css).boundingBox();\n if (box == null) {\n throw new ElementNotFoundError(locator, 'getBoundingRect');\n }\n return { x: box.x, y: box.y, width: box.width, height: box.height };\n }\n\n async exists(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const count = await this.page.locator(cssLocator).count();\n return count > 0;\n }\n\n async isChecked(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const checked = await this.page.locator(cssLocator).isChecked();\n return checked;\n }\n\n async isDisabled(locator: PartLocator): Promise<boolean> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n const isDisabled = await this.page.locator(cssLocator).isDisabled();\n return isDisabled;\n }\n\n async isReadonly(locator: PartLocator): Promise<boolean> {\n const readonly = await this.getAttribute(locator, 'readonly');\n return readonly != null;\n }\n\n async isVisible(locator: PartLocator): Promise<boolean> {\n const exists = await this.exists(locator);\n if (!exists) {\n return false;\n }\n\n async function checkCssVisibility(\n prop: CssProperty,\n invisibleValue: string,\n interactor: PlaywrightInteractor\n ): Promise<boolean> {\n try {\n const value = await interactor.getStyleValue(locator, prop);\n return value !== invisibleValue;\n } catch (e) {\n // Element may disappear or detached while being checked because of animation\n // when it happens, an error is thrown. In this case, if indeed the element\n // is not visible, we return false. Otherwise, we re-throw the error.\n if ((await interactor.exists(locator)) === false) {\n return false;\n }\n throw e;\n }\n }\n\n if ((await checkCssVisibility('opacity', '0', this)) === false) {\n return false;\n }\n\n if ((await checkCssVisibility('visibility', 'hidden', this)) === false) {\n return false;\n }\n\n if ((await checkCssVisibility('display', 'none', this)) === false) {\n return false;\n }\n\n return true;\n }\n\n async hasCssClass(locator: PartLocator, className: string): Promise<boolean> {\n const classNames = await this.getAttribute(locator, 'class');\n if (classNames == null) {\n return false;\n }\n\n const names = classNames.split(/\\s+/);\n return names.includes(className);\n }\n\n async hasAttribute(locator: PartLocator, name: string): Promise<boolean> {\n const attrValue = await this.getAttribute(locator, name);\n return attrValue != null;\n }\n\n //#region\n async innerHTML(locator: PartLocator): Promise<string> {\n const cssLocator = await locatorUtil.toCssSelector(locator, this);\n return this.page.locator(cssLocator).innerHTML();\n }\n //#endregion\n\n clone(): Interactor {\n return new PlaywrightInteractor(this.page);\n }\n}\n","import { ScenePart, TestEngine } from '@atomic-testing/core';\nimport { Page } from '@playwright/test';\n\nimport { PlaywrightInteractor } from './PlaywrightInteractor';\n\n/**\n * Create a {@link TestEngine} instance backed by Playwright.\n *\n * @param page - Playwright page used for interaction.\n * @param partDefinitions - Scene part definitions describing the scene\n * structure for the engine.\n * @returns A configured {@link TestEngine} ready for use.\n */\nexport function createTestEngine<T extends ScenePart>(page: Page, partDefinitions: T): TestEngine<T> {\n const engine = new TestEngine([], new PlaywrightInteractor(page), {\n parts: partDefinitions,\n });\n\n return engine;\n}\n"],"mappings":";;;;;;AAkCA,IAAa,uBAAb,MAAa,qBAA2C;;;;CAItD,YAAY,MAA4B;EAAZ,KAAA,OAAA;CAAa;;;;;;;;;;;;;;;;;;;;CAqBzC,MAAc,YAAe,SAAsB,QAAgB,KAAmC;EACpG,IAAI;GACF,OAAO,MAAM,IAAI;EACnB,SAAS,GAAG;GACV,IAAK,MAAM,KAAK,OAAO,OAAO,MAAO,OACnC,MAAM,IAAIA,qBAAAA,qBAAqB,SAAS,MAAM;GAEhD,MAAM;EACR;CACF;;;;;;;;CASA,MAAM,kBAAkB,SAAsB,QAAiC;EAC7E,MAAM,aAAa,MAAMC,qBAAAA,YAAY,cAAc,SAAS,IAAI;EAChE,MAAM,KAAK,YAAY,SAAS,2BAA2B,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,aAAa,MAAM,CAAC;CAC/G;;;;;;;;;;;;CAaA,MAAM,cAAc,SAAsB,OAAyC;EACjF,MAAM,aAAa,MAAMA,qBAAAA,YAAY,cAAc,SAAS,IAAI;EAChE,MAAM,KAAK,YAAY,SAAS,uBAAuB,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,cAAc,KAA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