Disable Cypress from automatic scrolling

Viewed 5450

I am testing my application where I have very long side menu and I have a code like that:

cy.get('tab').click({force: true})

The automatic scroll happens between get and click and then selected tab is not visible since the top menu has possition fixed. I found many solutions but none of them worked. So far I tried .click({force: true}) and .click(scrollBehaviour: false}) also .scrollIntoView() between get and click. Is there any other way to solve this issue?

4 Answers

Did you try to type "scrollBehavior": false in cypress.json file? Because it worked for me.

Depends on how the auto-scroll is implemented, you can try adding this at the top of the test

cy.window().then(win => win.scrollTo = cy.stub())

which attempts to stub out the native scrollTo function. I haven't tried it, it may fail if win.scrollTo is read-only.

Here's the reference page Window.scrollTo(), to can see in the notes some other variations to try if the app is using those instead.

Related