@surea11y/playwright 1.4.1 → 1.4.2
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 +45 -6
- package/package.json +2 -2
- package/src/A11yCoreBuilder.d.ts +39 -3
- package/src/A11yCoreBuilder.js +58 -2
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ A Playwright binding for [`@surea11y/core`](https://github.com/SureA11y/core)
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @surea11y/playwright playwright
|
|
8
|
+
npm install @surea11y/core @surea11y/playwright playwright
|
|
9
9
|
npx playwright install chromium # every test launches a real browser -- npm install alone doesn't fetch it
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
`@surea11y/core` 1.12.0 or later, the engine, comes with
|
|
12
|
+
`@surea11y/core` 1.12.0 or later, the engine, comes with the binding as a regular dependency, so a project that doesn't list it still works. List it in your own `package.json` too, as the line above does: your project and the binding then share one copy, so whatever you do with core directly, writing a SARIF log or an HTML report (`@surea11y/core/sarif`, `/report`), reading the rule catalogue or keeping a baseline, reads results with the same core that produced them. When your core can't match the binding's range, as with a linked checkout (`file:../core`) or a fork, add `"overrides": { "@surea11y/core": "$@surea11y/core" }` beside it.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
**Coming in 2.0:** core becomes a peer dependency, so the binding will no longer install it for you, and the `overrides` entry is no longer needed. Add `@surea11y/core` to your `package.json` now and 2.0 needs no change.
|
|
15
15
|
|
|
16
16
|
`npm test` (in this repo) only needs Chromium. The cross-browser regression tests in `tests/cross-browser.test.js` (proving this works against Firefox/WebKit too, not just Chromium) additionally need `npx playwright install firefox webkit`. `npm test` also compiles `tests/types/usage.ts` with TypeScript against the shipped types (`typescript` is a dev dependency only).
|
|
17
17
|
|
|
@@ -84,7 +84,7 @@ The four take a string or an array of strings. `undefined` (a missing config val
|
|
|
84
84
|
|
|
85
85
|
`.exclude(selector)` above excludes globally. Pass a second argument to scope it to specific rule IDs instead: `.exclude('.mat-select', { rules: ['aria-required-children'] })` skips `.mat-select` for that rule only — every other rule still sees it. Global and rule-scoped `.exclude()` calls compose freely.
|
|
86
86
|
|
|
87
|
-
**Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()`/`withPacks()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()`/`.withWcag()`/`.withBestPractices()`/`.includeMode()`/`.wcagLevel()`/`.logger()` are the exception: each call replaces the previous value instead of merging with it.
|
|
87
|
+
**Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()`/`withPacks()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()`/`.screenshots()`/`.withWcag()`/`.withBestPractices()`/`.includeMode()`/`.wcagLevel()`/`.logger()` are the exception: each call replaces the previous value instead of merging with it.
|
|
88
88
|
|
|
89
89
|
### When `.include()` matches nothing, or doesn't parse
|
|
90
90
|
|
|
@@ -243,6 +243,37 @@ This resolves each occurrence to an `ElementHandle` in its own frame instead of
|
|
|
243
243
|
|
|
244
244
|
Each `ElementHandle` holds a browser-side reference until garbage collected or explicitly disposed — for a scan with many violations that you're keeping around a while (rather than using immediately, as above), call `occurrence.elementHandle.dispose()` when you're done with it, per [Playwright's own `ElementHandle` guidance](https://playwright.dev/docs/api/class-elementhandle).
|
|
245
245
|
|
|
246
|
+
### A picture of each failing element
|
|
247
|
+
|
|
248
|
+
Opt in with `.screenshots()`, and each occurrence the scan flags gets a `screenshot` field: a picture of the element, with a box drawn around it, or the reason there is none.
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
const results = await new A11yCoreBuilder({ page })
|
|
252
|
+
.screenshots({ dir: 'a11y-shots', padding: 16 })
|
|
253
|
+
.analyze();
|
|
254
|
+
|
|
255
|
+
const [first] = results.checksResults.filter((r) => r.outcome === 'fail');
|
|
256
|
+
first.occurrences[0].screenshot;
|
|
257
|
+
// { path: 'a11y-shots/element-3f9a1c07.png', box: { x: 20, y: 20, width: 120, height: 40 } }
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
| Option | Default | |
|
|
261
|
+
|---|---|---|
|
|
262
|
+
| `dir` | none | Write each picture there. Without it, each comes back as `{ buffer, box }`, a PNG for you to store your own way. |
|
|
263
|
+
| `outcomes` | `['fail']` | Which occurrences to picture. For contrast, `['fail', 'cantTell']` shows the background the engine couldn't judge. |
|
|
264
|
+
| `padding` | `0` | CSS pixels of context around the element. |
|
|
265
|
+
| `highlight` | `true` | Draw a box around the element, over the page; the element itself is never restyled. |
|
|
266
|
+
| `max` | `50` | At most this many pictures per scan, frames included. |
|
|
267
|
+
|
|
268
|
+
- **One picture per element.** Several rules can flag the same element; it's pictured once, and each of their occurrences carries the same `screenshot`. A file is named after where the element is, so it keeps its name from run to run, and `formatFailures()` names it under each finding (` screenshot: a11y-shots/element-3f9a1c07.png`).
|
|
269
|
+
- **`box`** is where the element shows in the picture, in CSS pixels; the PNG is larger by the device pixel ratio. `cropped: true` says only part of it shows, as for an element taller than the viewport, which is pictured from its top-left corner.
|
|
270
|
+
- **No picture, and why**: `{ skipped }` with `'no-element'` (no selector, or nothing matches it any more), `'page-level'` (a finding about the whole page, on `<html>`, `<head>` or `<body>`), `'not-rendered'` (such as `display: none`), `'zero-size'`, `'off-screen'` (such as `left: -9999px`), `'max-reached'`, or `'capture-failed'` with the browser's `error`. A failed picture never fails the scan.
|
|
271
|
+
- **The page is put back.** Each element is scrolled into view for its picture, and afterwards every scroll position is restored and the box removed, also when a picture fails. Something drawn over the element, such as a sticky header, shows as it does on screen.
|
|
272
|
+
- **Frames.** With `.frames(true)`, an element in an `<iframe>`, cross-origin ones included, is pictured on the page as it shows there.
|
|
273
|
+
- **Off by default.** Pictures of real pages can hold personal data, and they end up as CI artifacts.
|
|
274
|
+
|
|
275
|
+
The pictures are taken right after each frame's scan, before `.reportOnly()` trims the result, and combine with `.elementRef(true)`. Focus, hover, animations or content that loads late can still differ from what the scan saw. An option it can't use throws a `TypeError` with `code: 'INVALID_ENGINE_OPTIONS'` at the call, and so does `.analyze()` with `options({ output: { includeSelector: false } })`, since each element is found by its selector. Works in Chromium, Firefox and WebKit.
|
|
276
|
+
|
|
246
277
|
### Web components: the internals hook
|
|
247
278
|
|
|
248
279
|
Many web components keep their `ElementInternals` in a private field and name themselves, set their states or give themselves a role through it:
|
|
@@ -347,6 +378,14 @@ results.engine.profile; // 'en301549-v4.1.1'
|
|
|
347
378
|
|
|
348
379
|
A pack brings rules, variants of core's rules, a standard or a checklist, and their profiles and messages, from a package of its own: a national standard such as RGAA, or your organisation's accessibility policy. `@surea11y/core` runs a pack as it runs its own rules and standards, so its results, rollups and report entries look like core's. Packs need `@surea11y/core` 1.11.1 or later.
|
|
349
380
|
|
|
381
|
+
Install a published pack in your project, beside core and this package:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
npm install @surea11y/core @surea11y/playwright playwright @acme/a11y-policy
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Your project, this package and the pack then share one copy of core, so the core that checks the pack is the one that runs it. With two copies, a scan can skip the pack (see "When a pack doesn't run" below).
|
|
388
|
+
|
|
350
389
|
`.withPacks()` registers packs in the page, and in every frame with `.frames(true)`, before the scan; a pack's profile is chosen with `.options({ profile })`:
|
|
351
390
|
|
|
352
391
|
```js
|
|
@@ -368,7 +407,7 @@ A pack's own rules appear in `checksResults` like core's, with ids that start wi
|
|
|
368
407
|
|
|
369
408
|
**Writing a pack.** A pack is an object made with `definePack` from `@surea11y/core/pack`. [`examples/acme-policy-pack.js`](./examples/acme-policy-pack.js) is a small one: a house rule, a checklist profile (WCAG 2.2 A and AA, `region`, and the house rule) and two checklist items. `npm run example:pack` scans a page with it, and [`examples/playwright-test-example.spec.js`](./examples/playwright-test-example.spec.js) uses it as a test gate. For a pack of your own, `npx surea11y-pack new <folder>` (from `@surea11y/core`) writes a package that works as generated, with its tests, docs and lint; core's [`PACKS.md`](https://github.com/SureA11y/core/blob/main/docs/PACKS.md) is the guide.
|
|
370
409
|
|
|
371
|
-
**When a pack doesn't run.** `.withPacks()` builds the page's script with the `@surea11y/core` this binding loads, and checks each pack as it does: `.analyze()` throws before scanning for a pack that core can't run, such as one whose `core` range leaves out the installed core, or whose profile names a rule that doesn't exist. A pack the page then doesn't run (one named with a raw `.options({ packs })` and never registered, or a page running another core version, when two copies of core are installed) is listed in `results.skippedPacks` with the reason. `getScanGaps()` reports that as `'pack-skipped'`, and `.analyze()` warns about it, so a test gate that asserts on `getScanGaps(results)` fails rather than passing with the pack's checks never run.
|
|
410
|
+
**When a pack doesn't run.** `.withPacks()` builds the page's script with the `@surea11y/core` this binding loads, and checks each pack as it does: `.analyze()` throws before scanning for a pack that core can't run, such as one whose `core` range leaves out the installed core, or whose profile names a rule that doesn't exist. A pack the page then doesn't run (one named with a raw `.options({ packs })` and never registered, or a page running another core version, when two copies of core are installed) is listed in `results.skippedPacks` with the reason. `getScanGaps()` reports that as `'pack-skipped'`, and `.analyze()` warns about it, so a test gate that asserts on `getScanGaps(results)` fails rather than passing with the pack's checks never run.
|
|
372
411
|
|
|
373
412
|
### Element addressing beyond a CSS selector
|
|
374
413
|
|
|
@@ -376,7 +415,7 @@ Every occurrence already carries `selector` and (with `.elementRef(true)`, above
|
|
|
376
415
|
|
|
377
416
|
## TypeScript
|
|
378
417
|
|
|
379
|
-
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle` and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap`, `getScanNotes()`/`ScanNote` and `formatOccurrenceLocation()` are typed too, and so are `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`), the static `installInternalsHook()`,
|
|
418
|
+
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle`, `screenshot` (`OccurrenceScreenshot`) and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap`, `getScanNotes()`/`ScanNote` and `formatOccurrenceLocation()` are typed too, and so are `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`), the static `installInternalsHook()`, `withPacks()`, which takes a pack made with `definePack` (`PackLike`), and `.screenshots()` (`ScreenshotOptions`). Code that handles every `ScanGap` kind it knows and treats the rest in an `else` branch needs a branch for `'pack-skipped'`, which carries `pack` rather than `selectors`. `analyze()` is typed `Promise<A11yCoreResult | A11yCoreMultiFrameResult>` — narrow on `'topFrame' in results` (or cast, if you already know which mode you called) to get the specific shape back, since a fluent builder can't statically track that `.frames(true)` was called earlier in the chain. `playwright` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `playwright` install for the types to resolve, same as they already do to construct a `Page` in the first place.
|
|
380
419
|
|
|
381
420
|
## What changes with `@surea11y/core` 1.12
|
|
382
421
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surea11y/playwright",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Accessibility (a11y, WCAG) checks for Playwright tests: scan the live page with new A11yCoreBuilder({ page }).analyze() and get only proven violations, with findings that need human review listed separately.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"LICENSE"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@surea11y/binding-base": "^1.
|
|
49
|
+
"@surea11y/binding-base": "^1.5.0",
|
|
50
50
|
"@surea11y/core": "^1.12.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
package/src/A11yCoreBuilder.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type * as Core from '@surea11y/core';
|
|
|
5
5
|
// 1.9.0, and checked there against real scan results), so they follow the
|
|
6
6
|
// engine instead of a copy of its docs. This file only adds what the
|
|
7
7
|
// binding puts on top: `elementHandle` on an occurrence with
|
|
8
|
-
// .elementRef(true),
|
|
8
|
+
// .elementRef(true), `screenshot` with .screenshots(), and the
|
|
9
|
+
// { topFrame, frames } shape of .frames(true).
|
|
9
10
|
// Every name this file exported before is still exported.
|
|
10
11
|
|
|
11
12
|
import type {
|
|
@@ -55,8 +56,30 @@ export type {
|
|
|
55
56
|
* page's scripts broke a JavaScript built-in the engine relies on).
|
|
56
57
|
*/
|
|
57
58
|
export { EngineError } from '@surea11y/binding-base';
|
|
58
|
-
export type {
|
|
59
|
-
|
|
59
|
+
export type {
|
|
60
|
+
EngineErrorCode,
|
|
61
|
+
PackLike,
|
|
62
|
+
WcagVersion,
|
|
63
|
+
WcagLevel,
|
|
64
|
+
WcagLevelInput,
|
|
65
|
+
PlannedCheck,
|
|
66
|
+
PlannedCriterion,
|
|
67
|
+
ScreenshotOptions,
|
|
68
|
+
ScreenshotSkip,
|
|
69
|
+
ScreenshotBox,
|
|
70
|
+
OccurrenceScreenshot
|
|
71
|
+
} from '@surea11y/binding-base';
|
|
72
|
+
import type {
|
|
73
|
+
PackLike,
|
|
74
|
+
WcagVersion,
|
|
75
|
+
WcagLevelInput,
|
|
76
|
+
ScanGap,
|
|
77
|
+
ScanNote,
|
|
78
|
+
PlannedCheck,
|
|
79
|
+
PlannedCriterion,
|
|
80
|
+
ScreenshotOptions,
|
|
81
|
+
OccurrenceScreenshot
|
|
82
|
+
} from '@surea11y/binding-base';
|
|
60
83
|
|
|
61
84
|
export type Category = Core.RuleMeta['category'];
|
|
62
85
|
export type LocaleResolutionReason = Core.LocaleResolution['reason'];
|
|
@@ -70,6 +93,12 @@ export interface Occurrence extends Core.Occurrence {
|
|
|
70
93
|
* `""`, or a shadow host on the way is gone) -- see A11yCoreBuilder#elementRef.
|
|
71
94
|
*/
|
|
72
95
|
elementHandle?: ElementHandle | null;
|
|
96
|
+
/**
|
|
97
|
+
* Only present when `.screenshots()` was used and this occurrence's own
|
|
98
|
+
* outcome is one it pictures: the picture, or why there is none. The
|
|
99
|
+
* occurrences about the same element share one object.
|
|
100
|
+
*/
|
|
101
|
+
screenshot?: OccurrenceScreenshot;
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
export interface CheckResult extends Omit<Core.CheckResult, 'occurrences'> {
|
|
@@ -192,6 +221,13 @@ export class A11yCoreBuilder {
|
|
|
192
221
|
frames(enabled?: boolean): this;
|
|
193
222
|
/** Opt in to resolving each fail/cantTell occurrence's selector to a live ElementHandle. */
|
|
194
223
|
elementRef(enabled?: boolean): this;
|
|
224
|
+
/**
|
|
225
|
+
* Opt in to a picture of each element the scan flags, on its occurrences'
|
|
226
|
+
* `screenshot` field: a Buffer, or a file in `dir`. `false` turns them
|
|
227
|
+
* off. Throws a TypeError with code 'INVALID_ENGINE_OPTIONS' for an option
|
|
228
|
+
* it can't use.
|
|
229
|
+
*/
|
|
230
|
+
screenshots(options?: ScreenshotOptions | boolean): this;
|
|
195
231
|
/** The rules this scan will run, worked out in Node with no page (@surea11y/core 1.12.0 and later). */
|
|
196
232
|
plannedChecks(): PlannedCheck[];
|
|
197
233
|
/** The criteria this scan will report in rulesResults, worked out in Node with no page. */
|
package/src/A11yCoreBuilder.js
CHANGED
|
@@ -114,6 +114,19 @@ const findOccurrenceElement = eval(`(args) => {
|
|
|
114
114
|
* const [firstFail] = results.checksResults.filter(r => r.outcome === 'fail');
|
|
115
115
|
* await firstFail.occurrences[0].elementHandle.screenshot({ path: 'flagged.png' });
|
|
116
116
|
*
|
|
117
|
+
* Or let the scan take a picture of each element it flags, with
|
|
118
|
+
* `.screenshots()` (@surea11y/binding-base's, see its README): each
|
|
119
|
+
* occurrence gets a `screenshot` field, the picture (a Buffer, or a file in
|
|
120
|
+
* `dir`) or why there is none. The element is scrolled into view and marked
|
|
121
|
+
* with a box drawn over the page, and the page is put back afterwards; in
|
|
122
|
+
* every frame with `.frames(true)`, including cross-origin ones:
|
|
123
|
+
*
|
|
124
|
+
* const results = await new A11yCoreBuilder({ page })
|
|
125
|
+
* .screenshots({ dir: 'a11y-shots', padding: 16 })
|
|
126
|
+
* .analyze();
|
|
127
|
+
* // results.checksResults[i].occurrences[j].screenshot
|
|
128
|
+
* // -> { path: 'a11y-shots/element-3f9a1c07.png', box: { x, y, width, height } }
|
|
129
|
+
*
|
|
117
130
|
* Register your own rule(s) for just this scan with
|
|
118
131
|
* `.withCustomRules([...])` (@surea11y/core's `engineOptions.customRules`
|
|
119
132
|
* escape hatch -- see ../core/docs/ENGINE_OPTIONS.md). Pass a real,
|
|
@@ -142,8 +155,8 @@ const findOccurrenceElement = eval(`(args) => {
|
|
|
142
155
|
* top of the first scan's scope rather than replacing it (intentional for
|
|
143
156
|
* "call include() several times for one scan" -- see above -- but a footgun
|
|
144
157
|
* if you hold one instance across multiple assertions).
|
|
145
|
-
* reportOnly()/frames()/elementRef() are the exception: each
|
|
146
|
-
* the previous value rather than merging with it.
|
|
158
|
+
* reportOnly()/frames()/elementRef()/screenshots() are the exception: each
|
|
159
|
+
* call replaces the previous value rather than merging with it.
|
|
147
160
|
*/
|
|
148
161
|
class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
149
162
|
/**
|
|
@@ -205,6 +218,9 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
205
218
|
runOnly
|
|
206
219
|
}));
|
|
207
220
|
this._warnScanGaps(result, '@surea11y/playwright');
|
|
221
|
+
// Right after the frame's scan, before reportOnly(): nothing unless
|
|
222
|
+
// .screenshots() was called.
|
|
223
|
+
if (this._screenshots) await this._screenshotFrame(frameOrPage, result);
|
|
208
224
|
return this._elementRef ? this._attachElementRefs(frameOrPage, result) : result;
|
|
209
225
|
};
|
|
210
226
|
|
|
@@ -266,6 +282,46 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
266
282
|
return result;
|
|
267
283
|
}
|
|
268
284
|
|
|
285
|
+
/**
|
|
286
|
+
* binding-base's screenshots step for one scanned frame (or the page),
|
|
287
|
+
* with the <iframe>s leading to it: each frame's frameElement(), a handle
|
|
288
|
+
* in its parent, disposed afterwards.
|
|
289
|
+
*/
|
|
290
|
+
async _screenshotFrame(frameOrPage, result) {
|
|
291
|
+
const framePath = [];
|
|
292
|
+
const parentOf = (f) => (typeof f.parentFrame === 'function' ? f.parentFrame() : null);
|
|
293
|
+
for (let f = frameOrPage; parentOf(f); f = parentOf(f)) {
|
|
294
|
+
// null when the frame detached after its scan: binding-base fails
|
|
295
|
+
// that frame's pictures.
|
|
296
|
+
const iframe = await f.frameElement().catch(() => null);
|
|
297
|
+
framePath.unshift({ frame: parentOf(f), iframe });
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
await this._captureScreenshots(result, frameOrPage, framePath);
|
|
301
|
+
} finally {
|
|
302
|
+
await Promise.all(framePath.map((step) => (step.iframe ? step.iframe.dispose().catch(() => {}) : null)));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* For binding-base's screenshots step: runs `fn(...args)` in the frame.
|
|
308
|
+
* Playwright's evaluate() takes one argument, so the arguments go as one
|
|
309
|
+
* array (an element handle inside it arrives as the element) and are
|
|
310
|
+
* spread in the page.
|
|
311
|
+
*/
|
|
312
|
+
_evaluateInFrame(frameOrPage, fn, args) {
|
|
313
|
+
// eslint-disable-next-line no-new-func
|
|
314
|
+
return frameOrPage.evaluate(new Function('args', 'return (' + fn.toString() + ')(...args)'), args);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* For binding-base's screenshots step: a PNG of `box`, CSS pixels in the
|
|
319
|
+
* viewport, which is what Playwright's clip is relative to.
|
|
320
|
+
*/
|
|
321
|
+
_captureBox(box) {
|
|
322
|
+
return this._page.screenshot({ clip: { x: box.x, y: box.y, width: box.width, height: box.height } });
|
|
323
|
+
}
|
|
324
|
+
|
|
269
325
|
async _findElement(frameOrPage, occurrence) {
|
|
270
326
|
const handle = await frameOrPage.evaluateHandle(findOccurrenceElement, {
|
|
271
327
|
selector: occurrence.selector,
|