docs: enhance documentation for toMatchAriaSnapshot usage and update snapshot options

This commit is contained in:
Debbie O'Brien 2025-01-28 07:54:33 +01:00
parent 8d869ec614
commit 0e336e505e
3 changed files with 7 additions and 9 deletions

View file

@ -2249,6 +2249,8 @@ Asserts that the target element matches the given [accessibility snapshot](../ar
```js
await expect(page.locator('body')).toMatchAriaSnapshot();
await expect(page.locator('body')).toMatchAriaSnapshot({ name: 'snapshot.yml' });
```
### option: LocatorAssertions.toMatchAriaSnapshot#2.name
@ -2259,12 +2261,6 @@ await expect(page.locator('body')).toMatchAriaSnapshot();
Name of the snapshot to store in the snapshot (screenshot) folder corresponding to this test.
Generates sequential names if not specified.
**Usage**
```js
await expect(page.locator('body')).toMatchAriaSnapshot({ name: 'snapshot.yml' });
```
### option: LocatorAssertions.toMatchAriaSnapshot#2.timeout = %%-js-assertions-timeout-%%
* since: v1.50

View file

@ -326,7 +326,7 @@ When updating snapshots, Playwright creates patch files that capture differences
applied, and committed to source control, allowing teams to track structural changes over time and ensure updates are
consistent with application requirements.
The source method for updating snapshots can be changed using the `--update-source-method` flag. There are several options available:
The way source code is updated can be changed using the `--update-source-method` flag. There are several options available:
- **"patch"** (default): Generates a unified diff file that can be applied to the source code using `git apply`.
- **"3way"**: Generates merge conflict markers in your source code, allowing you to choose whether to accept changes.
@ -347,7 +347,9 @@ await expect(page.getByRole('main')).toMatchAriaSnapshot({ name: 'main-snapshot.
By default, snapshots are saved in a directory next to your test file and a `.yml` file is created for each project specified in your Playwright configuration file. You can customize the snapshot path template using the `snapshotPathTemplate` option in the test runner configuration:
```js
snapshotPathTemplate: '__snapshots__/{testFilePath}/{arg}{ext}',
export default defineConfig({
snapshotPathTemplate: '__snapshots__/{testFilePath}/{arg}{ext}',
});
```
### 3. Using the `Locator.ariaSnapshot` method

View file

@ -385,7 +385,7 @@ const testOptions: [string, string][] = [
['--ui', `Run tests in interactive UI mode`],
['--ui-host <host>', 'Host to serve UI on; specifying this option opens UI in a browser tab'],
['--ui-port <port>', 'Port to serve UI on, 0 for any free port; specifying this option opens UI in a browser tab'],
['-u, --update-snapshots [mode]', `Update snapshots with actual results. Possible values are 'all', 'changed', 'missing' and 'none'. Not passing defaults to 'missing', passing without value defaults to 'changed'`],
['-u, --update-snapshots [mode]', `Update snapshots with actual results. Possible values are "all", "changed", "missing", and "none". Running tests without the flag defaults to "missing"; running tests with the flag but without a value defaults to "changed".`],
['--update-source-method <method>', `Chooses the way source is updated. Possible values are 'overwrite', '3way' and 'patch'. Defaults to 'patch'`],
['-j, --workers <workers>', `Number of concurrent workers or percentage of logical CPU cores, use 1 to run in a single worker (default: 50%)`],
['-x', `Stop after the first failure`],