Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable users to change the scrolling strategy #871

Closed
brian-mann opened this issue Nov 3, 2017 · 53 comments · Fixed by #8837
Closed

Enable users to change the scrolling strategy #871

brian-mann opened this issue Nov 3, 2017 · 53 comments · Fixed by #8837
Assignees
Labels
topic: scrolling ↕️ type: feature New feature that does not currently exist

Comments

@brian-mann
Copy link
Member

brian-mann commented Nov 3, 2017

Users have expressed a desire to modify how Cypress internally scrolls elements.

Related to:

Users should be able to change this strategy to be one of:

  • top
  • bottom
  • middle (don't scroll if already within screen)
  • disable (turn off all automatic scrolling)

future

- [ ] By default, scroll element into center

@dentuzhik
Copy link

dentuzhik commented May 24, 2018

Just expressing another usecase where disabling scrolling would be useful.

I am currently writing tests for mobile viewport, which in real life is never supposed to be able to scroll itself, and because of how cypress scrolls elements into view a lot of the times they end up being hidden and are not asserted correctly by .should('be.visible').

On the other hand some other elements which are normally positioned offscreen for animations become visible, and are also incorrectly asserted using visibility checks.

@kapalkat
Copy link

I think my problem touches the same area:
#2418

@JMSantos94

This comment has been minimized.

@jennifer-shehane jennifer-shehane added stage: proposal 💡 No work has been done of this issue stage: ready for work The issue is reproducible and in scope and removed stage: proposal 💡 No work has been done of this issue labels Nov 28, 2018
@jennifer-shehane

This comment has been minimized.

@kuceb kuceb removed the stage: ready for work The issue is reproducible and in scope label Dec 18, 2018
@kuceb kuceb modified the milestone: Sprint 16 Dec 18, 2018
@kuceb kuceb assigned kuceb and unassigned brian-mann Dec 18, 2018
@kuceb

This comment has been minimized.

@jennifer-shehane

This comment has been minimized.

@kuceb

This comment has been minimized.

@ghost

This comment has been minimized.

@dwelle

This comment has been minimized.

@jennifer-shehane
Copy link
Member

This issue is still in the 'proposal' stage, some initial proof of concept work as well as background architecture work has been done, but the issue itself has no work done on it as of today, we do not have an estimate on when this will be delivered.

@diggabyte
Copy link

@jennifer-shehane wondering what it will take to move this out of proposal?

The web is built on scrolling viewports. Yet cypress resets scroll position every time you .get() an element, which is hugely problematic for testing any element interaction that might exist below the fold or within a scrolling container.

Using force: true defeats the purpose of all the built in checks that make cypress so great!
This should be a top priority for the team to address.

@JohnMCrooks
Copy link

JohnMCrooks commented Apr 19, 2020

I'd like to also throw in my support for this fix. I'm seeing the unwanted scroll occur on the get(), and I'm sure it's the get because I removed anything else after it in the test case. Our analytics verify that the view is being cut off by the fixed nav-bar as we see in the test runner. The workaround doesn't seem to be working for us either on 4.0.2.

@bakjos
Copy link

bakjos commented Apr 23, 2020

@JohnMCrooks Today I have made a new test using the 4.4.1 version and the workaround is working well for me

@drewbrend
Copy link

drewbrend commented Jun 25, 2020

I had an issue with the workaround @bakjos posted in a specific scenario, though it worked with the majority of cases. When an element was not virtualized but was slightly off screen - it would get into an infinite loop, scrolling would trigger the scrolled event, which would run that workaround, which would scroll, triggering the workaround, and on and on. Then because react-virtualized sets pointer-events to none for 150ms after scrolling the element would never become clickable, so .click() would time out. I could work around this with click({force: true}) but hate using that because it opens you up to other problems. I made a slight tweak so it will only scroll an element once and now I don't have to use force. Hopefully this helps someone else.

let $lastEl: JQuery<HTMLElement>;
let hasScrolled = false;

Cypress.on('scrolled', ($el) => {
  if ($el.is($lastEl)) {
    if (hasScrolled) {
      return;
    }

    hasScrolled = true;
  } else {
    $lastEl = $el;
    hasScrolled = false;
  }

  $el.get(0).scrollIntoView({
    block: 'center',
    inline: 'center',
  });
});

@Ondskan56

This comment has been minimized.

dkarhi added a commit to dkarhi/web that referenced this issue Jul 31, 2020
I'm adding e2e tests for user profiles. These tests verify that:
* Users can update their phone number
* Users can't enter an invalid phone number

I ran into a documented issue with Cypress where it isn't properly scrolling an
element into view. This issue is being tracked at:
cypress-io/cypress#871. I forced a few actions to work
around this, but there are some additional workaround options suggested on the
issue page.
dkarhi added a commit to dkarhi/web that referenced this issue Jul 31, 2020
I'm adding e2e tests for user profiles. These tests verify that:
* Users can update their phone number
* Users can't enter an invalid phone number

I ran into a documented issue with Cypress where it isn't properly scrolling an
element into view. This issue is being tracked at:
cypress-io/cypress#871. I forced a few actions to work
around this, but there are some additional workaround options suggested on the
issue page.
jkeat pushed a commit to UPchieve/web that referenced this issue Jul 31, 2020
I'm adding e2e tests for user profiles. These tests verify that:
* Users can update their phone number
* Users can't enter an invalid phone number

I ran into a documented issue with Cypress where it isn't properly scrolling an
element into view. This issue is being tracked at:
cypress-io/cypress#871. I forced a few actions to work
around this, but there are some additional workaround options suggested on the
issue page.
@jennifer-shehane
Copy link
Member

Sorry, no updates here. We are prioritizing other work over this at the moment.

@jennifer-shehane jennifer-shehane removed the Epic Requires breaking up into smaller issues label Aug 19, 2020
@jennifer-shehane
Copy link
Member

I did review the comments here and am finding a lot of people saying they need to control the scroll behavior because they have to pass force: true to a click or similar action because their element is not being regarded as visible - due to how we scroll.

We're only aware of a couple of issues where this happens in the current 4.12.1 version now - many of these issues have been resolved since this was opened.

Scrolling causes visibility error


Please open an issue

If you're having a situation where Cypress is incorrectly determining the visibility of an element because of scrolling, and it doesn't fall under the issues above, then we are not aware of it.

We suggest opening a new issue with a fully reproducible example so that we can fix the core visibility algorithm and you won't need the scrolling workaround in the first place. This will likely get your issue fixed quicker than waiting for this scrolling strategy feature.

@Sakshi3110
Copy link

Sakshi3110 commented Aug 21, 2020

Hey @jennifer-shehane ,

I am also facing issues with ScrollTo and ScrollIntoView methods. I wanted to scroll down the Application Under test window while running tests,to test lazy loaded ads. Scroll works fine when I am viewing the tests. But once I Minimize the test window, scroll do not work, also I do not get any kind of error.

cy.scrollTo('bottom')`
cy.window.scrollTo('bottom')`
cy.get('.container-main > .header > .title').scrollIntoView({force:true}).should('be.visible')

Try this code :

it('Scrolling',function() {
  cy.visit("https://css-tricks.com/snippets/javascript/lazy-loading-images/")
  cy.scrollTo('0%','25%')
  cy.wait(5000)
  cy.get('.fem-learning-partner').should('be.visible').and('contain.text','Our Learning Partner')
})

All this works, when I just open Cypress test window and looking on behavior of my tests doing nothing else. :(

Why scrolling fails when I am not viewing/minimizing the cypress test window ?
No issues on headless chrome, but login fails due to cross domain redirection, so I have to check on chrome headed.

Is this an open issue with Cypress ? I am not able to complete many tests cases of my project due to this issue,my application is on vue-js. Can you please suggest something. It will be a big help.
Thanks !

@jennifer-shehane
Copy link
Member

@Sakshi3110 There are some issues covering this here: #5023 But they may not all be caused by the same situation.

@Sakshi3110
Copy link

@jennifer-shehane Thanks! I checked #5023 , May be I also need something in my code, which keeps Test Runner/Application under test browser in ACTIVE mode. So, that focus remains active even after minimizing windows.

@mgladchenko
Copy link

How long do we wait for solution?

@mgladchenko
Copy link

Please provide workaround if you are not going to fix it.

@bahmutov
Copy link
Contributor

Currently, this is just a proposal without any work planned in the nearest future.

@flucivja
Copy link

flucivja commented Sep 29, 2020

Any suggestion how to test components which close itself when page is scrolled? E.g. fluent-ui contextual menu components here https://developer.microsoft.com/en-us/fluentui#/controls/web/contextualmenu#IContextualMenuProps - try to click on button and then scroll the page ... I am working on Cypress tests where I am unable to click on menu item because once menu is opened and I try to click on menu item, page is scrolled, menu closes and Cypress fails because menu item element does not exists in the DOM.

Edit:
I found workaround for this by using jQuery to click which does not autoscroll:

cy.get('.menuitem').then(el => el.trigger('click'));

@cypress-bot cypress-bot bot added stage: pending release and removed stage: proposal 💡 No work has been done of this issue labels Nov 30, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 30, 2020

The code for this is done in cypress-io/cypress#8837, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 7, 2020

Released in 6.1.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.1.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 7, 2020
@jennifer-shehane
Copy link
Member

In Cypress 6.1.0, there’s a new scrollBehavior configuration option that controls the viewport position when an element is scrolled prior to action commands. Possible values are 'top', 'bottom', 'center', 'nearest', and false, with 'top' being the default. scrollBehavior: false disables scrolling altogether. scrollBehavior can be specified in global configuration, test configuration or individual action commands via options.

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: scrolling ↕️ type: feature New feature that does not currently exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.