Instructions for Cypress and JavaScript

Link to Instructions for Cypress and JavaScript copied to clipboard

Configuring your tests with Cypress and JavaScript

Free Trial
  1. 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/watcher
  2. In 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');
    
    const API_KEY = process.env.API_KEY
    
    module.exports = defineConfig(  
      cypressConfig({
        axe: {
          apiKey: API_KEY
        },
        // Your existing Cypress configuration code here
      })
    );
  3. In your Cypress support file (commonly called cypress/support/e2e.js), import the @axe-core/watcher package Cypress commands and call axeWatcherFlush() after each test:

    require('@axe-core/watcher/dist/cypressCommands');
    
    afterEach(() => {
      cy.axeWatcherFlush();
    });
  4. You're all done. Run your end-to-end tests and check your results. Please note @axe-core/watcher only runs in Chrome 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).