Instructions for WebDriverJS and JavaScript
Configuring your tests with WebDriverJS and JavaScript
Axe Watcher requires a supported browser already installed on your system: Chrome for Testing (a separate browser install, distinct from Google Chrome), Chromium, or Microsoft Edge. Google Chrome, version 139 or later, is not supported. See Setting Up and Configuring Browsers for Use with Axe Watcher for installation and configuration instructions.
-
In the root level of your testing folder, install the
@axe-core/watcherpackage and all of its dependencies usingnpmor your preferred package manager (for example,yarnorpnpm).npm install --save-dev @axe-core/watcher -
In your test file or files, import the
webdriverConfig()function, thewrapWebdriver()function, and theWebdriverControllerclass from@axe-core/watcher/webdriver:const { webdriverConfig, wrapWebdriver, WebdriverController } = require('@axe-core/watcher/webdriver') -
Update your test setup code (typically in a
beforeorbeforeAllblock), specifying Chrome options when instantiating yourbrowserinstance, providing your API key:// Original code: let browser = await new Builder() .forBrowser('chrome') .build() // Becomes: const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY const PROJECT_ID = process.env.PROJECT_ID const SERVER_URL = process.env.SERVER_URL let browser = await new Builder() .forBrowser('chrome') .setChromeOptions( webdriverConfig({ axe: { apiKey: ACCESSIBILITY_API_KEY, projectId: PROJECT_ID, serverURL: SERVER_URL } } ) .build()Be sure to set
ACCESSIBILITY_API_KEYandPROJECT_IDin your environment to your personal API key (found in your Axe Account, API KEYS tab) and your project ID (shown at the top of these instructions when you created your project or available from the Projects page by choosing Configure project under Settings). If your organization uses a regional, private cloud, or on-premises Axe Developer Hub instance, also setSERVER_URLto the base URL of that instance (for example,https://axe-eu.deque.com); otherwise, omitSERVER_URLand the defaulthttps://axe.deque.comwill be used. -
Create an instance of the
WebdriverController:const controller = new WebdriverController(browser)noteIf you enable screenshot capture (
takeScreenshots: true), note thatWebdriverControllerdoes not implement screenshot capture in@axe-core/watcher4.6.0. To capture screenshots, subclassWebdriverController, overridecaptureScreenshot()to call Selenium's owntakeScreenshot()method, and instantiate your subclass instead:class ScreenshotWebdriverController extends WebdriverController { async captureScreenshot() { return await this.driver.takeScreenshot() } } const controller = new ScreenshotWebdriverController(browser) -
Wrap your
browserinstance with thewrapWebdriver()function:browser = wrapWebdriver(browser, controller) -
Finally, ensure all test results from Axe Watcher are flushed out. To do this, add the following block of code to your test teardown code (typically in an
afterEachblock):afterEach(async () => { await controller.flush() })
