Wanted to know if there is some way to test for scroll amount, within a certain range with Cypress.io.
More Specifically
My attempt: The way I assume would be best is to test that would to test out, that a current div is not within the viewable area of phone screen. Then to scroll down so it does become viewable.
cy.get('#angular-projects').should('not.be.visible') // div #angular-projects
cy.get('#developer-projects').click() // button
cy.get('#angular-projects').should('be.visible')
Wanted to know whether this can be done via mocha, chai, if there is no cypress work around
options (Object) Pass in an options object to change the default behavior of cy. scrollTo() . Ensure element is scrollable. Error if element cannot scroll.
An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0 .
Say your page displays a list of names and you want a certain person to be highlighted and scrolled into view. There's a browser API for that: Element. scrollIntoView() , which scrolls an element into view.
You can get the window
object with cy.window() and then build your assertion checking if the scrollY equals what you expect.
Something like this should test if the scroll is between 300 and 500 pixels from the top (the first argument of closeTo specifies the value you want and the second is the margin of error you want to accept):
cy.window().then(($window) => {
expect($window.scrollY).to.be.closeTo(400, 100);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With