component-driven / cypress-axe

Test accessibility with axe-core in Cypress
MIT License
622 stars 86 forks source link

Support iframes #100

Open james2406 opened 3 years ago

james2406 commented 3 years ago

Hi. It would be great if this library supported an option to target a specific window/document.

This could be achieved with an API like this:

it('checks the iframe content is accesible', () => {
  cy.iframe('iframe.testing').within((frame) => {
    const window = frame.ownerDocument.defaultView
    cy.injectAxe({ window });
    cy.checkA11y(undefined, { window });
  });
});

The only annoying thing is you have to inject the axe-core lib into each iframe that you want to check.

What do you think? I'd be happy to submit a PR.

rishichenna commented 2 years ago

frame.ownerDocument is empty in my case and throws an error: cannot read property "defaultView". Is there any other way to inject?

  cy.iframe("iframe#XYZ").within((frame) => {
    // const window = frame.ownerDocument.defaultView
    const window = frame.ownerDocument
    cy.injectAxe({ window });
    cy.checkA11y(null, null, terminalLog, true, { window });

Using cypress": "9.1.0"