Accessibility Checks and Axe Integration

Accessibility is essential for inclusive products and often a regulatory requirement. While manual audits remain important, you can catch many common issues automatically by integrating accessibility checkers like axe with Playwright.

Running Axe Accessibility Checks in Playwright

You can use libraries such as @axe-core/playwright or inject axe into the page to scan for violations after navigation or key interactions.

// accessibility-axe.spec.ts
import { test, expect } from '@playwright/test';
import axe from '@axe-core/playwright';

test('homepage has no serious a11y violations', async ({ page }) => {
  await page.goto('https://demo.myshop.com');
  const results = await axe.run(page, {
    runOnly: ['wcag2a', 'wcag2aa'],
  });

  expect(results.violations).toEqual([]);
});
Note: Automated tools can detect issues like missing alt text, low contrast or incorrect ARIA usage, but they cannot fully replace manual keyboard or screen-reader testing.
Tip: Start by adding accessibility checks to critical flows (login, checkout, onboarding) and expand coverage over time.
Warning: Treat a11y findings as real defects, not optional suggestions; triage and prioritise them like any other bug.

Combining accessibility assertions with your functional tests ensures that regressions are caught early, before features ship.

Common Mistakes

Mistake 1 โ€” Running a11y scans only once, manually

This misses regressions.

โŒ Wrong: Doing a single audit before release and never automating it.

โœ… Correct: Integrate scans into CI so new issues are caught on every change.

Mistake 2 โ€” Ignoring keyboard and focus behaviour

This leaves important gaps.

โŒ Wrong: Only checking contrast and labels but not tab order or focus visibility.

โœ… Correct: Add manual checks or automated flows that exercise keyboard navigation.

🧠 Test Yourself

What is a good way to use axe with Playwright?