0
0
Cypresstesting~20 mins

cy.scrollTo() in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Scroll Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the effect of this Cypress command?
Consider the following Cypress test code snippet:
cy.get('#content').scrollTo('bottom')

What will this command do during test execution?
Cypress
cy.get('#content').scrollTo('bottom')
AScrolls the element with id 'content' to its bottom edge.
BScrolls the entire page to the bottom regardless of the element.
CScrolls the element with id 'content' to the top edge.
DThrows an error because 'bottom' is not a valid argument.
Attempts:
2 left
💡 Hint
Think about what element is targeted and what 'bottom' means in scrolling context.
assertion
intermediate
2: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)
Acy.get('#box').should('have.css', 'scrollTop', '100px')
Bcy.get('#box').should('have.value', 100)
Ccy.get('#box').should('have.attr', 'scrollTop', '100')
Dcy.get('#box').should('have.prop', 'scrollTop', 100)
Attempts:
2 left
💡 Hint
Scroll position is a property, not a CSS style or attribute.
🔧 Debug
advanced
2:00remaining
Why does this scrollTo command fail to scroll?
Given the code:
cy.get('.scrollable').scrollTo('right')

The element does not scroll. What is the most likely reason?
Cypress
cy.get('.scrollable').scrollTo('right')
AThe element selector '.scrollable' is incorrect and matches no elements.
BThe 'right' argument is invalid; it should be 'end'.
CThe element has no horizontal scrollbar because content width fits inside the container.
Dcy.scrollTo() only works on the window object, not elements.
Attempts:
2 left
💡 Hint
Check if the element can actually scroll horizontally.
🧠 Conceptual
advanced
2: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')
and
cy.scrollTo(0, 0)
A'top' scrolls vertically only; (0,0) scrolls horizontally and vertically to top-left corner.
B'top' scrolls the page; (0,0) scrolls the element.
C'top' is invalid and causes error; (0,0) is the correct way to scroll to top.
D'top' scrolls to the top edge; (0,0) scrolls to the top-left corner. Both are equivalent.
Attempts:
2 left
💡 Hint
Consider horizontal and vertical scroll axes.
framework
expert
3: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?
AUse cy.scrollTo('bottom', { easing: 'linear' }) and immediately run assertions after.
BUse cy.scrollTo('bottom', { duration: 1000 }) and chain .then() to run assertions after scrolling.
CUse cy.scrollTo('bottom') without options; Cypress always waits for scrolling to finish.
DUse cy.scrollTo('bottom', { duration: 1000 }) and add cy.wait(1000) before assertions.
Attempts:
2 left
💡 Hint
Think about how Cypress handles commands with duration and chaining.