Accessibility testing
axe-core integrated with Playwright runs automated WCAG checks in 3 lines of code. I add it to every page-level test — it catches missing labels, contrast issues, and duplicate IDs before they reach production.
Install axe-core
Playwright doesn't include accessibility scanning out of the box — you need the @axe-core/playwright package. axe-core is the most widely used automated accessibility engine. It catches ~57% of WCAG issues automatically — the rest require manual review.
Scan the whole page or a specific component
By default AxeBuilder.analyze() scans the entire page. If you only care about a specific region — a modal, a form, a nav — use .include(). This is useful when you're adding accessibility tests incrementally and don't want violations from other parts of the page to block you.
Important: if you're scanning a UI state that appears after user interaction (a dropdown, a modal), trigger that state before calling analyze().
Handle known violations
When adding accessibility tests to an existing app, you'll find violations you can't fix immediately. Two options: exclude the element, or disable the specific rule. Don't suppress blindly — document why each suppression exists and when it should be fixed.
Shared axe configuration via fixture
When the same axe configuration (same WCAG tags, same exclusions) repeats across many tests — extract it into a fixture. This keeps configuration in one place and makes tests cleaner.