Usage
This example shows how to use UserWay Selenium accessibility library to run static analysis on a webpage:
public class MyE2ETests {
@Test
@DisplayName("Basic workflow example")
void basicWorkflowExampleTest() throws InterruptedException {
// Initialize and configure your Selenium driver as you like
WebDriver driver = new ChromeDriver();
// Open target page
driver.get("https://my.site.com");
// Prepare and wait until page loads with your favourite method
Thread.sleep(2000);
// Prepare configuration for static analysis script
AnalysisConfig analysisConfig = AnalysisConfig.builder()
.level(Level.AA) // Analyse for A- and AA-level violations only
.ignoreSelectors(Set.of("button", "div")) // Do not analyse HTML elements that have these selectors
// ... more configurations
.build();
// Prepare configuration for Selenium accessibility audit
AuditConfig auditConfig = AuditConfig.builder()
.driver(driver) // Add your WebDriver here
.analysisConfiguration(analysisConfig) // Attach prepared analysis config
.reportPath("./e2e-a11y-results") // Set directory where analysis results will be saved
.screenshots(true) // We will make screenshots of violations on your website
// ... more configurations
.build();
// Execute analysis
AccessibilityStati statistics = AccessibilityAuditor.userwayAnalysis(auditConfig);
// Use analysis results for your assertions
assertThat(statistics.status()).isEqualTo(AnalysisStatus.SUCCEEDED);
assertThat(statistics.issuesFound()).isLessThan(10);
// ... more assertions
}
}
By default, UserWay Selenium scans the page for AA violations and neither saves JSON report nor makes screenshots, but you can easily customize its behavior.