AxeWatcher Class

Link to AxeWatcher Class copied to clipboard

The main class for integrating axe accessibility testing into Selenium Java test suites

Free Trial
Not for use with personal data

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.

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")
    .setServerUrl("https://axe.deque.com");

AxeWatcher watcher = new AxeWatcher(options);

Methods

configure(ChromeOptions chromeOptions)

Configures ChromeOptions to enable accessibility testing with axe Watcher.

important

This method must be called before creating a ChromeDriver instance.

Parameters:

  • chromeOptions - The existing ChromeOptions instance to configure

Returns:

  • A new ChromeOptions instance 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().setApiKey("your-api-key-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);

wrapDriver(ChromeDriver chromeDriver)

Wraps a ChromeDriver instance to enable accessibility testing functionality.

important

This method must be called after configure() has been used to set up the ChromeDriver.

Parameters:

  • chromeDriver - The ChromeDriver instance to wrap

Returns:

  • A wrapped WebDriver instance with accessibility testing functionality enabled

Throws:

  • RuntimeException - If configure() was not called before this method

Example:

AxeWatcherOptions options = new AxeWatcherOptions().setApiKey("your-api-key-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");

enableDebugLogger()

Enables debug logging for axe Watcher operations. This can be useful for troubleshooting issues during test development.

Returns:

  • The current AxeWatcher instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions().setApiKey("your-api-key-here");
AxeWatcher watcher = new AxeWatcher(options).enableDebugLogger();

Notes and Limitations

  • axe Watcher does not support full headless mode. Use --headless=new instead of --headless if you need headless operation.
  • axe Watcher does not support incognito mode.
  • You must call configure() before creating a ChromeDriver instance.
  • You must call wrapDriver() after creating the ChromeDriver instance.
  • Call flush() on the wrapped driver's axeWatcher() in your test teardown to ensure all results are sent to axe Developer Hub.

See Also