Cypress · Browser testing end to end
How do you test accessibility with Cypress?
Short answer
Use cypress-axe to inject axe-core and run cy.checkA11y on a page or component. Automated checks catch structural issues, but keyboard, focus and screen-reader behaviour still need manual tests.
Automated accessibility checks catch a useful subset of problems: missing labels, invalid ARIA, low contrast in some cases, duplicate IDs and landmark issues. They do not prove the interface is usable with a keyboard or a screen reader, so they complement manual checks rather than replacing them.
import "cypress-axe";
describe("signup accessibility", () => {
beforeEach(() => {
cy.visit("/signup");
cy.injectAxe();
});
it("has no detectable violations", () => {
cy.checkA11y();
});
it("reports a violation after an error state", () => {
cy.get("[data-cy=submit]").click();
cy.checkA11y("[data-cy=signup-form]");
});
});What to add beyond axe
- Tab through the page and confirm focus order and visible focus
- Operate dialogs, menus and forms without a mouse
- Test that errors are announced through a live region
- Check that a modal traps focus and restores it on close
- Verify contrast and that colour is not the only signal
Configure the axe rules you care about rather than ignoring categories wholesale. A small, intentional rule set in CI catches regressions without turning every minor advisory into a hard failure. For component tests, run checkA11y after mounting so the DOM is ready.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does cy.injectAxe do?
- 2Which accessibility issues does axe not catch?
- 3How do you scope an accessibility check to one component?
- 4Should every accessibility rule be a hard CI failure?
Say it in the interview
I use cypress-axe to inject axe-core and run cy.checkA11y on pages and mounted components. That catches structural issues like missing labels and invalid ARIA. I still test keyboard operation, focus management, live-region announcements and contrast manually, because automated tools cannot judge usability. I keep an intentional rule set so the check is meaningful rather than noisy.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.