Integrando axe-core aos testes do Playwright
Faça a compilação falhar quando surgirem regressões de acessibilidade.
Integrando axe-core aos testes do Playwright é uma aula grátis de Web Accessibility Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Web Accessibility Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Web Accessibility Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
From Manual Scan to Automated Test
Clicking a browser extension is great for one page. To guard every page on every commit, you wire axe-core into your automated test suite.
Why Playwright
Playwright drives a real browser from code, so axe runs against the page exactly as users see it, including content rendered by JavaScript.
The Bridge Package
The axe-core/playwright package connects the two. Install it alongside Playwright so your tests can inject and run the axe engine.
npm install --save-dev @axe-core/playwrightImport the Builder
In your test file you import AxeBuilder. It is the helper that injects axe-core into the current page and collects the results for you.
import AxeBuilder from '@axe-core/playwright';Navigate, Then Analyze
First let Playwright load the page, then call analyze on a fresh AxeBuilder to scan whatever is currently rendered in the browser.
await page.goto('/');
const results = await new AxeBuilder({ page }).analyze();Assert Zero Violations
The result holds a violations array. A passing page has an empty array, so you assert its length is zero to fail the test on any issue.
expect(results.violations).toEqual([]);A Complete Test Case
Put it together and you have a real accessibility test that runs in CI like any other Playwright spec.
test('home page has no a11y violations', async ({ page }) => {
await page.goto('/');
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});Test After Interaction
The real power is scanning dynamic states. Open a modal or expand a menu first, then analyze, so axe checks the UI users actually trigger.
await page.getByRole('button', { name: 'Open menu' }).click();
const results = await new AxeBuilder({ page }).analyze();Narrow the Scope
You can focus the scan on one region with include, which is handy when testing a single component without noise from the rest of the page.
new AxeBuilder({ page }).include('#signup-form').analyze();Choose Your Rule Set
Use withTags to run only the rules tied to a standard, like the WCAG 2.1 AA criteria, so your test matches your conformance target.
new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa']).analyze();Remember the Ceiling
Green Playwright tests still only cover the automatable share of issues. They complement manual screen reader checks; they never replace them.
Quick Check
Recall how you make a test fail on accessibility problems.
Recap: a11y in Your Pipeline
AxeBuilder injects axe-core into a real browser, you analyze each state, and assert zero violations. Now accessibility regressions break the build automatically. ✅
Perguntas Frequentes
A aula “Integrando axe-core aos testes do Playwright” é grátis?
Sim — o texto completo de “Integrando axe-core aos testes do Playwright” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Web Accessibility Academy, atualize para CoddyKit PRO. O curso de Web Accessibility Academy inclui 4 aulas no total.
O que vou aprender em “Integrando axe-core aos testes do Playwright”?
Faça a compilação falhar quando surgirem regressões de acessibilidade. Você pratica Web Accessibility Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Web Accessibility Academy?
Nenhuma experiência prévia é necessária. Web Accessibility Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Integrando axe-core aos testes do Playwright”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Web Accessibility Academy?
Sim. Cada aula de Web Accessibility Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- O que a automação consegue e não consegue detectar
- Analisando com axe DevTools e Lighthouse
- Integrando axe-core aos testes do Playwright
- Análise estática e bloqueios de CI para acessibilidade