Accessibility should be part of the development process, not something that gets checked just before a website goes live.
Unfortunately, it’s still common to see accessibility testing treated as a separate activity, left until the end of a project or picked up during a periodic audit. By that point, issues are much harder and more expensive to fix.
One way to improve this is to build automated accessibility testing into your existing development and testing workflows. Playwright and axe-core work well together here: Playwright handles browser automation and test execution, while axe-core analyses the rendered page and identifies many common accessibility problems. Together, they let developers pick up common issues automatically, add checks to their existing end-to-end tests and catch regressions before they reach production.
In this article, I’ll look at why it’s worth automating accessibility testing, what you need to get started, some practical ways to implement it, and how to read and act on what axe-core reports.
Why automate accessibility testing?
Catch problems earlier
The earlier you find an accessibility issue, the easier it is to fix. Discovering that a form field has no accessible label during development is far easier to deal with than discovering it after a release, particularly if that form is used across several areas of the website.
Running accessibility checks as part of your development and testing process means you can pick these problems up before they become embedded in your application.
Reduce repetitive manual testing
Manual accessibility testing is still essential, but repeating the same checks across multiple pages, templates and application states takes time. Many common issues can be identified automatically, including:
- Form fields without accessible labels
- Images missing alternative text
- Insufficient colour contrast
- Invalid or misused ARIA attributes
- Duplicate IDs referenced by labels or ARIA attributes
- Missing page titles or language attributes
Automating these checks cuts down the repetitive work in routine testing, so developers and accessibility specialists can concentrate on the issues that need human judgement.
Prevent accessibility regressions
Fixing an accessibility issue is only part of the job. You also need to make sure it doesn’t come back. A seemingly unrelated change to a shared component, navigation menu or form can easily introduce a problem somewhere else in the application.
By including accessibility checks in your regression tests, you’ll know about these problems as soon as they’re introduced.
Make accessibility part of your CI/CD pipeline
Accessibility testing doesn’t need to be a separate process. Playwright tests can run locally, on every pull request or in a scheduled regression suite, alongside your other automated tests. Accessibility checks become part of your normal workflow, and you get consistent feedback whenever changes are committed or a build is produced.
None of this replaces accessibility specialists or manual assessments, and it can’t prove that a website conforms to WCAG. The aim is to catch the easily identifiable problems consistently, so they don’t keep being reintroduced.
What do you need?
Playwright
Playwright is an end-to-end testing framework for automating browsers. It supports Chromium, Firefox and WebKit, and lets you navigate pages, interact with controls, submit forms, check application states and assert expected behaviour. It also includes role-based locators, test fixtures, parallel execution and built-in reporting.
For accessibility work, Playwright is particularly useful because it can put a page into the state you want to test. It can open a menu, reveal a dialog, select a tab or submit a form before an accessibility scan takes place.
If you’re already using Playwright for functional or regression testing, you can build accessibility checks into your existing test suite rather than introducing another testing framework.
axe-core
axe-core is an open-source accessibility testing engine developed by Deque. It runs a set of rules against rendered web content and reports the issues it can detect programmatically, covering areas such as:
- Accessible names and labels
- Image alternative text
- Colour contrast
- ARIA attributes and relationships
- HTML semantics and document structure
- Forms and controls
Each rule is tagged with the WCAG success criteria it relates to, which becomes useful later on. axe-core does the accessibility analysis, while Playwright provides the browser, the page state and the test assertions.
@axe-core/playwright
The @axe-core/playwright package connects the two. It provides an AxeBuilder class that you configure and run against a Playwright page. A scan returns a results object listing violations, passes, incomplete checks and the elements affected, and you use normal Playwright assertions to decide whether the test passes or fails.
A development or test environment
You’ll also need an application to test. Ideally, this should be a local development or staging environment that closely resembles production, with access to the page templates, components and interactive states that matter to your users.
For example, testing a navigation menu in its default state isn’t enough. You should also test it when it’s expanded and when someone is using it with a keyboard.
Basic knowledge of JavaScript or TypeScript
The examples below use TypeScript, although the same principles apply to JavaScript. You’ll need a basic understanding of:
- Playwright tests, locators and assertions
- Async/await
- HTML and ARIA
- WCAG principles
You don’t need to be an accessibility specialist to get started, but understanding why a particular issue matters will help you interpret the results and decide how to fix it.
Installing and configuring Playwright
If you haven’t already installed Playwright, you can create a new project using:
npm init playwright@latest
Follow the prompts to configure your project. Then, whether it’s a new project or an existing one, install the axe integration:
npm install --save-dev @axe-core/playwright
You can now import AxeBuilder into your Playwright tests:
import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';
The examples assume your Playwright configuration sets a baseURL, so page.goto('/') opens the application under test. If it doesn’t, use the full URL of your local or test environment.
Keep the package up to date as part of your normal dependency management. axe-core’s rules change between releases, so it’s worth reviewing updates rather than treating the test engine as a set-and-forget dependency.
Method 1: Scan an entire page
The simplest approach is to run an axe-core scan against a complete page:
import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';
test('Homepage accessibility', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('main')).toBeVisible();
const accessibilityResults = await new AxeBuilder({ page }).analyze();
expect(accessibilityResults.violations).toEqual([]);
});
There are three steps here:
- Playwright navigates to the page being tested.
- The test waits for the main content to be visible, to confirm that the page has rendered.
- axe-core analyses the page, and Playwright checks that the results contain no accessibility violations.
If axe-core finds any violations, the assertion fails and so does the test. Each violation includes a description, an impact rating, the affected elements and a link to guidance on fixing it, so it’s fairly easy to see where the problems are. I’ll come back to reading the results in more detail later.
Bear in mind that this only checks for issues that can be detected automatically, in the page’s current state. A passing test doesn’t mean the page is WCAG compliant.
Method 2: Target specific WCAG requirements
By default, axe-core runs all of its enabled rules, including best-practice checks that aren’t tied to a specific WCAG success criterion. If you want the test suite to reflect the standard you’re working to, you can restrict it to rules associated with particular WCAG levels using withTags():
test('Homepage WCAG accessibility checks', async ({ page }) => {
await page.goto('/');
const accessibilityResults = await new AxeBuilder({ page })
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa'])
.analyze();
expect(accessibilityResults.violations).toEqual([]);
});
This configures axe-core to run only the rules tagged against WCAG 2.0, 2.1 and 2.2 at levels A and AA.
The important distinction is that you’re testing for automatically detectable issues associated with those criteria, not proving that the website meets every requirement. A tag filter only selects the automated rules; many WCAG success criteria need human assessment and can’t be reliably evaluated by automated testing at all.
Tags can change between releases, so check the supported tags against the version of axe-core you’re using.
Method 3: Test individual components and interactive elements
Scanning an entire page is useful, but it only tests the page as it is when the scan runs. Navigation menus, modal windows, accordions and dropdowns change their rendered HTML and accessibility properties as people interact with them, so it’s worth testing these components in each of their states.
Here’s an example using a navigation menu:
test('Navigation menu accessibility', async ({ page }) => {
await page.goto('/');
// Open the navigation menu
await page.getByRole('button', { name: 'Navigation Menu' }).click();
// Wait for the menu to become visible
await page.locator('#navigation-menu-flyout').waitFor();
// Run an accessibility scan against the menu
const accessibilityResults = await new AxeBuilder({ page })
.include('#navigation-menu-flyout')
.analyze();
expect(accessibilityResults.violations).toEqual([]);
});
Notice the use of include(). This restricts the scan to a specific element or section of the page. It takes a CSS selector rather than a Playwright locator, so use one that matches your own markup.
More importantly, the scan takes place after the menu has been opened. axe-core analyses the page as it’s currently rendered and generally ignores hidden content, so it won’t open menus or discover other states for you. You need to use Playwright to get the page into each state before running the scan.
The same approach can be used for:
- Dropdown and mega menus
- Modal dialogs and confirmation windows
- Accordion panels and disclosure widgets
- Tabs and tab panels
- Search suggestions and autocomplete controls
- Form validation and error messages
- Shopping baskets, account areas and checkout steps
For each component, think about the states people can reach and test those states deliberately. A scan of a closed dialog is no substitute for a scan of the dialog when it’s open.
I’d recommend paying particular attention to reusable components, as an issue in one shared component can affect every page that uses it.
Method 4: Combine automated scans with functional accessibility tests
Having the right HTML attributes in place is only half the story. People also need to be able to use your website.
For example, a button might have an accessible name and pass an axe-core scan, but that doesn’t mean it works when operated with a keyboard. You can use Playwright to test some of these behaviours directly.
Check keyboard focus
test('Main navigation keyboard accessibility', async ({ page }) => {
await page.goto('/');
await page.keyboard.press('Tab');
await expect(page.getByRole('link', { name: 'Home' })).toBeFocused();
});
This checks that pressing Tab moves focus to the expected element. It assumes the Home link is the first focusable element on the page. If you have a skip link, that should come first, and it’s worth testing for in its own right.
In a real test, you’d extend this to check the focus order across all the relevant controls, whether focus stays visible, and whether focus moves appropriately when dialogs or menus are opened and closed.
Check that form fields have accessible labels
test('Contact form labels', async ({ page }) => {
await page.goto('/contact');
await expect(page.getByLabel('Your name')).toBeVisible();
await expect(page.getByLabel('Email address')).toBeVisible();
await expect(page.getByLabel('Your message')).toBeVisible();
});
getByLabel() finds form controls by their accessible label (including aria-label and aria-labelledby), so if a field isn’t labelled properly, the test fails. A failure can also reveal a mismatch between the wording in your test and the accessible name the page actually exposes.
It also encourages you to interact with form controls the way users perceive them, rather than relying on CSS selectors or implementation-specific IDs.
Check that buttons have accessible names
test('Buttons have accessible names', async ({ page }) => {
await page.goto('/');
const buttons = page.getByRole('button');
const count = await buttons.count();
for (let i = 0; i < count; i++) {
await expect(buttons.nth(i)).toHaveAccessibleName(/\S/);
}
});
toHaveAccessibleName() expects a name to compare against, so the regular expression /\S/ checks that each button’s name contains at least one non-space character. axe-core’s own button-name rule covers similar ground, but an explicit test makes the requirement clear to anyone reading your test suite.
Combining automated scans with behavioural tests like these gives you a more useful testing strategy than relying on an automated scan alone, although both still need to be backed up by keyboard and assistive technology testing.
Method 5: Create a reusable accessibility testing fixture
If you’re testing multiple pages, you’ll probably find yourself repeating the same axe-core configuration. Rather than duplicating this code throughout your test suite, you can create a reusable Playwright fixture.
For example, create a file called axe-test.ts:
import { test as base } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';
type AxeFixture = {
makeAxeBuilder: () => AxeBuilder;
};
export const test = base.extend<AxeFixture>({
makeAxeBuilder: async ({ page }, use) => {
const makeAxeBuilder = () =>
new AxeBuilder({ page }).withTags([
'wcag2a',
'wcag2aa',
'wcag21a',
'wcag21aa',
'wcag22aa'
]);
await use(makeAxeBuilder);
}
});
export { expect } from '@playwright/test';
You can then import your custom fixture into individual test files in place of @playwright/test:
import { test, expect } from './axe-test';
test('Homepage accessibility', async ({ page, makeAxeBuilder }) => {
await page.goto('/');
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations).toEqual([]);
});
This gives you one central place to manage your accessibility testing configuration. If you want to change the WCAG tags or add other options later, you only need to update the fixture, which makes it much easier to roll accessibility testing out across a larger application.
You can still customise an individual scan when you need to. A component test, for example, can call include() on the builder the fixture returns before running analyze().
Understanding and investigating the results
When a scan fails, the next step is to understand what axe-core has reported, not to change the test until it passes. Each violation typically includes:
- The rule ID and a description of the problem
- An impact rating: critical, serious, moderate or minor
- A help message and a link to further guidance
- The elements affected, each with a target selector and a failure summary explaining what was detected
You can print the results while you’re developing:
const accessibilityResults = await new AxeBuilder({ page }).analyze();
for (const violation of accessibilityResults.violations) {
console.log(`${violation.impact}: ${violation.help}`);
for (const node of violation.nodes) {
console.log('Affected element:', node.target);
console.log(node.failureSummary);
}
}
The impact rating helps with prioritisation, but it shouldn’t be the only factor. Consider how many users are affected, how important the task is, whether there’s a workaround and how widely the component is used.
It’s also worth knowing that axe-core returns an incomplete list alongside violations. These are checks it couldn’t confidently pass or fail, such as colour contrast over a background image. They aren’t confirmed violations, but they need manual review. The tests in this article only fail on violations, so make sure someone looks at the incomplete results too.
A good workflow is to reproduce the issue, inspect the affected element, understand the rule, fix the underlying markup or interaction, then rerun the test.
Integrating accessibility testing into CI/CD
Once your tests are working locally, the next step is to run them in your continuous integration pipeline, for example whenever a developer opens a pull request. A typical workflow might look something like this:
- A developer pushes changes and opens a pull request.
- The CI pipeline installs dependencies and the Playwright browsers.
- The application is built and started in the test environment.
- Playwright runs the test suite, including the accessibility scans.
- The results are published for the development team.
- Failures are investigated before the changes are merged.
You don’t necessarily need to run every accessibility test against every page on every commit. For a smaller site, the full suite on every pull request may be practical. For a larger application, you might run a smaller set of critical checks on pull requests and a more comprehensive suite as part of scheduled regression testing.
Make sure the test environment is stable and representative. Tests can give misleading results if they run before the application has finished rendering, if the data is inconsistent or if external services behave unpredictably.
Use Playwright’s reporting and your CI artefacts to make failures actionable. The team should be able to see which page or component failed, which rule was triggered and which elements need attention.
What matters is that the checks run consistently as part of the normal development process, rather than every now and then.
Handling existing accessibility issues
If you’re introducing automated accessibility testing to an established website, you may well discover a significant number of existing issues. If every test fails as soon as any violation is found, you could end up with a testing process that’s difficult to introduce or maintain.
There are a couple of ways to approach this.
Prioritise and fix existing issues
Ideally, you should identify the existing violations, assess their impact and prioritise fixing them, using the impact rating alongside the other factors above. Critical and serious issues should generally be dealt with first.
Temporarily manage known violations
AxeBuilder provides exclude() and disableRules(), which let you leave out particular elements or switch off specific rules during a scan. For example:
const accessibilityResults = await new AxeBuilder({ page })
// Skip a component with known issues
.exclude('#legacy-component')
// Switch off a rule while a known issue is being fixed
.disableRules(['color-contrast'])
.analyze();
Use these options carefully, though. Excluding an element also excludes everything inside it from every rule, and disabling a rule can hide new instances of the same problem elsewhere on the page.
I’d treat exclusions as temporary technical debt: record the reason, the scope and an owner for each one, and make sure there’s a plan to fix the underlying issue. Avoid using them simply to make your tests pass.
What automated accessibility testing cannot do
Automated accessibility testing is useful, but it isn’t a replacement for manual testing. Some issues need an understanding of context, meaning and real user experience, and can’t be reliably assessed by running the HTML against a set of rules. For example:
- Does the content make sense when read by a screen reader?
- Is the keyboard navigation logical and predictable?
- Is the focus indicator clearly visible?
- Are instructions and error messages clear, and presented at the right time?
- Does the alternative text describe the purpose of an image in context?
- Does the content still work when text is resized or zoomed to 200% or 400%?
- Are dynamic updates announced appropriately to assistive technologies?
- Can someone complete the task without getting stuck in a keyboard trap?
Some of these can be partially tested through automation, but they all still need a person to assess them. I’d recommend supplementing Playwright and axe-core with:
Keyboard testing: Work through important journeys using only the keyboard. Check focus order, focus visibility, interactive controls and keyboard traps.
Screen reader testing: Test with screen readers such as NVDA, JAWS and VoiceOver. Check that headings, landmarks, forms, controls, status messages and dynamic content are communicated correctly.
Visual testing: Check colour contrast where automated tools struggle, such as text over images and hover or focus states, along with text resizing, zoom, reflow and responsive layouts.
Manual WCAG assessment: Review the applicable WCAG success criteria and assess the areas automated tools can’t reliably evaluate.
Where possible, include people with disabilities in usability testing. They can identify practical barriers that automated tools and conventional audits may overlook. No single tool or method will catch everything, so combine them.
Bringing it all together
If you’re already using Playwright for end-to-end testing, adding automated accessibility testing with axe-core is relatively straightforward. You can start with simple page-level scans and gradually introduce checks covering individual components, interactive states and keyboard behaviour.
I’d recommend approaching it incrementally:
- Install
@axe-core/playwrightin your Playwright project. - Start by scanning your most important pages and templates.
- Choose WCAG tags that match the standard you need to meet.
- Review the results and prioritise existing accessibility issues.
- Add tests for reusable components and interactive states.
- Include keyboard, label and accessible-name assertions.
- Create a reusable fixture, so the configuration stays consistent.
- Run the tests in your CI/CD pipeline and make failures visible to the team.
- Keep supplementing automated checks with manual keyboard, screen reader and usability testing.
For me, the biggest benefit is consistency. Once accessibility checks are part of your normal development workflow, problems you’ve already fixed are far less likely to creep back in, and accessibility becomes something developers think about throughout the project rather than at the end of it.
Useful resources
- Playwright: Accessibility testing – official documentation covering axe-core integration and examples
- Playwright: Locators – role-based and label-based locators
- Playwright: Test fixtures – creating reusable fixtures for your test suite
- axe-core on GitHub – the open-source accessibility testing engine
- @axe-core/playwright on npm – installation and package information
- Deque University: axe rules – explanations of each axe-core rule
- Web Content Accessibility Guidelines (WCAG) – W3C guidance on accessibility standards
- Accessibility Insights for Web – tools and guidance for carrying out manual accessibility assessments