← Back to Frontend, page 3

frontend-0042 · Medium mid

How do you test accessibility automatically, and what can automated tools not tell you?

Run a rules engine such as axe-core in unit, end-to-end and CI tests to catch machine-checkable faults like missing names, bad ARIA and low contrast. It cannot judge whether alt text is meaningful, whether focus order makes sense or whether a flow is usable, so keyboard and screen reader checks by a person are still needed.

Full answer

Automated tools parse the page and apply rules. They are quick, cheap and good at regressions. They find faults such as:

  • images without alt, buttons and inputs without an accessible name;
  • invalid or misused ARIA, duplicate ids that ARIA relies on;
  • missing document language, missing page title;
  • insufficient colour contrast in many (not all) cases;
  • skipped heading levels in some tools, landmarks used wrongly.

They cannot decide:

  • whether alt="image" is helpful (it is present, so it passes);
  • whether the focus order matches the visual order and the reading order;
  • whether a custom widget can really be used with a keyboard and a screen reader;
  • whether error messages are clear, or whether time limits are fair;
  • whether captions are accurate, or colour is the only way to see a status.

Studies and vendors give different numbers for the share of problems that tools can catch, so do not quote a percentage. Say that automation covers a part and a manual check covers the rest.

A sensible process:

  1. Lint in the editor with an accessibility lint rule set.
  2. Run axe-core inside component or page tests, and fail the build on new violations.
  3. Run a scanner or Lighthouse in CI on key pages.
  4. Test by hand for every new widget: Tab through it, use it without a mouse, zoom to 200 percent, and try a screen reader.
  5. Keep known issues in a tracked list, not in a muted rule.

The snippet runs the axe-core engine on a deliberately bad page in Chrome, and returns the rule ids it found. The page has an image without alt, a button without a name, an input without a label and a page with no title. The test checks that these rules fire, and that the good version has none of them. The checks that axe skips for manual review were not run.

javascript
// In a browser test, after loading axe.min.js into the page:
const results = await axe.run(document, { runOnly: ['wcag2a', 'wcag2aa'] });
window.ruleIds = results.violations.map((v) => v.id).sort();

Run in headless Chrome 156 through Playwright. Two full runs gave the same results. The axe-core library was loaded into the page by the test, and the snippet body ran as shown. The bad page reported image-alt, button-name, label, document-title and html-has-lang, and the good page reported none of them. Checks that axe leaves for manual review were not run.

Key points

  • Rules engines catch machine-checkable faults and prevent regressions.
  • They cannot judge meaning, focus order or real usability.
  • Use them in editor, component tests and CI.
  • Add manual keyboard and screen reader checks.
  • Do not quote a single percentage of coverage.

Common mistakes

  • Treating a clean automated report as proof of accessibility.
  • Muting a failing rule instead of fixing it.
  • Testing only the home page.
  • Skipping keyboard testing because the scanner passed.

Follow-ups

  • Which kinds of faults need a human?
  • How would you add axe to a Playwright test?
  • How do you handle a violation in third-party code?

Tips

  • Give two examples of what tools catch and two of what they cannot.
  • Describe a layered process, not one tool.