| name | accessibility-selenium-testing |
| description | Toolkit for validating Web Content Accessibility Guidelines (WCAG) compliance using Selenium WebDriver (Java) and the Axe Core engine. Supports full-page analysis, component-specific scanning, and rule filtering. |
Accessibility Testing with Selenium WebDriver & Axe Core
This skill enables automated accessibility analysis within the existing Selenium WebDriver framework. It utilizes the Axe-core engine to detect WCAG violations (A, AA, AAA) and Best Practice issues directly in the browser.
When to use this skill
Use this skill when you need to:
- Validate WCAG Compliance: Ensure pages meet WCAG 2.1 or 2.2 Level A and AA standards.
- Audit UI Components: Scan specific modals, forms, keyboard navigation, color contrast ratios, or widgets in isolation.
- Gatekeeping: Prevent critical accessibility violations (like missing generic labels or low contrast) from reaching production.
- Verification: Ensure accessibility (ARIA attributes) is maintained across releases, preventing regressions.
- Regression Testing: Verify that new UI changes haven't introduced accessibility barriers.
- Reporting: Generate readable reports of accessibility violations for developers.
- Filter Rules: Exclude specific known issues or false positives from test failures.
WCAG Levels
- Level A: Basic accessibility (must have)
- Level AA: Intermediate accessibility (should have, legal requirement in many jurisdictions)
- Level AAA: Advanced accessibility (nice to have)
Your Role
As an Accessibility Automation Specialist, your role involves:
- Integration: Injecting the Axe script into the WebDriver instance.
- Configuration: Setting up the
AxeBuilder with specific tags (e.g., "wcag2aa", "best-practice").
- Analysis: Parsing the JSON result from Axe to identify violations.
- Assertion: Failing the test only when legitimate violations exceed the threshold.
- Reporting: Logging specific details (Help URL, HTML target, Impact) to the console or report files.
Reference Documentation
Before starting any test creation, read these files to understand the standards:
Prerequisites
- Java JDK 21
- Maven Dependency:
com.deque.html.axe-core/selenium (Latest version)
- Selenium WebDriver instance (ChromeDriver/EdgeDriver)
- AssertJ (Recommended for readable failure messages)
- Gson/Jackson (Usually included with Axe) for parsing reports.
Core Capabilities
1. Axe Builder Implementation
Utilize the Fluent API AxeBuilder to configure the scan:
- Full Page Scan:
new AxeBuilder().analyze(driver)
- Component Scan:
new AxeBuilder().include(By.id("my-component")).analyze(driver)
- Rule Configuration:
.withTags(Arrays.asList("wcag2a", "wcag2aa"))
- Exclusions:
.exclude(By.cssSelector(".legacy-footer")) (Use carefully)
2. Validation & Assertion
- Violation Checking: Analyze the
Results object. results.getViolations() should be empty.
- Impact Filtering: Filter violations by impact level (Critical, Serious, Moderate, Minor).
- Soft Assertions: Use AssertJ or SoftAssertions to report all accessibility errors found on a page before failing the test.
3. Reporting
- Console Logging: Print readable violation summaries (Rule ID + Help URL + Selector).
- Report Generation: Serialize the
Results object to JSON for external tools/dashboards.
Code Style & Patterns
Use the following patterns for robust accessibility testing implementation:
Basic Full-Page Analysis
public void verifyPageAccessibility(WebDriver driver) {
Results results = new AxeBuilder()
.withTags(List.of("wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "best-practice"))
.analyze(driver);
logViolations(results.getViolations());
assertThat(results.violationFree())
.as("Accessibility violations found on page: %s", driver.getCurrentUrl())
.isTrue();
}
Component-Specific Scanning
public void verifyComponentAccessibility(WebDriver driver, String... cssSelectors) {
AxeBuilder builder = new AxeBuilder()
.withTags(List.of("wcag2a", "wcag2aa"));
for (String selector : cssSelectors) {
builder.include(selector);
}
Results results = builder.analyze(driver);
assertThat(results.violationFree())
.as("Component accessibility check failed")
.isTrue();
}
Excluding Known Issues (Use Sparingly)
public void verifyAccessibilityWithExclusions(WebDriver driver) {
Results results = new AxeBuilder()
.withTags(List.of("wcag2a", "wcag2aa"))
.exclude(".third-party-widget")
.exclude(".legacy-component")
.disableRules(List.of("color-contrast"))
.analyze(driver);
assertThat(results.violationFree())
.as("Accessibility violations found on page: %s", driver.getCurrentUrl())
.isTrue();
}
JUnit 5 Integration Example
class AccessibilityTest {
@Test
void homePage_shouldBeAccessible() {
driver.get("https://example.com");
Results results = new AxeBuilder()
.withTags(List.of("wcag2a", "wcag2aa", "wcag21aa"))
.analyze(driver);
assertThat(results.violationFree())
.as("Homepage should meet WCAG 2.1 AA standards")
.isTrue();
List<Rule> criticalViolations = results.getViolations().stream()
.filter(v -> List.of("critical", "serious").contains(v.getImpact()))
.toList();
}
}
Manual Testing Checklist
Keyboard Navigation
Screen Readers
Visual
Best Practices Checklist
ā
Test "Ready" States: Ensure the DOM is fully loaded and stable (no spinners) before triggering Axe analysis.
ā
Scan Unique States: Don't scan the header/footer in every test. Focus scans on unique page states (e.g., "Modal Open", "Form Error State").
ā
Zero Tolerance for Critical: Always fail the build on "Critical" and "Serious" impacts.
ā
Use Specific Tags: Define if you are testing for wcag2a, wcag2aa, or best-practice to avoid noise.
ā
Avoid "Sleeps": Axe injects JavaScript; ensure standard explicit waits are used before the injection.
ā
Readable Failures: Do not just print "Test Failed". Print the Help URL provided by Axe so developers can fix it.
ā
Component Isolation: If testing a large legacy app, include() specific new components to test them in isolation.