Automated Tools
Automated Tools
Automated tools catch common accessibility issues.
axe-core
// Install
npm install axe-core @axe-core/react
// React integration
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
if (process.env.NODE_ENV !== 'production') {
import('@axe-core/react').then((axe) => {
axe.default(React, ReactDOM, 1000);
});
}
ReactDOM.render(<App />, document.getElementById('root'));
Jest Integration
// jest.config.js
module.exports = {
setupFilesAfterSetup: ['@testing-library/jest-dom'],
};
// Form.test.js
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import Form from './Form';
expect.extend(toHaveNoViolations);
describe('Form Accessibility', () => {
it('should have no axe violations', async () => {
const { container } = render(<Form />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
Playwright Integration
// accessibility.spec.js
const { test, expect } = require('@playwright/test');
const AxeBuilder = require('@axe-core/playwright').default;
test('page has no accessibility violations', async ({ page }) => {
await page.goto('/');
const accessibilityScanResults = await new AxeBuilder({ page })
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
CI Integration
# .github/workflows/a11y.yml
name: Accessibility Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm run test:a11y
- run: npm run build
- run: npx lighthouse http://localhost:3000 --only-categories=accessibility
Manual Testing
Manual Testing
Automated tools can't catch everything.
Keyboard Testing
- Tab through all interactive elements
- Check focus visibility
- Verify logical tab order
- Test keyboard shortcuts
- Ensure no keyboard traps
Screen Reader Testing
- Test with NVDA/VoiceOver
- Verify all content is announced
- Check landmarks and headings
- Test dynamic content announcements
- Verify form labels and errors
Visual Testing
- Check color contrast
- Verify text can be resized to 200%
- Test with different color modes
- Check focus indicators
- Verify content reflows at 320px width
Manual Testing Checklist
## Keyboard
- [ ] All interactive elements focusable
- [ ] Focus visible on all elements
- [ ] Tab order logical
- [ ] No keyboard traps
- [ ] Enter/Space activate buttons
- [ ] Escape closes modals
## Screen Reader
- [ ] Page title announced
- [ ] Landmarks announced
- [ ] Headings in order
- [ ] Images have alt text
- [ ] Form labels announced
- [ ] Errors announced
## Visual
- [ ] Contrast ratios pass
- [ ] Text resizable to 200%
- [ ] No content loss at 320px
- [ ] Focus indicators visible
- [ ] No flashing content
Axe and Lighthouse
Axe and Lighthouse
Axe Rules
// Common axe rules
const rules = {
// Color contrast
'color-contrast': { enabled: true },
// Forms
'label': { enabled: true },
'aria-required-attr': { enabled: true },
// Images
'image-alt': { enabled: true },
// Navigation
'link-name': { enabled: true },
'button-name': { enabled: true },
// ARIA
'aria-allowed-attr': { enabled: true },
'aria-required-attr': { enabled: true },
};
Lighthouse Scores
# Run Lighthouse accessibility audit
npx lighthouse http://localhost:3000 --only-categories=accessibility
# Output
# Accessibility: 95/100
#
# Issues:
# - [aria-*] attributes: 2 issues
# - Color contrast: 1 issue
Common Issues Found
| Issue | Tool | Fix |
|---|---|---|
| Missing alt text | axe, Lighthouse | Add meaningful alt |
| Low contrast | axe, Lighthouse | Increase contrast ratio |
| Missing labels | axe | Add labels or aria-label |
| Empty buttons | axe | Add accessible name |
| Missing heading | Lighthouse | Add h1 element |
Testing Strategy
- Automated: Run axe in CI/CD
- Manual: Test with screen readers
- Visual: Check contrast and zoom
- Keyboard: Navigate without mouse
- User Testing: Include disabled users
Practice Problems
Create a reusable React component implementing Accessibility Testing. Include proper state management and accessibility.
Solution
// Production-ready component with:
// - Proper TypeScript types
// - Accessibility (ARIA)
// - Error boundaries
// - Loading states
// - Memoization where neededWrite unit and integration tests for Accessibility Testing using React Testing Library.
Solution
// Test coverage:
// 1. Rendering tests
// 2. Interaction tests
// 3. Edge case tests
// 4. Accessibility testsOptimize Accessibility Testing for performance. Consider memoization, code splitting, and bundle size.
Solution
// Optimization techniques:
// 1. React.memo / useMemo / useCallback
// 2. Code splitting with lazy()
// 3. Virtual scrolling for lists
// 4. Image lazy loading
// 5. Bundle analysisQuiz
1. What does axe-core test?
2. Can automated tools catch all accessibility issues?
3. What is the primary purpose of Accessibility Testing?
4. What is a common mistake when implementing Accessibility Testing?
Flashcards
Question
What is axe-core?
Click to reveal answer
Answer
An automated accessibility testing engine that catches common WCAG violations.
Question
Why is manual testing needed?
Click to reveal answer
Answer
Automated tools only catch ~30-40% of issues; manual testing covers the rest.
Question
What does Lighthouse test?
Click to reveal answer
Answer
Performance, accessibility, SEO, and best practices for web pages.
Question
How do you test keyboard accessibility?
Click to reveal answer
Answer
Tab through all elements, verify focus visibility, check logical tab order.
Question
What is Accessibility Testing?
Click to reveal answer
Answer
Accessibility Testing is a key concept in frontend development.
Revision Notes
Key Takeaways
- 1.Automated tools catch common issues but not everything
- 2.Manual testing with screen readers is essential
- 3.Integrate axe-core into CI/CD pipeline
- 4.Test keyboard navigation separately
- 5.Combine automated and manual testing for best coverage
Interview Tips
- •Explain the difference between automated and manual testing
- •Discuss how to integrate accessibility testing into CI/CD
- •Know common tools and their coverage
Cheat Sheet
Accessibility Testing Cheat Sheet
Automated
- axe-core: WCAG violations
- Lighthouse: Overall score
- jest-axe: Unit tests
Manual
- Keyboard navigation
- Screen reader testing
- Visual contrast check
- Zoom to 200%
CI/CD
- axe in unit tests
- Lighthouse in pipeline
- axe in Playwright
Coverage
- Automated: 30-40%
- Manual: 60-70%