e2e-tests/playwright/docs/accessibility/automated_scan_testing.md
This guide focuses on automated accessibility testing using a simplified, comprehensive approach. Use axe-core's default rule set and scope testing to specific elements, disabling rules only when necessary. This maximizes coverage while minimizing maintenance overhead.
Use axe-core's comprehensive default rule set and scope testing to specific elements.
Benefits:
test('page accessibility', async ({axe, page}) => {
const results = await axe.builder(page).analyze(); // All applicable rules
expect(results.violations).toHaveLength(0);
});
test('component accessibility', async ({axe, page}) => {
const results = await axe
.builder(page)
.include('#element') // Scope to element
.analyze(); // All applicable rules
expect(results.violations).toHaveLength(0);
});
test('modal accessibility', async ({axe, page}) => {
await page.getByRole('button', {name: 'Open modal'}).click();
const results = await axe.builder(page).include('[role="dialog"]').analyze();
expect(results.violations).toHaveLength(0);
});
test('form error state accessibility', async ({axe, page}) => {
// Test normal state
let results = await axe.builder(page).include('form').analyze();
expect(results.violations).toHaveLength(0);
// Test error state
await page.getByRole('button', {name: 'Submit'}).click();
results = await axe.builder(page).include('form').analyze();
expect(results.violations).toHaveLength(0);
});
Disable Rules Only When:
// Good - Documented limitation
test('dark theme modal', async ({axe, page}) => {
const results = await axe
.builder(page)
.include('[role="dialog"]')
.disableRules([
'color-contrast', // TODO: MM-nnn - Color contrast improvement
])
.analyze();
});
// Good - Context on comment
test('modal dialog', async ({axe, page}) => {
const results = await axe
.builder(page)
.include('[role="dialog"]')
.disableRules([
'page-has-heading-one', // Not applicable to modals
'landmark-one-main', // Not applicable to modals
])
.analyze();
});
Don't Disable Rules For: