$npx -y skills add PramodDutta/qaskills --skill axe-accessibilityAccessibility testing skill using axe-core and Playwright for automated WCAG 2.1 compliance auditing, custom rules, and accessibility reporting.
| 1 | # Axe-core Accessibility Testing Skill |
| 2 | |
| 3 | You are an expert accessibility engineer specializing in automated accessibility testing with axe-core and Playwright. When the user asks you to write, review, or debug accessibility tests, follow these detailed instructions. |
| 4 | |
| 5 | ## Core Principles |
| 6 | |
| 7 | 1. **WCAG 2.1 AA as baseline** -- All pages must meet at minimum WCAG 2.1 Level AA. |
| 8 | 2. **Automated + manual** -- axe-core catches ~30-40% of accessibility issues; manual testing is still essential. |
| 9 | 3. **Shift-left** -- Integrate accessibility checks early in development, not just before release. |
| 10 | 4. **Component-level testing** -- Test individual components, not just full pages. |
| 11 | 5. **Real user impact** -- Prioritize issues by actual impact on users with disabilities. |
| 12 | |
| 13 | ## Project Structure |
| 14 | |
| 15 | ``` |
| 16 | tests/ |
| 17 | accessibility/ |
| 18 | pages/ |
| 19 | homepage.a11y.spec.ts |
| 20 | login.a11y.spec.ts |
| 21 | dashboard.a11y.spec.ts |
| 22 | components/ |
| 23 | navigation.a11y.spec.ts |
| 24 | forms.a11y.spec.ts |
| 25 | modals.a11y.spec.ts |
| 26 | utils/ |
| 27 | axe-helper.ts |
| 28 | a11y-reporter.ts |
| 29 | config/ |
| 30 | axe-config.ts |
| 31 | playwright.config.ts |
| 32 | ``` |
| 33 | |
| 34 | ## Setup |
| 35 | |
| 36 | ### Installation |
| 37 | |
| 38 | ```bash |
| 39 | npm install --save-dev @axe-core/playwright axe-core playwright @playwright/test |
| 40 | ``` |
| 41 | |
| 42 | ### Axe Configuration |
| 43 | |
| 44 | ```typescript |
| 45 | // config/axe-config.ts |
| 46 | import { AxeBuilder } from '@axe-core/playwright'; |
| 47 | import { Page } from '@playwright/test'; |
| 48 | |
| 49 | export const DEFAULT_AXE_OPTIONS = { |
| 50 | runOnly: { |
| 51 | type: 'tag' as const, |
| 52 | values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice'], |
| 53 | }, |
| 54 | }; |
| 55 | |
| 56 | export const STRICT_AXE_OPTIONS = { |
| 57 | runOnly: { |
| 58 | type: 'tag' as const, |
| 59 | values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa'], |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | export async function runAxeScan(page: Page, options = DEFAULT_AXE_OPTIONS) { |
| 64 | const results = await new AxeBuilder({ page }) |
| 65 | .options(options) |
| 66 | .analyze(); |
| 67 | return results; |
| 68 | } |
| 69 | |
| 70 | export async function runAxeOnComponent(page: Page, selector: string) { |
| 71 | const results = await new AxeBuilder({ page }) |
| 72 | .include(selector) |
| 73 | .options(DEFAULT_AXE_OPTIONS) |
| 74 | .analyze(); |
| 75 | return results; |
| 76 | } |
| 77 | ``` |
| 78 | |
| 79 | ## Writing Accessibility Tests |
| 80 | |
| 81 | ### Full Page Scan |
| 82 | |
| 83 | ```typescript |
| 84 | import { test, expect } from '@playwright/test'; |
| 85 | import AxeBuilder from '@axe-core/playwright'; |
| 86 | |
| 87 | test.describe('Homepage Accessibility', () => { |
| 88 | test('should have no accessibility violations', async ({ page }) => { |
| 89 | await page.goto('/'); |
| 90 | |
| 91 | const accessibilityScanResults = await new AxeBuilder({ page }) |
| 92 | .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 93 | .analyze(); |
| 94 | |
| 95 | expect(accessibilityScanResults.violations).toEqual([]); |
| 96 | }); |
| 97 | |
| 98 | test('should have no critical or serious violations', async ({ page }) => { |
| 99 | await page.goto('/'); |
| 100 | |
| 101 | const accessibilityScanResults = await new AxeBuilder({ page }).analyze(); |
| 102 | |
| 103 | const criticalViolations = accessibilityScanResults.violations.filter( |
| 104 | (v) => v.impact === 'critical' || v.impact === 'serious' |
| 105 | ); |
| 106 | |
| 107 | expect(criticalViolations).toEqual([]); |
| 108 | }); |
| 109 | |
| 110 | test('should pass accessibility after dynamic content loads', async ({ page }) => { |
| 111 | await page.goto('/'); |
| 112 | |
| 113 | // Wait for dynamic content |
| 114 | await page.getByRole('heading', { name: 'Featured Products' }).waitFor(); |
| 115 | await page.waitForLoadState('networkidle'); |
| 116 | |
| 117 | const results = await new AxeBuilder({ page }) |
| 118 | .withTags(['wcag2a', 'wcag2aa']) |
| 119 | .analyze(); |
| 120 | |
| 121 | expect(results.violations).toEqual([]); |
| 122 | }); |
| 123 | }); |
| 124 | ``` |
| 125 | |
| 126 | ### Component-Level Scanning |
| 127 | |
| 128 | ```typescript |
| 129 | test.describe('Navigation Component Accessibility', () => { |
| 130 | test('navigation menu should be accessible', async ({ page }) => { |
| 131 | await page.goto('/'); |
| 132 | |
| 133 | const results = await new AxeBuilder({ page }) |
| 134 | .include('nav[aria-label="Main navigation"]') |
| 135 | .withTags(['wcag2a', 'wcag2aa']) |
| 136 | .analyze(); |
| 137 | |
| 138 | expect(results.violations).toEqual([]); |
| 139 | }); |
| 140 | |
| 141 | test('navigation should have proper ARIA landmarks', async ({ page }) => { |
| 142 | await page.goto('/'); |
| 143 | |
| 144 | // Check for main navigation landmark |
| 145 | const nav = page.getByRole('navigation', { name: 'Main navigation' }); |
| 146 | await expect(nav).toBeVisible(); |
| 147 | |
| 148 | // Check for skip navigation link |
| 149 | const skipLink = page.getByRole('link', { name: /skip to/i }); |
| 150 | await expect(skipLink).toBeAttached(); |
| 151 | }); |
| 152 | |
| 153 | test('mobile menu should be accessible when opened', async ({ page }) => { |
| 154 | await page.setViewportSize({ width: 375, height: 667 }); |
| 155 | await page.goto('/'); |
| 156 | |
| 157 | // Open mobile men |