Snapshot testing
ARIA snapshots capture the accessibility tree of a page as YAML and compare it on re-run. Unlike HTML snapshots, they survive CSS/class refactors — they only break when the meaningful structure changes.
What gets captured
An ARIA snapshot is not HTML. It's the accessibility tree — the same view a screen reader sees. It captures roles, accessible names, and attributes like checked, expanded, disabled. Implementation details like CSS classes, data attributes, or HTML tags don't appear.
This is the key advantage: a developer can rewrite the component's internals, change the markup, rename classes — the snapshot won't break unless the component's accessible structure actually changes.
Write and match a snapshot
The template is a YAML-like string where each line is - role "accessible name". You can match the whole page with expect(page).toMatchAriaSnapshot() or scope to a specific element with a locator.
Partial matching — check what matters
By default, a snapshot template matches a subset — you don't need to list every element. Only what you put in the template is checked. If the page has 20 nav links but you only care that the Orders link exists, include just that one.
You can also omit the accessible name to match any element with that role, or use regex for dynamic text.
Strict children — exact list
When you need to assert that the element has EXACTLY these children and no others, add /children: equal to the template. This is useful for navigation menus, action toolbars, or select options where unexpected extra items are a bug.
Auto-generate snapshot templates
You don't have to write snapshot templates by hand. Two ways to generate them: run with --update-snapshots flag (updates in-test inline strings), or use the VS Code extension's "Update snapshot" button next to a failing test.
On the first run when there's no existing snapshot, Playwright auto-generates it and the test passes. After that, any deviation fails the test until you explicitly update.