In the root level of your testing folder, install the @axe-core/watcher package and all of its dependencies using npm or your preferred package manager (for example, yarn or pnpm).
npm install --save-dev @axe-core/watcherIn cypress.config.js, import the cypressConfig() function from the @axe-core/watcher package and wrap your config with it:
const { defineConfig } = require('cypress');
const { cypressConfig } = require('@axe-core/watcher/cypress/config');
const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
const PROJECT_ID = process.env.PROJECT_ID
module.exports = defineConfig(
cypressConfig({
axe: {
apiKey: ACCESSIBILITY_API_KEY,
projectId: PROJECT_ID
},
// Your existing Cypress configuration code here
})
);Be sure to set ACCESSIBILITY_API_KEY and PROJECT_ID in your environment to your personal API key (found in your axe Account, API KEYS tab) and your project ID (shown at the top of these instructions when you created your project or available from the Projects page by choosing Configure project under Settings).
In your Cypress support file (commonly called cypress/support/e2e.js), import cypressCommands and call axeWatcherFlush() after each test:
require('@axe-core/watcher/cypress/support');
afterEach(() => {
cy.axeWatcherFlush();
});You're all done. Run your end-to-end tests and check your results. Please note @axe-core/watcher only runs in Chrome for Testing or Chromium and should only be used in Cypress run mode. It may be used with --headless=new or --headed (for example, cypress run --headed --browser=chrome-for-testing).