Instructions for Cypress and JavaScript
Configuring your tests with Cypress and JavaScript
-
In the root level of your testing folder, install the
@axe-core/watcherpackage and all of its dependencies usingnpmor your preferred package manager (for example,yarnorpnpm).npm install --save-dev @axe-core/watcher -
In
cypress.config.js, import thecypressConfig()function from the@axe-core/watcherpackage and wrap your config with it:const { defineConfig } = require('cypress'); const { cypressConfig } = require('@axe-core/watcher'); const API_KEY = process.env.API_KEY module.exports = defineConfig( cypressConfig({ axe: { apiKey: API_KEY }, // Your existing Cypress configuration code here }) ); -
In your Cypress support file (commonly called
cypress/support/e2e.js), importcypressCommandsand callaxeWatcherFlush()after each test:require('@axe-core/watcher/dist/cypressCommands'); afterEach(() => { cy.axeWatcherFlush(); }); -
You're all done. Run your end-to-end tests and check your results. Please note
@axe-core/watcheronly runs in Chrome and should only be used in Cypress run mode. It may be used with--headless=newor--headed(for example,cypress run --headed --browser=chrome).
