ARIA snapshots let a Playwright test check the accessibility tree that browsers expose to assistive technology. They are useful when a page or component must keep the same roles, accessible names, landmarks, and heading structure while visual styling continues to change.
Playwright can compare the full page body or a scoped locator against a YAML snapshot. A scoped locator keeps the diff small enough to review when a heading, link, or button name changes.
Use ARIA snapshots for stable semantic regions rather than feeds, counters, or timestamps that change on every run. Pair them with ordinary Playwright assertions for exact behavior checks, because a snapshot can show that a button exists without proving the click flow works.
Related: How to run Playwright tests
Related: How to use Playwright role locators
Related: How to create Playwright visual baselines
$ cd ~/projects/playwright-demo
import { test, expect } from '@playwright/test';
test('home page exposes accessible structure', async ({ page }) => {
await page.setContent(`
<main>
<h1>Playwright fixture ready</h1>
<nav aria-label="Primary">
<a href="/docs">Docs</a>
</nav>
<button>Subscribe</button>
</main>
`);
await expect(page.locator('body')).toMatchAriaSnapshot(`
- main:
- heading "Playwright fixture ready" [level=1]
- navigation "Primary":
- link "Docs":
- /url: /docs
- button "Subscribe"
`);
});
The body locator keeps the assertion focused on the rendered semantic page structure. Use a smaller landmark or component locator when the application shell changes often.
$ npx playwright test tests/home.spec.ts --project=chromium --reporter=line Running 1 test using 1 worker [1/1] [chromium] › tests/home.spec.ts:3:5 › home page exposes accessible structure 1 passed (1.3s)
Leave the expected snapshot at button "Subscribe" so the next run proves the assertion fails on an accessible-name change.
$ npx playwright test tests/home.spec.ts --project=chromium --reporter=line
Running 1 test using 1 worker
[1/1] [chromium] › tests/home.spec.ts:3:5 › home page exposes accessible structure
1) [chromium] › tests/home.spec.ts:3:5 › home page exposes accessible structure
Error: expect(locator).toMatchAriaSnapshot(expected) failed
Locator: locator('body')
Timeout: 5000ms
- Expected - 1
+ Received + 1
- main:
- heading "Playwright fixture ready" [level=1]
- navigation "Primary":
- link "Docs":
- /url: /docs
- - button "Subscribe"
+ - button "Join"
##### snipped #####
1 failed
$ npx playwright test tests/home.spec.ts --project=chromium --reporter=line Running 1 test using 1 worker [1/1] [chromium] › tests/home.spec.ts:3:5 › home page exposes accessible structure 1 passed (1.5s)