Consider the following Cypress test code snippet that tries to get a button inside a Shadow DOM and click it. What will be the test execution result?
cy.get('custom-element').shadow().find('button#submit').click();
Remember that Cypress supports shadow() to access Shadow DOM elements.
The shadow() command in Cypress allows access to the shadow root of a web component. Then find() locates the button inside it. This code correctly clicks the button inside Shadow DOM, so the test passes.
You want to check that a <span> inside a Shadow DOM contains the text "Hello World". Which Cypress assertion is correct?
cy.get('my-component').shadow().find('span')
Use the assertion that exactly matches the full text content.
have.text asserts the element's full text content equals the given string. contain.text is not a valid Cypress assertion. contain performs partial text matching, while include.text is unsupported.
Given a web component <outer-comp> with a Shadow DOM containing <inner-comp> which also has Shadow DOM, which contains a button with id btn. Which Cypress command correctly locates the button?
Remember each Shadow DOM requires a separate shadow() call.
Each Shadow DOM layer must be accessed with shadow(). Option B correctly accesses outer-comp shadow root, then inner-comp shadow root, then finds the button. Other options miss a shadow() call or misuse it.
This test fails with Timed out retrying: Expected to find element: 'button#save', but never found it. What is the likely cause?
cy.get('custom-el').find('button#save').click();Think about how Shadow DOM elements are accessed in Cypress.
find() cannot access elements inside Shadow DOM unless shadow() is used first to enter the shadow root. The failure is due to missing shadow() call.
You want Cypress to automatically pierce Shadow DOM for all get and find commands without calling shadow() explicitly. Which configuration option achieves this?
Check Cypress official docs for Shadow DOM configuration.
The Cypress config option to enable automatic Shadow DOM traversal is experimentalShadowDomSupport: true in cypress.json (experimental feature in earlier versions). Other options do not exist. Modern versions use explicit shadow().