0
0
Cypresstesting~20 mins

Shadow DOM access in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shadow DOM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Cypress test accessing Shadow DOM?

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?

Cypress
cy.get('custom-element').shadow().find('button#submit').click();
ATest fails with error: Element not found because shadow() is not a valid Cypress command
BTest fails with error: Cannot read property 'find' of undefined
CTest passes but does not click the button inside Shadow DOM
DTest passes and clicks the button inside Shadow DOM
Attempts:
2 left
💡 Hint

Remember that Cypress supports shadow() to access Shadow DOM elements.

assertion
intermediate
2:00remaining
Which assertion correctly verifies text inside Shadow DOM?

You want to check that a <span> inside a Shadow DOM contains the text "Hello World". Which Cypress assertion is correct?

Cypress
cy.get('my-component').shadow().find('span')
A.should('contain.text', 'Hello World')
B.should('contain', 'Hello World')
C.should('have.text', 'Hello World')
D.should('include.text', 'Hello World')
Attempts:
2 left
💡 Hint

Use the assertion that exactly matches the full text content.

locator
advanced
2:00remaining
Which locator correctly selects a nested Shadow DOM element?

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?

Acy.get('outer-comp').shadow().shadow().find('button#btn')
Bcy.get('outer-comp').shadow().find('inner-comp').shadow().find('button#btn')
Ccy.get('outer-comp').shadow().find('inner-comp').find('button#btn')
Dcy.get('outer-comp').find('inner-comp').shadow().find('button#btn')
Attempts:
2 left
💡 Hint

Remember each Shadow DOM requires a separate shadow() call.

🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail to find Shadow DOM element?

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();
AThe <code>find()</code> does not penetrate Shadow DOM; need to use <code>shadow()</code> first
BThe button does not exist in the DOM at all
CThe selector <code>button#save</code> is invalid CSS
DThe <code>click()</code> command is deprecated and causes failure
Attempts:
2 left
💡 Hint

Think about how Shadow DOM elements are accessed in Cypress.

framework
expert
2:00remaining
Which Cypress configuration enables automatic Shadow DOM support for all commands?

You want Cypress to automatically pierce Shadow DOM for all get and find commands without calling shadow() explicitly. Which configuration option achieves this?

A"experimentalShadowDomSupport": true in <code>cypress.json</code>
B"autoShadow": true in <code>cypress.json</code>
C"shadowDomSupport": true in <code>cypress.config.js</code>
D"enableShadow": true in <code>cypress.json</code>
Attempts:
2 left
💡 Hint

Check Cypress official docs for Shadow DOM configuration.