Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying shadow dom with cy.contains when within shadow root does not find elements #8494

Closed
chrisbreiding opened this issue Sep 3, 2020 · 2 comments · Fixed by #8520
Closed
Assignees

Comments

@chrisbreiding
Copy link
Contributor

chrisbreiding commented Sep 3, 2020

Current behavior:

Querying shadow dom with cy.contains when already within a shadow root does not find the element with the specified text.

Screen Shot 2020-09-08 at 10 52 11 AM

Desired behavior:

Querying the shadow dom should work using cy.contains.

Test code to reproduce

cypress.json

{
  "experimentalShadowDomSupport": true
}

cypress/fixures/shadow-dom.html

<html>
<body>
  <div id="outer">
    <div id="host"></div>
  </div>

  <script>
    document
    .getElementById('host')
    .attachShadow({ mode: 'open' })
    .innerHTML = '<div class="in-shadow-dom">In Shadow DOM</div>'
  </script>
</body>
</html>

spec.js

it('fails querying shadow dom in cy.within', () => {
  cy.visit('/cypress/fixures/shadow-dom.html')
  cy
  .get('#host')
  .shadow()
  .contains('In Shadow DOM')
  .should('have.class', 'in-shadow-dom')
})

Versions

Cypress 4.8.0+

@chrisbreiding chrisbreiding self-assigned this Sep 3, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Sep 3, 2020
@chrisbreiding chrisbreiding changed the title Querying shadow dom with cy.contains causes error 'root.getRootNode is not a function' Querying shadow dom with cy.contains when within shadow root does not find elements Sep 8, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress labels Sep 8, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 9, 2020

The code for this is done in cypress-io/cypress#8520, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Sep 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 15, 2020

Released in 5.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant