Instructions for WebDriverJS and JavaScript
Configuring your tests with WebDriverJS and JavaScript
-
In the root level of your testing folder, install the
@axe-core/watcher
package and all of its dependencies usingnpm
or your preferred package manager (for example,yarn
orpnpm
).npm install --save-dev @axe-core/watcher
-
In your test file or files, import the
webdriverConfig()
function, thewrapWebdriver()
function, and theWebdriverController
class from@axe-core/watcher
:const { webdriverConfig, wrapWebdriver, WebdriverController } = require('@axe-core/watcher')
-
Update your test setup code (typically in a
before
orbeforeAll
block), specifying Chrome options when instantiating yourbrowser
instance, providing your API key:// Original code: let browser = await new Builder() .forBrowser('chrome') .build() // Becomes: const API_KEY = process.env.API_KEY let browser = await new Builder() .forBrowser('chrome') .setChromeOptions( webdriverConfig({ axe: { apiKey: API_KEY } } ) .build()
-
Create an instance of the
WebdriverController
:const controller = new WebdriverController(browser)
-
Wrap your
browser
instance 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
afterEach
block):afterEach(async () => { await controller.flush() })