@cronn/aria-snapshot
v0.1.1
Published
JSON-based ARIA snapshots for Playwright
Downloads
130
Readme
ARIA Snapshots
Playwright's ARIA Snapshots
snapshot the accessibility tree of a page using YAML as serialization format. @cronn/aria-snapshot provides a lightweight adapter, transforming the original YAML format to an optimized JSON format.
Serializing ARIA Snapshots in JSON provides more flexibility when writing Playwright tests, because JSON structures are natively supported in JavaScript and can be composed without requiring additional tooling.
Getting Started
Adding the library to your project
npm install -D @cronn/aria-snapshotyarn add -D @cronn/aria-snapshotpnpm add -D @cronn/aria-snapshotWriting Tests
import { snapshotAria } from "@cronn/aria-snapshot";
import { defineValidationFileExpect } from "@cronn/playwright-file-snapshots";
const expect = defineValidationFileExpect();
test("matches ARIA snapshot", async ({ page }) => {
await expect(snapshotAria(page.getByRole("main"))).toMatchJsonFile();
});ARIA Snapshot Example:
{
"main": [
"heading 'List' [level=1]",
{
"list": [
{
"listitem": "Apple"
},
{
"listitem": "Peach"
}
]
}
]
}To compose multiple ARIA snapshots in a single JSON file, you can use an object structure:
import { snapshotAria } from "@cronn/aria-snapshot";
test("matches composed ARIA snapshots", async ({ page }) => {
await expect({
nav: await snapshotAria(page.getByRole("navigation")),
main: await snapshotAria(page.getByRole("main")),
}).toMatchJsonFile();
});