When using Cypress for automated testing, by default, Cypress attempts to scroll the element you're interacting with into view. If you do not want Cypress to automatically scroll the page, you can use { scrollBehavior: false } as an option for the command to disable automatic scrolling. For example, if you are using the click() command:
javascriptcy.get('button').click({ scrollBehavior: false });
In this example, Cypress will click the button on the page, but it will not automatically scroll the button into view. This means that if the button is not within the viewport initially, the click may not occur. You can also change the scrolling behavior globally, so you don't have to specify { scrollBehavior: false } for each command. In your cypress.json configuration file, you can add the scrollBehavior configuration to set the default behavior:
json{ "scrollBehavior": false }
With this approach, Cypress will not automatically scroll during any command in the test run. Please note that disabling automatic scrolling may cause your interactive commands (such as click or type) to fail if the element is not within the viewport when the command is executed. This could affect test reliability, as users typically scroll to make an element visible before interacting with it under normal browsing conditions.