AxeWatcherOptions Class

Link to AxeWatcherOptions Class copied to clipboard

Configure axe Watcher for accessibility testing in Selenium Java tests with customizable options

Free Trial
Not for use with personal data

The AxeWatcherOptions class provides configuration options for the axe Watcher Selenium Java integration. This class allows you to customize how axe Watcher performs accessibility testing during automated browser tests, including server connection details, test execution behavior, and accessibility standards.

Constructor

AxeWatcherOptions()

Creates a new instance of AxeWatcherOptions with default settings. The default values are:

  • serverUrl: https://axe.deque.com
  • autoAnalyze: true
AxeWatcherOptions options = new AxeWatcherOptions();

Methods

setApiKey(String apiKey)

Sets the API key to authenticate with axe Developer Hub. This is required to use axe Watcher.

Parameters:

  • apiKey - Your axe Developer Hub API key

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

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

setServerUrl(String serverUrl)

Sets the server URL to send accessibility results. Defaults to https://axe.deque.com.

Parameters:

  • serverUrl - URL of the server to send accessibility results to

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setServerUrl("https://custom.axe-instance.com");

setBuildId(String buildId)

Sets the build ID for parallel test runners. When not null, this allows parallel test runners to generate results that appear as a single test run in axe Developer Hub.

Parameters:

  • buildId - Build ID to aggregate results under, typically a CI/CD build ID

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Using a CI build ID from an environment variable
options.setBuildId(System.getenv("GITHUB_RUN_ID"));

setAutoAnalyze(boolean autoAnalyze)

Sets whether to analyze the page under test automatically. Defaults to true.

Parameters:

  • autoAnalyze - Whether to automatically analyze the page under test

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Disable automatic analysis for manual control
options.setAutoAnalyze(false);

setRunContext(AxeRunContext runContext)

Sets the context of the page under test to either limit the scope of what is analyzed or exclude certain elements from analysis.

Parameters:

  • runContext - Run context for axe-core analysis

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Only analyze main content and exclude navigation
AxeRunContext context = new AxeRunContext()
    .setInclude(Arrays.asList("#main-content"))
    .setExclude(Arrays.asList("#navigation"));
options.setRunContext(context);

setRunOptions(AxeRunOptions runOptions)

Sets additional options for axe-core analysis, such as which rules to execute or disable.

Parameters:

  • runOptions - Run options for axe-core analysis

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Disable the color contrast rule and focus on WCAG 2.1 AA
Map<String, AxeRuleOptions> rules = new HashMap<>();
rules.put("color-contrast", new AxeRuleOptions().setEnabled(false));

AxeRunOnly runOnly = new AxeRunOnly()
    .setType("tag")
    .setValues(Arrays.asList("wcag21aa"));

AxeRunOptions runOptions = new AxeRunOptions()
    .setRules(rules)
    .setRunOnly(runOnly);

options.setRunOptions(runOptions);

setExcludeUrlPatterns(String[] excludeUrlPatterns)

Sets URL patterns to exclude from analysis. Uses the Minimatch library to match URLs.

Parameters:

  • excludeUrlPatterns - URL patterns to exclude from analysis

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Exclude login pages and admin dashboard
options.setExcludeUrlPatterns(new String[] {
    "https://example.com/login*",
    "https://example.com/admin/*"
});

setConfigurationOverrides(ConfigurationOverrides configurationOverrides)

Sets configuration overrides based on your organization's axe Account global configuration settings.

Parameters:

  • configurationOverrides - Configuration overrides

Returns:

  • AxeWatcherOptions - The current instance for method chaining

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
// Override to use WCAG 2.2 AA and enable best practices
ConfigurationOverrides overrides = new ConfigurationOverrides()
    .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    .setEnableBestPractices(true);
options.setConfigurationOverrides(overrides);

getApiKey()

Gets the current API key.

Returns:

  • String - The current API key

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setApiKey("my-api-key");
String apiKey = options.getApiKey(); // Returns "my-api-key"

getServerUrl()

Gets the current server URL.

Returns:

  • String - The current server URL

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
String serverUrl = options.getServerUrl(); // Returns default "https://axe.deque.com"

getBuildId()

Gets the current build ID.

Returns:

  • String - The current build ID

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setBuildId("build-123");
String buildId = options.getBuildId(); // Returns "build-123"

getAutoAnalyze()

Gets whether automatic analysis is enabled.

Returns:

  • boolean - Whether automatic analysis is enabled

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
boolean autoAnalyze = options.getAutoAnalyze(); // Returns true (default)

getRunContext()

Gets the current run context.

Returns:

  • AxeRunContext - The current run context

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunContext context = new AxeRunContext();
options.setRunContext(context);
AxeRunContext currentContext = options.getRunContext();

getRunOptions()

Gets the current run options.

Returns:

  • AxeRunOptions - The current run options

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
AxeRunOptions runOptions = new AxeRunOptions();
options.setRunOptions(runOptions);
AxeRunOptions currentOptions = options.getRunOptions();

getExcludeUrlPatterns()

Gets the current exclude URL patterns.

Returns:

  • String[] - The current exclude URL patterns

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
options.setExcludeUrlPatterns(new String[] {"https://example.com/login*"});
String[] patterns = options.getExcludeUrlPatterns();

getConfigurationOverrides()

Gets the current configuration overrides.

Returns:

  • ConfigurationOverrides - The current configuration overrides

Example:

AxeWatcherOptions options = new AxeWatcherOptions();
ConfigurationOverrides overrides = new ConfigurationOverrides();
options.setConfigurationOverrides(overrides);
ConfigurationOverrides current = options.getConfigurationOverrides();

toJson()

Serializes the AxeWatcherOptions instance to a JSON string.

Returns:

  • String - A JSON string representation of the options

Throws:

  • RuntimeException - If configurationOverrides and runOptions.runOnly are used together (these are mutually exclusive)

Example:

AxeWatcherOptions options = new AxeWatcherOptions()
    .setApiKey("my-api-key")
    .setServerUrl("https://custom.axe-instance.com");
String json = options.toJson();

Configuration Limitations

When configuring AxeWatcherOptions, be aware of the following constraints:

  1. The API key is required:

    options.setApiKey("your-api-key"); // Required
  2. Mutually exclusive options:

    You cannot use both runOptions.runOnly and configurationOverrides.accessibilityStandard together. If you need to set a specific accessibility standard, use ConfigurationOverrides as shown below:

    // Correct: Using ConfigurationOverrides
    options.setConfigurationOverrides(
        new ConfigurationOverrides()
            .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    );
    
    // Correct: Using RunOptions.runOnly
    options.setRunOptions(
        new AxeRunOptions()
            .setRunOnly(new AxeRunOnly().setType("tag").setValues(Arrays.asList("wcag22aa")))
    );
    
    // Incorrect: Using both together will throw an exception
    options.setConfigurationOverrides(
        new ConfigurationOverrides()
            .setAccessibilityStandard(ConfigurationOverrides.AccessibilityStandard.WCAG22AA)
    ).setRunOptions(
        new AxeRunOptions()
            .setRunOnly(new AxeRunOnly().setType("tag").setValues(Arrays.asList("wcag21aa")))
    );

See Also