How-To Guide

How to Run Accessibility Tests in CI

Add automated accessibility checks to CI with axe, keyboard tests and manual review, and gate merges on regressions without false confidence.

On this page

  1. Introduction
  2. What Automation Can and Cannot Catch
  3. Adding axe to the Test Suite
  4. Keyboard and Focus Tests
  5. Contrast and Dynamic States
  6. Manual Review and Assistive Technology
  7. Common Pitfalls and Conclusion

Introduction

Accessibility bugs are easy to ship and hard to notice if you do not use assistive technology. A missing label, a low-contrast text, a div pretending to be a button: they pass a visual review and fail a screen-reader user. Automated accessibility testing catches a meaningful slice of these mechanically, in CI, on every change. It does not catch everything, and treating it as proof of accessibility is a mistake, but combined with keyboard testing and periodic manual review it stops the most common regressions before they merge.

What Automation Can and Cannot Catch

Automated tools such as axe check the DOM against a set of rules: missing alt text, insufficient colour contrast, invalid ARIA, missing form labels, duplicate ids, and more. These are the mechanical violations, and a tool finds them reliably and cheaply. That is a real and worthwhile slice.

What automation cannot judge is whether the experience makes sense: whether the reading order tells a coherent story, whether the focus order matches the visual order, whether an error message is helpful, whether a custom widget is operable and understandable. Those need keyboard testing and human review. Being explicit about the gap prevents the false confidence that “axe passed, so we are accessible”.

# automated vs manual
automated: alt text, contrast, labels, ARIA validity, landmarks, ids
manual:    reading order, focus order, error clarity, widget operability,
           cognitive load, screen-reader announcement quality
# passing axe != accessible; it means the mechanical rules passed

Adding axe to the Test Suite

Inject axe into your browser tests and assert that there are no violations of the rules you care about. Run it on the pages and in the states that matter, not just the home page, because forms, modals and error states are where violations concentrate. Treat a violation as a test failure so the merge is blocked.

Report failures with the rule id, the element selector and the help text, so the person fixing it knows what to change rather than only that something failed. A violation without a selector is a puzzle; a violation with one is a task.

Configure the rule set deliberately. Some rules produce false positives or apply to legacy markup you have not addressed yet; disable them explicitly with a documented reason rather than turning off the whole check. A rule disabled silently is a rule that will be forgotten and left disabled forever.

import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';

for (const path of ['/', '/checkout', '/signup']) {
  test(`a11y: ${path}`, async ({ page }) => {
    await page.goto(path);
    const results = await new AxeBuilder({ page })
      .withTags(['wcag2a', 'wcag2aa'])
      .disableRules(['region'])      // documented: single-page layout, tracked in ENG-123
      .analyze();
    expect(results.violations).toEqual([]);
  });
}

Keyboard and Focus Tests

Automate what keyboard behaviour can be checked: that the page is reachable by Tab, that focus moves in a sensible order, that the focus indicator is visible, that a modal traps focus, that Escape closes it and returns focus to the trigger. These are assertions a browser test can make and they catch the classic “keyboard trap” and “focus lost” bugs.

Test the interactive flows, not just the static render. Submit a form with the keyboard, open and close a dialog, navigate a menu, and assert the focus location after each step. Keyboard behaviour is where custom widgets most often fail, and it is exactly what a visual or ARIA-only check misses.

test('dialog traps focus and restores it', async ({ page }) => {
  await page.goto('/account');
  await page.getByRole('button', { name: 'Delete account' }).press('Enter');
  const dialog = page.getByRole('dialog');
  await expect(dialog).toBeVisible();

  for (let i = 0; i < 5; i++) await page.keyboard.press('Tab');
  // focus must stay inside the dialog, never reach the page behind it
  expect(await page.evaluate(() => document.activeElement?.closest('[role=dialog]') !== null)).toBe(true);

  await page.keyboard.press('Escape');
  await expect(dialog).toBeHidden();
  await expect(page.getByRole('button', { name: 'Delete account' })).toBeFocused();

Contrast and Dynamic States

Colour contrast is checkable but depends on state: a button’s hover colour, a disabled input, an error message, text over an image. Add explicit tests that set the state and then run the contrast check, because a default-state-only check misses the state where contrast fails. Dynamic content such as a toast or an inline error is often the offender.

Test the states users actually encounter: empty, loading, error, disabled, focused, hovered. A component library should have a contrast test per variant, not just for the default. When a design token changes, these tests catch the contrast regression that visual review misses.

test('error state meets contrast', async ({ page }) => {
  await page.goto('/signup');
  await page.getByLabel('Email').fill('not-an-email');
  await page.getByRole('button', { name: 'Sign up' }).click();
  const err = page.getByRole('alert');
  await expect(err).toBeVisible();
  const results = await new AxeBuilder({ page }).include('[role=alert]').withTags(['wcag2aa']).analyze();
  expect(results.violations).toEqual([]);          // contrast checked in the error state
});

Manual Review and Assistive Technology

Schedule a periodic manual pass with a screen reader: navigate the critical flows, listen to the announcements, and check that the experience is coherent. This is the only way to catch the defects automation cannot, such as a reading order that makes no sense or a custom widget that announces nothing useful.

Include people with disabilities in the review where possible; it is the most reliable test of real usability and is also the right thing to do. Automated tests are the floor, not the ceiling. A team that ships an axe-clean product that is unusable with a screen reader has passed the wrong test.

# cadence for a real a11y programme
per commit:  automated axe + keyboard/focus assertions in CI
per release: manual keyboard-only walkthrough of critical flows
per quarter: screen-reader review of critical flows
ongoing:     involve disabled users in usability review
# automation is the floor; human review is where real accessibility is proven

Common Pitfalls and Conclusion

Do not treat axe passing as “accessible”; it means the mechanical rules passed. Do not disable rules silently. Do not check only the default state; test error, disabled, hovered and loading states. Do not run accessibility tests only on the home page. And do not skip manual screen-reader review, which is where the important defects live.

Automated accessibility tests catch the mechanical violations cheaply and block them at merge; keyboard and focus tests catch the interaction defects; manual review catches the rest. Run all three, with automation as a fast CI gate and human review on a schedule. The result is fewer accessibility regressions shipped, and a clear-eyed view of what the tests do and do not prove.

Sources: W3C: WCAG 2.2, Deque: axe-core, MDN: Accessibility.

FAQ

Does passing axe mean my site is accessible?
No. Axe checks mechanical rules such as labels, contrast and ARIA. It cannot judge reading order, focus order, error clarity or whether a custom widget is understandable. Treat it as a floor and add keyboard testing and periodic screen-reader review.
Why test non-default states for contrast?
Because contrast often fails only in specific states: hover, disabled, error messages, text over images. Testing only the default state misses the state where the user actually sees the problem, so set the state first and then run the check.

Related Examples