0
0
Cypresstesting~10 mins

cypress-axe for accessibility - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Cypress
Cypress
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();
  });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, Cypress ready to run tests-PASS
2Browser opens and navigates to 'https://example.cypress.io'Example Cypress page loaded in browserPage loaded successfully with status 200PASS
3Inject axe-core accessibility testing library into the pageaxe-core script injected and ready to run accessibility checksaxe-core script is present in the page contextPASS
4Run accessibility checks on the entire page using cy.checkA11y()axe-core analyzes page elements for accessibility issuesNo accessibility violations foundPASS
5Test endsTest completed with no accessibility violations-PASS
Failure Scenario
Failing Condition: Accessibility violations are found on the page during cy.checkA11y()
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.injectAxe() do in the test?
AIt adds the axe-core accessibility testing library to the page
BIt navigates to the test page URL
CIt runs the accessibility checks
DIt clicks on a button to start the test
Key Result
Using cypress-axe helps catch accessibility issues early by automatically scanning pages during tests, ensuring your site is usable by everyone.