Importing and Initializing Puppeteer for JavaScript
Importing and initializing the Axe DevTools for Web Puppeteer JavaScript package (@axe-devtools/puppeteer)
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 will also need Puppeteer installed.
Importing and Initializing
Import both Axe DevTools for Web and Puppeteer. 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 { AxeDevToolsPuppeteer } = require('@axe-devtools/puppeteer');
const puppeteer = require('puppeteer');JavaScript with ES modules
Use this syntax in a project with "type": "module" in its package.json, or in .mjs files.
import { AxeDevToolsPuppeteer } from '@axe-devtools/puppeteer';
import puppeteer from 'puppeteer';TypeScript
TypeScript uses the same import syntax as ES modules. @axe-devtools/puppeteer 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 { AxeDevToolsPuppeteer } from '@axe-devtools/puppeteer';
import puppeteer from 'puppeteer';
import type { AxeResults } from 'axe-core';For each scan, a new AxeDevToolsPuppeteer object will be created. To see how to do this, see the guide on writing tests.
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.
