AxeWatcher Class
The main class for integrating axe accessibility testing into Selenium Java test suites
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.
This method must be called before creating a ChromeDriver
instance.
Parameters:
chromeOptions
- The existingChromeOptions
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.
This method must be called after configure()
has been used to set up the ChromeDriver
.
Parameters:
chromeDriver
- TheChromeDriver
instance to wrap
Returns:
- A wrapped
WebDriver
instance with accessibility testing functionality enabled
Throws:
RuntimeException
- Ifconfigure()
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 aChromeDriver
instance. - You must call
wrapDriver()
after creating theChromeDriver
instance. - Call
flush()
on the wrapped driver'saxeWatcher()
in your test teardown to ensure all results are sent to axe Developer Hub.