Install and configure
Add as a dev dependency:
npm i -D cypress-axe
Install peer dependencies:
npm i -D cypress axe-core
Include the commands
Cypress/support/index.js file to include the cypress-axe commands by adding:
This will inject the
axe-core runtime into the page under test. You must run this after a call to
cy.visit() and before you run the
You run this command with
cy.injectAxe() either in your test, or in a
beforeEach, as long as the
visit comes first.
To configure the format of the data used by aXe. This can be used to add new rules, which must be registered with the library to execute.
User specifies the format of the JSON structure passed to the callback of axe.run
This will run axe against the document at the point in which it is called. This means you can call this after interacting with your page and uncover accessibility issues introduced as a result of rendering in response to user actions.
Parameters on cy.checkA11y (axe.run)
context: (optional) Defines the scope of the analysis - the part of the DOM that you would like to analyze. This will typically be the document or a specific selector such as class name, ID, selector, etc.
options: (optional) Set of options passed into rules or checks, temporarily modifying them. This contrasts with axe.configure, which is more permanent.
When accessibility violations are detected, your test will fail and an entry titled "A11Y ERROR!" will be added to the command log for each type of violation found (they will be above the failed assertion). Clicking on those will reveal more specifics about the error in the DevTools console.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!