Importing and Initializing for WebdriverIO

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

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

Not for use with personal data

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

Import both Axe DevTools for Web and WebdriverIO. The syntax depends on the language and module system your project uses. Pick the one that matches your project:

JavaScript with CommonJS modules

This is the default for a Node.js project without "type": "module" in its package.json.

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

JavaScript with ES modules

Use this syntax in a project with "type": "module" in its package.json, or in .mjs files.

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

TypeScript

TypeScript uses the same import syntax as ES modules. @axe-devtools/webdriverio ships its own type declarations, so there is no separate @types/ package to install. Scan results are typed as AxeResults, which axe-core exports:

import { AxeDevToolsWebdriverIO } from '@axe-devtools/webdriverio';
import { remote } from 'webdriverio';
import type { AxeResults } from 'axe-core';

Initializing the Client

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

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

In TypeScript, the client is a WebdriverIO.Browser, which is the type AxeDevToolsWebdriverIO expects:

const client: WebdriverIO.Browser = await remote({
  capabilities: {
    browserName: 'chrome'
  }
});

Then, you can initialize Axe DevTools for Web with the webdriver client. This statement is the same in both languages:

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.