Agent Wranglers

STK-42Default Open source

Use axe-core for accessibility tests

Run axe-core on every page your browser tests open, and fail the test on any violation.

Review by

2027-04-30

How to do it

axe-core 1.0 shipped in June 2015, and 4.14.0 came out on 5 October 2026. npm counted over 49 million downloads in the week to 18 October 2026. It is MPL-2.0 licensed, an OSI-approved licence. It runs inside any browser driver. Wire it in as Check accessibility in every build describes. Choose something else when you need a full manual audit, because automated rules find only part of the problems a screen reader user meets.

Examples

TypeScript example

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

test('the shop page has no accessibility violations', async ({ page }) => {
  await page.goto('https://example.com/shop');
  const results = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa', 'best-practice']).analyze();
  expect(results.violations).toEqual([]);
});

Python example

from pathlib import Path
from playwright.sync_api import Page

AXE_SCRIPT = Path("node_modules/axe-core/axe.min.js").read_text()
WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa", "best-practice"]

def test_shop_page_has_no_violations(page: Page):
    page.goto("https://example.com/shop")
    page.add_script_tag(content=AXE_SCRIPT)
    results = page.evaluate("tags => axe.run({ runOnly: tags })", WCAG_TAGS)
    assert results["violations"] == []

How to check

Every page the browser tests open runs axe-core with every tag the accessibility chapter lists, and the build fails on one violation.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/axe-core">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.