1. In the root level of your testing folder, install the @axe-core/watcher package and all of its dependencies using npm or your preferred package manager (for example, yarn or pnpm).

    npm install --save-dev @axe-core/watcher
  2. In your wdio.config.js file, import the wdioTestRunner() function, the wrapWdio() function, and the WdioController class from @axe-core/watcher/wdio:

    const {
      wdioTestRunner,
      wrapWdio,
      WdioController
    } = require('@axe-core/watcher/wdio')
  3. Before exporting your WebdriverIO configuration, wrap it with a call to wdioTestRunner() while providing your API key:

    exports.config = {
      // Your config options here...
    }
    
    // Becomes:
    
    const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
    const PROJECT_ID = process.env.PROJECT_ID
    
    exports.config = wdioTestRunner({
      axe: {
        apiKey: ACCESSIBILITY_API_KEY,
        projectId: PROJECT_ID
      }, {
        // Your config options here...
      }
    })

    Be sure to set ACCESSIBILITY_API_KEY and PROJECT_ID in 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).

  4. In your test setup code (typically in a before or beforeAll block), create an instance of the WdioController, and then wrap your browser object:

    const controller = new WdioController(browser)
    wrapWdio(browser, controller)
  5. 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 afterFetch block):

    afterEach(async () => {
      await controller.flush()
    })