Integrating Accessibility (a11y) Audits Directly in GitHub Actions with Axe-Core
Integrating Accessibility (a11y) Audits Directly in GitHub Actions with Axe-Core
Web accessibility is no longer a nice-to-have or a minor post-launch checkbox. With regulations like the ADA (Americans with Disabilities Act) and WCAG (Web Content Accessibility Guidelines) being strictly enforced, non-compliant web applications risk heavy fines and brand damage.
Despite this, web accessibility audits are often skipped because manual evaluations are time-consuming and expensive.
The solution is to automate accessibility testing github actions as part of your active CI/CD cycle. By integrating Axe-Core with Playwright, you can catch up to 50% of common accessibility issues (like low color contrast, missing alt texts, and incorrect heading hierarchies) on every commit.
1. Adding axe-playwright to Your Project
Axe-Core is the leading engine for web accessibility testing. Combining it with Playwright allows you to scan dynamically rendered UI elements.
First, add the package to your development dependencies:
npm install --save-dev @axe-core/playwright
2. Writing the Accessibility Test Case
Here is how you can write a test in Playwright that scans a page for accessibility violations and generates a report:
const { test, expect } = require('@playwright/test');
const AxeBuilder = require('@axe-core/playwright').default;
test.describe('Accessibility Audits', () => {
test('homepage should have no automatically detectable accessibility violations', async ({ page }) => {
await page.goto('/');
// Analyze the page
const accessibilityScanResults = await new AxeBuilder({ page }).analyze();
// Verify there are no violations
expect(accessibilityScanResults.violations).toEqual([]);
});
});
3. Configuring the GitHub Actions Workflow
To ensure that no code gets merged into your main branch with critical accessibility bugs, set up a GitHub Actions workflow to execute the tests on every Pull Request.
Create a file named .github/workflows/a11y-checks.yml:
name: Accessibility Checks
on:
pull_request:
branches: [main]
jobs:
a11y-audit:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: Install Dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Accessibility Tests
run: npx playwright test tests/accessibility.spec.js
The Benefits of Automated a11y Testing
By setting up this automated gate, your development team will:
* Catch Violations Early: Fix missing form labels, ARIA landmarks, and contrast issues while developing, rather than during code freeze.
* Reduce Legal Risk: Continuously maintain a baseline level of compliance.
* Ensure Inclusivity: Provide a consistent, functional experience for users utilizing screen readers and assistive tech.
👉 Need help making your platform compliant? Building automated gates requires specialist expertise. Let QA::SYNTH handle your test suite architecture. We design and integrate compliance checks directly into your CI pipeline so you can ship stable, accessible code with confidence.