Instructions for WebdriverIO and JavaScript
Configuring your tests with WebdriverIO 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 files, import the
wdioConfig()
function, thewrapWdio()
function, and theWdioController
class from@axe-core/watcher
:const { wdioConfig, wrapWdio, WdioController } = require('@axe-core/watcher')
-
In your test setup code (typically in a
before
orbeforeAll
block), wrap any existing code for creating abrowser
instance with a call towdioConfig()
, while providing your API key:const browser = await wdio.remote( wdioConfig({ axe: { apiKey: process.env.API_KEY } }) )
-
Once you have a
browser
instance, create an instance of theWdioController
class:const controller = new WdioController(browser)
-
Wrap your
browser
instance with thewrapWdio()
function, providing thebrowser
instance and thecontroller
instance:wrapWdio(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() })