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

Visibility errors when window is hidden during headed mode test execution #4039

Closed
agualis opened this issue Apr 26, 2019 · 15 comments
Closed

Visibility errors when window is hidden during headed mode test execution #4039

agualis opened this issue Apr 26, 2019 · 15 comments
Assignees

Comments

@agualis
Copy link

@agualis agualis commented Apr 26, 2019

Current behavior:

Cypress tests fail when the browser is not focused in "run headed" mode.

This kind of problem is always related with components with animations and overlays like modals, popups or sticky headers. (this example shows the problem with sweet alert library).

Desired behavior:

The tests should be deterministic no matter the execution mode and the browser focus state.

Steps to reproduce: (app code and test code)

Repository to reproduce the problem (check readme to follow instructions)
https://github.com/agualis/flaky-swal-cypress

Video showing the error:
https://github.com/agualis/flaky-swal-cypress/blob/master/flaky-cypress-test.mov

Versions

Cypress: 3.2.0 │
Browser: Chrome 73
OS: macOS Mojave

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Apr 26, 2019

Hi @agualis, I believe this will be fixed in #2982

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Jun 11, 2019

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

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Jun 19, 2019

I'm actually unable to reproduce this from the repo provided as is so I can't confirm if 3.3.2 release fixes this. @Bkucera did you reproduce?

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Jun 27, 2019

Released in 3.3.2.

@johnknoop
Copy link

@johnknoop johnknoop commented Sep 27, 2019

I still have problems of this nature in 3.4.1.

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Sep 27, 2019

@johnknoop please provide a reproducible test example, either in this issue or a new one. Thanks!

@johnknoop
Copy link

@johnknoop johnknoop commented Sep 27, 2019

@johnknoop please provide a reproducible test example, either in this issue or a new one. Thanks!

That might take me some time, since I don't want to share the codebase as-is. I understand you need something reproducable to work with though. I'll try to get around to it!

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Sep 27, 2019

@johnknoop feel free to point us to a public-facing url if you need. We don't need access to anything but the test code.

@johnknoop
Copy link

@johnknoop johnknoop commented Sep 27, 2019

I think the problem may not be with Cypress, but with the fact that my application should do certain things when an input field has focus. When the Cypress window doesn't have focus, the browser doesn't recognize that the field is focused, even though Cypress thinks it has focus,, and thus the application behaves differently.

It would be nice if cy.get('#myElement').focus() would trigger the field to be focused, but I can see how that might be out of your control.

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Sep 27, 2019

@johnknoop we should be properly "tricking" your app into thinking the browser is focused. We force document.hasFocus() to true and even polyfill focus events when browser is not in focus- even when your appcode calls input.focus(). document.activeElement always updates regardless of browser focus too. It's possible there are still edge cases, so reproducible examples are key here.

@johnknoop
Copy link

@johnknoop johnknoop commented Oct 12, 2019

@Bkucera

I've just spent a few hours trying to create a simple example that reproduces the issue, but to no success.

It reproduces 100% of the times in my real test though.

I can record you guys a video and send, but I'm not sure if you would get any good information from that.

Is there some instrumentation log or something that I can enable?

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Oct 15, 2019

@johnknoop usually we can't get much from video, and we don't have very robust debug logs in the driver. Usually these types of issues are related to some lib or ui framework so that type of information helps

@johnknoop
Copy link

@johnknoop johnknoop commented Oct 15, 2019

@Bkucera

For what it's worth.. it's an AngularJS 1.6 app. The app is quite interactive, so a lot of stuff is displayed/hidden based on mouse interaction. And 98% (ish) of these seem to work when the Cypress window is hidden behind another window. There's only very few cases that don't work.

The one that I tried to reproduce in a codepen.io sample, but failed, uses elements that are repeated, and within each element is an input field. When that input field has focus, a property on the angular scope is set to true, which makes a fly-out visible (it's not part of the DOM when it's hidden). The thing that fails is that the input field never gets focused if the cypress window lacks focus. This much I have gathered using logging.

@mankybansal
Copy link

@mankybansal mankybansal commented Oct 16, 2019

I have noticed this in our Next.js app as well. All the tests pass when the window is in focus and I'm looking at it. The minute I switch workspaces on the mac (even after a few tests have passed), the next test fails.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Dec 24, 2019

This issue will be closed to further comment as the exact issue here was resolved and tested.

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.

@cypress-io cypress-io locked and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants