WebDriverJS API Reference for Axe DevTools for Web

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

Reference for the APIs in the @axe-devtools/webdriverjs package

Not for use with personal data

Constructor

In the standard configuration, the only argument required to be passed to the Axe DevTools constructor is the WebDriverJS instance. If you wish to use a different axe-core version than originally included or a custom ruleset, you can pass these options to the constructor.

note

You cannot select a nonstandard axe-core version and a custom rule set.

Axe DevTools WebDriverJS constructor:

AxeDevToolsBuilder(driver:WebDriver, String:ruleset|Object:axe (optional))

You must pass an instance of a Selenium WebDriver as the first argument. The second optional argument may be either a ruleset ID or an axe object. If you do not provide a second argument, you must configure the @axe-devtools/script-builder custom rule configuration file, or the constructor will throw an exception.

These examples show how to use the constructor:

// instantiate with the Section 508 rule set
const builder = new AxeDevToolsBuilder(driver, '508');

// or with a specific axe instance
const axe = require('../axe-core-2.3.0');
const builder = new AxeDevToolsBuilder(driver, axe);

Custom Rules

For information on using custom rules with Axe DevTools for Web, read the guide on custom ruleset generation and integration in the CLI guide.

analyze

The analyze() method runs the analysis and returns accessibility scan results.

analyze(): Promise<axe.AxeResults>

Run an analysis using the default configuration on the given client. A Promise is returned, which resolves with the accessibility result set returned by axe-core.

analyzeUniversal

The analyzeUniversal() method runs the analysis and returns results in the Axe Universal Format. The existing analyze() method is unchanged.

analyzeUniversal(): Promise<UniversalExport>

Chain Options

Two options exist for scoping your Axe DevTools scans. You can choose to include or exclude specific CSS scopes. The chain methods (below) on the constructor make this possible.

include

new AxeDevToolsBuilder(driver).include('<CSS-Selector>');

Adds a CSS selector to the list of elements to include in the analysis. Elements outside the scope passed to include() will not be scanned.

exclude

new AxeDevToolsBuilder(driver).exclude('<CSS-Selector>');

Add a CSS selector to the list of elements to exclude from analysis. Only elements outside the scope passed to exclude() will be scanned.

These methods can be chained to refine the scan scope further, as shown below:

new AxeDevToolsBuilder(driver).include('<CSS-Selector>').exclude('<Inner-CSS-Selector>');

In this example, all elements within <CSS-Selector> would be scanned, except for the elements inside <Inner-CSS-Selector>.

Rule Configuration

The rule configuration methods overwrite the standard rule configuration. Additional calls with these methods will overwrite previous calls.

withRules

The withRules() method limits analysis to only those rules with the specified rule IDs. It accepts a string for a single rule ID or an array of multiple rule IDs.

These examples show using withRules with a single rule ID and an array of rule IDs:

//with a single rule ID
AxeDevToolsBuilder(driver).withRules('html-lang');

//with an array of rule IDs
AxeDevToolsBuilder(driver).withRules(['html-lang', 'image-alt']);

withTags

The withTags() method limits analysis to only those rules associated with the provided tag. Accepts a single tag or an array of tags, as shown below:

//with a single tag
AxeDevToolsBuilder(driver).withTags('wcag2a');

//with an array of tags
AxeDevToolsBuilder(driver).withTags(['wcag2a', 'wcag2aa']);

disableRules

AxeDevToolsBuilder.disableRules(rules: RuleID[]): AxeDevToolsBuilder

The disableRules() method causes the array of rules provided to be skipped when running an analysis.

axe-core options

options

.options(options: Axe.RunOptions)

The options method specifies options to be used by axe.run. It will override any other configured options, including calls to withRules and withTags. See the axe-core API documentation for information.

new AxeDevToolsBuilder(page).options({
  checks: { 'valid-lang': ['orcish'] }
});

configure

.configure(config: Axe.Spec)

The configure method injects an axe configuration object to modify the ruleset before an analysis. Subsequent calls to this method will invalidate previous ones by calling axe.configure() and replacing the configuration object. See axe-core API documentation for the object's structure.

The following example creates a new axe-core configuration and passes it to Axe DevTools to be used for scanning:

const config = {
  checks: [Object],
  rules: [Object]
};
const results = await new AxeDevToolsBuilder(page).configure(config).analyze();

Usage Service

By default, the usage service is enabled, and the default URL is https://usage.deque.com. Set the AXE_TRACK_USAGE environment variable to false to disable it.

Environment Variables

These environment variables allow you to configure the usage service and change the properties of reported events.

Name Type Can Override Description
AXE_DISTINCT_ID String A UUID identifier that remains the same for the logged-in user (unless it is regenerated). In Ruby, this variable is named DEQUE_DISTINCT_ID.
AXE_INCLUDE_TEST_RESULTS Boolean Set to true to include the full axe-core results in the testResults object of each event (default is false). Supported by the CLI and the Node.js APIs only.
AXE_METRICS_URL String The URL of the REST usage endpoint (default is https://usage.deque.com)
AXE_TRACK_USAGE Boolean Set to false to disable usage service reporting. Reporting is enabled by default.
AXE_APPLICATION String false The application that was used to check for accessibility errors
AXE_DEV_INSTANCE Boolean true Indicates whether this event is from a software developer's actions. Useful for marking and later removing events logged during development or testing.
AXE_DEPARTMENT String true The user's department within the organization
AXE_KEYCLOAK_ID String false The user's Keycloak ID
AXE_LOGGED_IN Boolean false Records whether the user is logged in to the application under test
AXE_ORGANIZATION String true The user's organization. To have your usage appear in Axe Reports, set this to your organization's ID (contact Deque to obtain it).
AXE_SESSION_ID String false A UUID identifying the user's session
AXE_USER_ID String false A specific user's identity such as an email address, name, or login ID. Axe Reports counts unique users from this value.
AXE_USER_JOB_ROLE String false The user's job role
AXE_USER_STATUS String false Status information you want to associate with the user

enableTracking

This method allows users to opt in to or out of sending data to the usage service. Sending is enabled by default.

.enableTracking(state: boolean)
AxeDevToolsBuilder(driver).enableTracking(true)

setTrackingUrl

This method allows users to change where the usage metrics data are sent.

.setTrackingUrl(url: string)
AxeDevToolsBuilder(driver).setTrackingUrl('https://foobar.biz')

setDistinctId

This method allows users to change the distinct ID being stored or used.

.setDistinctId(distinctId: string)
AxeDevToolsBuilder(driver).setDistinctId('foobar')