Test Overview
This test uses cypress-axe to check if the web page meets accessibility standards. It loads the page, injects the accessibility tool, runs the accessibility checks, and verifies there are no violations.
This test uses cypress-axe to check if the web page meets accessibility standards. It loads the page, injects the accessibility tool, runs the accessibility checks, and verifies there are no violations.
import 'cypress-axe'; describe('Accessibility check with cypress-axe', () => { it('should have no accessibility violations on load', () => { cy.visit('https://example.cypress.io'); cy.injectAxe(); cy.checkA11y(); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, Cypress ready to run tests | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io' | Example Cypress page loaded in browser | Page loaded successfully with status 200 | PASS |
| 3 | Inject axe-core accessibility testing library into the page | axe-core script injected and ready to run accessibility checks | axe-core script is present in the page context | PASS |
| 4 | Run accessibility checks on the entire page using cy.checkA11y() | axe-core analyzes page elements for accessibility issues | No accessibility violations found | PASS |
| 5 | Test ends | Test completed with no accessibility violations | — | PASS |
cypress-axe in Cypress tests?cy.injectAxe().cy.runAxe(), cy.loadAxe(), and cy.startAxe() are not valid Cypress commands for this purpose.cy.checkA11y() do?cy.visit('/home')
cy.injectAxe()
cy.checkA11y()cy.checkA11y() without arguments.cy.checkA11y() runs accessibility checks on the whole page and reports violations.cy.visit('/dashboard')
cy.checkA11y()cy.injectAxe().cy.checkA11y() does not run properly and silently fails.main-content. Which code snippet correctly does this using cypress-axe?cy.injectAxe() without arguments to add axe to the page.cy.checkA11y('#main-content') to check accessibility only inside that element.Pass the test and this pattern moves unknown