Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Cypress from automatic scrolling

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?

like image 745
N.Nicko Avatar asked Mar 23 '26 18:03

N.Nicko


2 Answers

You can set the scrollBehavior globally or per test(-suite).

I'm disabling it on a per tests basis like so:

it('check something w/ autoscroll disabled', { scrollBehavior: false }, () => {
  cy.get('.tab').click();
  // do something else ...
});

Docs: https://docs.cypress.io/guides/references/configuration#Actionability

like image 138
Philipp Kyeck Avatar answered Mar 26 '26 06:03

Philipp Kyeck


Did you try using scrollBehaviour: 'top' ?

You can find more details regarding the ScrollBehaviour here:

https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Scrolling https://docs.cypress.io/guides/references/configuration#Actionability https://docs.cypress.io/api/commands/click#Arguments

like image 35
DieGraueEminenz Avatar answered Mar 26 '26 06:03

DieGraueEminenz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!