Importing and Initializing for WebdriverIO

Link to Importing and Initializing for WebdriverIO copied to clipboard

Importing and initializing the axe DevTools for Web WebdriverIO package (@axe-devtools/webdriverio)

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 to have WebdriverIO downloaded and configured.

Importing and Initializing

Outside of a module, axe DevTools for Web is imported and an instance created with a statement like this:

const { AxeDevToolsWebdriverIO } = require('@axe-devtools/webdriverio');

Importing WebdriverIO will be required as well:

const webdriverio = require('webdriverio');

Within a module, the syntax is slightly different. The statement should look like this:

import { AxeDevToolsWebdriverIO } from '@axe-devtools/webdriverio';

Importing WebdriverIO will be required as well:

import webdriverio from 'webdriverio';

At this point, you'll be able to initialize your webdriver inside your testing function like this:

const client = webdriverio.remote({
  desiredCapabilities: {
    browserName: 'chrome'
  }
});

await client.init();

Then, you can initalize axe DevTools for Web with the webdriver client

const axeDevTools = new AxeDevToolsWebdriverIO({ client });

Next Steps

Once you've installed, imported, and initialized axe DevTools for Web and its driver, you're ready to move on to scanning for accessibility and writing accessibility tests. Each scan with axe DevTools for Web requires a new instance, so to set up and run your scans 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.