AxeWatcher Class

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

The main class for integrating axe accessibility testing into Selenium Java test suites (use AxeWatcherPlaywright for Playwright)

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.

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.

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();
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.

important

This method must be called before creating an EdgeDriver instance. Microsoft Edge requires Selenium 4 or later.

Parameters:

  • edgeOptions - The existing EdgeOptions instance to configure

Returns:

  • A new EdgeOptions instance 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 the EdgeDriver.

Throws:

  • IllegalArgumentException - If headless or incognito mode is enabled (Axe Watcher does not support these modes)
  • IllegalStateException - If your project uses a version of selenium-java older than 4. Selenium 3's EdgeOptions targets 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.

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();
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.

important

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

Parameters:

  • edgeDriver - The EdgeDriver 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();
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 AxeWatcher instance 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=new instead of --headless if you need headless operation.
  • Axe Watcher does not support incognito mode.
  • You must call configure() before creating a ChromeDriver or EdgeDriver instance.
  • You must call wrapDriver() after creating the ChromeDriver or EdgeDriver instance.
  • 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's axeWatcher() in your test teardown to ensure all results are sent to Axe Developer Hub.

See Also