Importing and Initializing for Playwright
Importing and initializing the axe DevTools for Web for Playwright package (@axe-devtools/playwright)
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 a downloaded and configured Playwright version of your choice.
Importing and Initializing
Outside of a module, axe DevTools for Web is imported and an instance created with a statement like this:
const AxeDevtoolsBuilder = require('@axe-devtools/playwright').default;
Importing Playwright will be required as well:
const playwright = require('playwright');
Within a module, the syntax is slightly different. The statement should look like this:
import AxeDevtoolsBuilder from '@axe-devtools/playwright';
Importing Playwright will be required as well:
import * as playwright from 'playwright';
Once you've imported axe DevTools for Web, you can initialize the driver. Each scan requires its own instance of axe DevTools for Web, so you'll initialize that while writing tests.
// This will open up a headless instance of chromium
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
Next Steps
Once you've installed, imported, and initialized axe DevTools for Web, you're ready to move on to scanning for accessibility and writing accessibility tests. To do that, 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.