Skip to Content

Usage

This example shows how to use UserWay Selenium accessibility library to run static analysis on a webpage:

public class MyE2ETests { private static WebDriver driver; private static AuditConfig auditConfig; @BeforeAll static void setup() { var options = new ChromeOptions(); options.addArguments("--headless"); driver = new ChromeDriver(options); // Prepare analysis configuration var 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.builder() .driver(driver) // Add your WebDriver here .analysisConfiguration(analysisConfig) // Attach prepared analysis config .saveReport(true) // Whether analysis reports for CA11Y platform should be saved or not .reportPath("./uw-a11y-reports") // Set directory where analysis results will be saved .elementScreenshots(true) // We will make screenshots of violations on your website // ... more configurations .build(); } @Test @DisplayName("Basic workflow example") void basicWorkflowExampleTest() throws InterruptedException { // Open target page driver.get("https://my.site.com"); // Prepare and wait until page loads with your favourite method driver.manage().timeouts().implicitlyWait(Duration.ofMinutes(1)); // Execute analysis var statistics = AccessibilityAuditor.userwayAnalysis(auditConfig); // Optional: 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.

Last updated on