Add support for shadow dom
See original GitHub issueCurrently, Cypress fails for various reasons when dealing with the shadow dom. So far, I’ve seen three issues.
- Cypress considers the shadow root to be a non-DOM subject.
cy.get("#root")
.then ($root) ->
return Cypress.$($root[0].shadowRoot)
.find('.child-2')
.should('have.text', 'I am child 2')
Moving the .find
into the .then
gets past this issue, but is not ideal:
cy.get("#root")
.then ($root) ->
return Cypress.$($root[0].shadowRoot).find('.child-2')
.should('have.text', 'I am child 2')
It might be nice and maybe even necessary to have a convenience method like cy.getShadowRoot()
that could be chained off other dom commands.
- When you try to assert something on an element inside a shadow root, Cypress reports that the element is detached from the dom. This stems from the fact that
$.contains(el1, el2)
returns false when el1 is outside the shadow root and el2 is inside it. Some discussion here.
cy.get("#root")
.then ($root) ->
return Cypress.$($root[0].shadowRoot).find('.child-1')
.should("have.text", "I am child 1")
- Commands that cause Cypress to check if the subject is hidden by ancestors trigger infinite recursion and blow the call stack because it never hits the
<body>
or<html>
elements while walking up the chain of ancestors.
cy.get("#root")
.then ($root) ->
return Cypress.$($root[0].shadowRoot).find('.child-2')
.contains('button', 'Go')
Issue Analytics
- State:
- Created 7 years ago
- Reactions:118
- Comments:114 (20 by maintainers)
Top Results From Across the Web
Using shadow DOM - Web Components | MDN
Shadow DOM allows hidden DOM trees to be attached to elements in the regular DOM tree — this shadow DOM tree starts with...
Read more >Shadow DOM (V1) | Can I use... Support tables for ... - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >Shadow DOM Support - Pendo Help Center
Pendo supports Shadow DOM elements for feature tagging and page element positioning for Guides. What is a Shadow DOM? It is a web...
Read more >Add support for Shadow DOM · Issue #1014 - GitHub
The problem Shadow DOM is used by any framework that supports web components. For example, when testing ... Add support for Shadow DOM...
Read more >Declarative Shadow DOM - web.dev
Shadow DOM provides a way to scope CSS styles to a specific DOM subtree and isolate that subtree from the rest of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another +1 here!
I agree with you. Nowadays it’s a common scenario big companies bet for WebComponents for build their front-end, and it’s a shame we can’t use cypress for testing 😦
Hope it get’s prioritized.
No work has been done on this issue.