Importing and Initializing for WebDriverJS
Importing and initializing the Axe DevTools for Web WebDriverJS package (@axe-devtools/webdriverjs)
Once you've installed Axe DevTools for Web, you need to import it into your testing setup and initialize the package.
Prerequisites
In order to import and initialize Axe DevTools for Web, it needs to be installed first. If you haven't yet, read the guide on how to install it from a bundle, from your artifact repository, or from Deque's Agora. You also need a downloaded and configured Selenium WebDriver of your choice.
Importing and Initializing
Import both Axe DevTools for Web and WebDriverJS. The syntax depends on the language and module system your project uses. Pick the one that matches your project:
JavaScript with CommonJS modules
This is the default for a Node.js project without "type": "module" in its package.json.
const { AxeDevToolsBuilder } = require('@axe-devtools/webdriverjs');
const webdriver = require('selenium-webdriver');JavaScript with ES modules
Use this syntax in a project with "type": "module" in its package.json, or in .mjs files.
import { AxeDevToolsBuilder } from '@axe-devtools/webdriverjs';
import webdriver from 'selenium-webdriver';TypeScript
TypeScript uses the same import syntax as ES modules. @axe-devtools/webdriverjs ships its own type declarations, so there is no separate @types/ package to install. Scan results are typed as AxeResults, which axe-core exports:
import { AxeDevToolsBuilder } from '@axe-devtools/webdriverjs';
import { Builder } from 'selenium-webdriver';
import type { WebDriver } from 'selenium-webdriver';
import type { AxeResults } from 'axe-core';Initializing the Driver
Once you've imported Axe DevTools for Web, you can initialize the driver. Each scan requires its own instance of Axe DevTools for Web, so you'll initialize that while writing tests.
In JavaScript:
const driver = new webdriver.Builder().forBrowser('chrome').build();In TypeScript, using the Builder and WebDriver types imported above:
const driver: WebDriver = new Builder().forBrowser('chrome').build();Next Steps
Once you've installed, imported, and initialized Axe DevTools for Web, you're ready to move on to scanning for accessibility and writing accessibility tests. To do that, see the guide on writing tests.
Troubleshooting
If you have trouble with any of the importing or initializing of Axe DevTools for Web, contact your Deque representative directly, reach us via our support desk, or send us an email. We'll be happy to help.
