AxeWatcher Class
The main class for integrating axe accessibility testing into Selenium Java test suites (use AxeWatcherPlaywright for Playwright)
The AxeWatcher class is the core component of the Axe Watcher Selenium Java integration, which allows you to easily add accessibility testing to your existing end-to-end test suites. This class provides methods to configure browser options and wrap WebDriver instances to enable accessibility analysis during automated testing.
configure() and wrapDriver() each provide an overload per browser: pass ChromeOptions and ChromeDriver to test in Chrome for Testing or Chromium, or EdgeOptions and EdgeDriver to test in Microsoft Edge. Microsoft Edge requires Watcher 4.5.1 or later and Selenium 4 or later.
When integrated into your testing framework, Axe Watcher:
- Automatically analyzes web pages for accessibility problems when tests run
- Re-analyzes pages upon detection of DOM changes
- Links Git commits to accessibility results
- Sends accessibility results to Axe Developer Hub for tracking and analysis
Constructor
AxeWatcher(AxeWatcherOptions options)
Creates a new instance of AxeWatcher with the specified options.
Parameters:
options- The configuration options for Axe Watcher
Example:
AxeWatcherOptions options = new AxeWatcherOptions()
.setApiKey("your-api-key-here")
.setProjectId("your-project-ID-here")
.setServerUrl("https://axe.deque.com");
AxeWatcher watcher = new AxeWatcher(options);Methods
configure(ChromeOptions chromeOptions)
Configures ChromeOptions to enable accessibility testing with Axe Watcher.
This method must be called before creating a ChromeDriver instance.
Parameters:
chromeOptions- The existingChromeOptionsinstance to configure
Returns:
- A new
ChromeOptionsinstance with Axe Watcher configuration applied
Throws:
IllegalArgumentException- If headless or incognito mode is enabled (Axe Watcher does not support these modes)
Example:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);
ChromeOptions chromeOptions = new ChromeOptions();
// Add any additional Chrome options here
ChromeOptions configuredOptions = watcher.configure(chromeOptions);
// Now create ChromeDriver with the configured options
ChromeDriver driver = new ChromeDriver(configuredOptions);configure(EdgeOptions edgeOptions)
Configures EdgeOptions to enable accessibility testing with Axe Watcher in Microsoft Edge.
This method must be called before creating an EdgeDriver instance. Microsoft Edge requires Selenium 4 or later.
Parameters:
edgeOptions- The existingEdgeOptionsinstance to configure
Returns:
- A new
EdgeOptionsinstance with Axe Watcher configuration applied. Only the command-line arguments and the binary path are carried over from the instance you pass in, so set any other capabilities on the returned instance before you construct theEdgeDriver.
Throws:
IllegalArgumentException- If headless or incognito mode is enabled (Axe Watcher does not support these modes)IllegalStateException- If your project uses a version ofselenium-javaolder than 4. Selenium 3'sEdgeOptionstargets the legacy EdgeHTML browser, which Axe Watcher doesn't support.
Example:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);
EdgeOptions edgeOptions = new EdgeOptions();
// configure() carries over the arguments and the binary path set here;
// set any other capabilities on the returned instance instead
edgeOptions.addArguments("--window-size=1280,720");
EdgeOptions configuredOptions = watcher.configure(edgeOptions);
// Now create EdgeDriver with the configured options
EdgeDriver driver = new EdgeDriver(configuredOptions);wrapDriver(ChromeDriver chromeDriver)
Wraps a ChromeDriver instance to enable accessibility testing functionality.
This method must be called after configure() has been used to set up the ChromeDriver.
Parameters:
chromeDriver- TheChromeDriverinstance to wrap
Returns:
- A wrapped
WebDriverinstance with accessibility testing functionality enabled
Throws:
RuntimeException- Ifconfigure()was not called before this method
Example:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);
ChromeOptions chromeOptions = watcher.configure(new ChromeOptions());
ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
// Wrap the ChromeDriver
WebDriver driver = watcher.wrapDriver(chromeDriver);
// Now use the wrapped driver for testing
driver.get("https://example.com");wrapDriver(EdgeDriver edgeDriver)
Wraps an EdgeDriver instance to enable accessibility testing functionality.
This method must be called after configure() has been used to set up the EdgeDriver.
Parameters:
edgeDriver- TheEdgeDriverinstance to wrap
Returns:
- A wrapped
WebDriverinstance with accessibility testing functionality enabled
Throws:
RuntimeException- Ifconfigure()was not called before this method
Example:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options);
EdgeOptions edgeOptions = watcher.configure(new EdgeOptions());
EdgeDriver edgeDriver = new EdgeDriver(edgeOptions);
// Wrap the EdgeDriver
WebDriver driver = watcher.wrapDriver(edgeDriver);
// Now use the wrapped driver for testing
driver.get("https://example.com");enableDebugLogger()
Enables debug logging for Axe Watcher operations. This can be useful for troubleshooting issues during test development.
Returns:
- The current
AxeWatcherinstance for method chaining
Example:
AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("your-api-key-here");
options.setProjectId("your-project-id-here");
AxeWatcher watcher = new AxeWatcher(options).enableDebugLogger();Notes and Limitations
- Axe Watcher does not support full headless mode. Use
--headless=newinstead of--headlessif you need headless operation. - Axe Watcher does not support incognito mode.
- You must call
configure()before creating aChromeDriverorEdgeDriverinstance. - You must call
wrapDriver()after creating theChromeDriverorEdgeDriverinstance. - Microsoft Edge requires Watcher 4.5.1 or later and Selenium 4 or later. The Chrome path (
ChromeOptions/ChromeDriver, used with Chrome for Testing or Chromium) is supported on Selenium 3.141.59 and later. - Call
flush()on the wrapped driver'saxeWatcher()in your test teardown to ensure all results are sent to Axe Developer Hub.
