106 / 139 · 13 Browser Automation with Playwright · Visual Testing and Edge Cases← prev⊞ allnext →☰ Read as one page
12.3Accessibility Testing
Playwright integrates with axe-core for automated accessibility checks:
import AxeBuilder from '@axe-core/playwright';
test('homepage has no accessibility violations', async ({ page }) => {
await page.goto('/');
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});
// Check specific rules or sections
test('login form is accessible', async ({ page }) => {
await page.goto('/login');
const results = await new AxeBuilder({ page })
.include('#login-form')
.withRules(['color-contrast', 'label', 'aria-required-attr'])
.analyze();
expect(results.violations).toEqual([]);
});