Not sure it it is a bug, or a misunderstanding from mine.
When testing a MaterialUI component, I got some trouble with hot reloading. If I refresh my browser with F5, my code behaves correctly:

Yet, if test is relaunched using hot reload, select list takes a long time before closing:

I would expect the behavior to be the same between fresh refresh or hot reload.
I created a repository to reproduce the issue: https://github.com/jpetitcolas/cypress-bug
Clone it, then launch the React app and open Cypress:
git clone https://github.com/jpetitcolas/cypress-bug.git
npm install
npm start
# in another term
npm run cypress
Then, comment or uncomment the following line to let browser to hot reload.
@jpetitcolas I was able to reproduce this by removing focus of the mouse from the test runner during a run. Notice the run will be fast as long as the mouse is over the window. Can you confirm this behavior, and see if you can reproduce on 2.1.0 ?
confirmed bug on all cypress versions
cypress run and cypress open, when window doesn't have focusWe detected that the root cause has to do with a combination of things.
activeElement to something other than the one we have a reference to by calling the native .focus() method.blur event is called, but it is not because the browser refuses to fire it due to the activeElement being changedcy.blur() command does not take this into account and reaches its timeout limit, thus failingcy.click().To fix this problem (and others) we need to make the sub focus/blur routes non-async (to the best of our ability) or add checks after async actions to take into account if the activeElement was manually changed by application code instead. In that case, the blur should belong to the activeElement not the internal one we have a reference to.
In the future, we should consider not actually polyfilling the focus and blur events that the browser would normally fire if the window is in focus. I tested how the browser performs with real native events, and it does fire them if the window is visible but not active - but it does not fire them if the window is not visible - such as if your IDE is covering it up, or another chrome window is as well.
I don't have a full reproduction case or anything ready, so sorry if this is polluting the issue but I will chime in with what I know. We have an issue on one of our repos at work with Cypress and Material-UI which results in erratic behavior when the test runner is not focused. Here is an edited excerpt from our internal report:
tl;dr
Until we figure this one out: Don't focus away from cypress when you run it locally. Press play, don't touch the keyboard or mouse, let it do its thing.
Description
Note: This issue only seems to pop up locally in the Cypress interactive/GUI test runner. So far it hasn't happened in CI or on when using npm run cypress:run locally.
When I run cypress tests, it seems now to matter whether or not the Cypress window is focused/in the foreground. If I am on a single laptop screen and tab away from Cypress for too long, and the entire window is obscured/not visible, I start getting test failures.
Versions used
Cypress 2.1.0 using Electron 59 browser
macOS 10.13.4
Steps to reproduce
In a cypress test, navigate to XXXXX and immediately interact with an input (e.g. cy.type() in a field, or cy.click() a delete button).
Put this cypress test in a loop to repeat the test 100 times.
Run the test. Observe it pass e.g. 25 times. If you leave it alone, you will have 100% success rate.
Tab away from cypress and do other things. Make sure the cypress window is not visible.
At some point, you will see intermittent test failures that look like this:
This element '
Comments
Very strange... curious if anyone else can reproduce. This was happening to me on XXXXXX I was able to get a small reproduction case here:
It passed 34 times in a row. I focused away from cypress, then it started failing repeatedly. I wondered if it was because I pressed CMD+TAB, and accidentally sent a TAB command to the focused browser? No -- that wouldn't make subsequent tests fail.
I feel like this has something to do with the behaviour of Chromium changing because the window isn't visible, i.e. a rendering optimization in Chromium (or macOS, or the display drivers) that interferes with Cypress' interaction, or maybe exposes a race condition that isn't normally there. Also, since I don't see it happen anywhere but on XXXXXX, maybe a hardware-accelerated animation in MaterialUI's CSS is somehow triggering this behaviour.
This is way too vague to report to cypress for now, and I'd like to see if anyone else can reproduce it before going that far.
@jbinto we're actually aware of the root issue and have already fixed it in a local branch. This will get released with the next patch update.
Released in 3.0.2.
Could this issue be related with this?
Most helpful comment
@jbinto we're actually aware of the root issue and have already fixed it in a local branch. This will get released with the next patch update.