Challenge - 5 Problems
Scroll Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the effect of this Cypress command?
Consider the following Cypress test code snippet:
What will this command do during test execution?
cy.get('#content').scrollTo('bottom')What will this command do during test execution?
Cypress
cy.get('#content').scrollTo('bottom')
Attempts:
2 left
💡 Hint
Think about what element is targeted and what 'bottom' means in scrolling context.
✗ Incorrect
The command targets the element with id 'content' and scrolls it to its bottom edge. It does not scroll the whole page. 'bottom' is a valid position argument for cy.scrollTo().
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the scroll position after cy.scrollTo()?
After executing
cy.get('#box').scrollTo(0, 100), which assertion correctly checks that the vertical scroll position is 100 pixels?Cypress
cy.get('#box').scrollTo(0, 100)
Attempts:
2 left
💡 Hint
Scroll position is a property, not a CSS style or attribute.
✗ Incorrect
The scrollTop property holds the vertical scroll position as a number. Using 'have.prop' with 'scrollTop' and value 100 correctly asserts the scroll position.
🔧 Debug
advanced2:00remaining
Why does this scrollTo command fail to scroll?
Given the code:
The element does not scroll. What is the most likely reason?
cy.get('.scrollable').scrollTo('right')The element does not scroll. What is the most likely reason?
Cypress
cy.get('.scrollable').scrollTo('right')
Attempts:
2 left
💡 Hint
Check if the element can actually scroll horizontally.
✗ Incorrect
If the content inside the element fits within its width, no horizontal scrollbar appears, so scrolling to 'right' has no effect.
🧠 Conceptual
advanced2:00remaining
What is the difference between cy.scrollTo('top') and cy.scrollTo(0, 0)?
In Cypress, what is the difference between these two commands?
cy.scrollTo('top')andcy.scrollTo(0, 0)
Attempts:
2 left
💡 Hint
Consider horizontal and vertical scroll axes.
✗ Incorrect
'top' scrolls vertically to the top but keeps horizontal scroll unchanged. (0,0) scrolls both horizontally and vertically to the top-left corner.
❓ framework
expert3:00remaining
How to ensure cy.scrollTo() waits for smooth scrolling to finish before next command?
You want to scroll an element smoothly and then perform assertions only after scrolling finishes. Which approach ensures Cypress waits correctly?
Attempts:
2 left
💡 Hint
Think about how Cypress handles commands with duration and chaining.
✗ Incorrect
When using duration option, Cypress waits for the scroll animation to finish before continuing. Chaining .then() ensures assertions run after scrolling completes.