cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Cypress v13.6.0 no longer running commands (hangs) when we focus out of the window

Open Julien-Marcou opened this issue 1 year ago • 41 comments

Current behavior

When I launch my E2E tests on Chrome, if I focus out of the Chrome window, the E2E commands are no longer running, it's hanging there doing nothing.

If I always stay focused on the Chrome window, the commands work as expected.

After focusing out, re-focusing in the window does not make the commands continue/restart.

Might be related to this PR this https://github.com/cypress-io/cypress/pull/28334

Desired behavior

I should be able to run E2E tests while not being focused on Chrome (as before) so I can do something else while the E2E tests are running.

Test code to reproduce

Sorry I don't have time to create a reproduction of the bug for the moment

Cypress Version

13.6.0

Node version

v18.18.2

Operating System

macOS 14.1.1

Debug Logs

No response

Other

No response

Julien-Marcou avatar Nov 23 '23 14:11 Julien-Marcou

@Julien-Marcou That's certainly not intended. We haven't observed this behavior so I wonder if it is something specific with your tests. A reproducible example or a video of the hanging behavior would be helpful. We'll keep an eye on tracking for this.

jennifer-shehane avatar Nov 27 '23 15:11 jennifer-shehane

I am experiencing the same issue in v13.6.0

esetnik avatar Nov 27 '23 22:11 esetnik

I am experiencing this issue as well in 13.6.0 When I open a test in test runner it runs correctly, but if I go to VS Code and make a change to the code and save, normally the test will run again in test runner, but it hangs. I have to stop and restart the test every time I make a change to the code.

stephenmday avatar Nov 27 '23 23:11 stephenmday

I have the same focus issue with Cypress 13.6.0 and Chrome 119 but it does not occur when selecting Edge, Firefox or Electron. In my case, saving changes in VS Code still causes the test runner to start over but because the focus was lost, the process stops there.

EllenFr avatar Nov 28 '23 13:11 EllenFr

We are experiencing the same issue after we updated to v13.6.0 The tests are executed in an Azure Pipeline and stop sending out the requests after 2-3 hours of execution. Additionally, the issue @stephenmday and @EllenFr described appears on my local machine, too. We went back to v13.5.1 for now.

NOTE: I think I should mention that we are sending an HTTP request in "beforeAll" hook of each test to ensure that the test environment is initialized correctly. This one specific request is the one that gets stuck.

It's a globally defined "beforeAll" hook in the e2e.ts image

valantic-dev avatar Nov 28 '23 14:11 valantic-dev

I see the same issue with 13.6.0

alexsch01 avatar Nov 28 '23 19:11 alexsch01

Does anyone have a clone-able repo that can be used to reliably reproduce this issue? I've tried a few projects, but can't recreate the described behavior, so I wonder if there's something project-specific that I'm missing. A way to reproduce it locally would provide a way forward to diagnose and fix the problem.

chrisbreiding avatar Nov 28 '23 20:11 chrisbreiding

I am seeing this constantly when running Cypress 13.6.0 with latest Chrome interactively on Windows.

If the Cypress window loses focus it will hang.

Even if I let it run, it eventually hangs when it gets to some download tests because the browser pops up a tooltip: 'Find your downloads here'.

elebitzero avatar Nov 28 '23 22:11 elebitzero

Steps to reproduce:

  1. Run in "open" mode with Chrome, Edge or Electron.
cy.get("#some-text-field").type("foo-bar-baz", { delay: 1000 }).blur()
  1. Wait until Cypress starts typing.
  2. Before blur you have plenty of time (about 10 seconds) to click on another window.
  3. Defocusing of the window leads to defocussing of the text field, so type kind of freezes and blur fails:

cy.blur() can only be called when there is a currently focused element.

Note that in Firefox the text field does not loose focus unwantedly until the Firefox window gets the focus back.

iomedico-beyer avatar Nov 30 '23 15:11 iomedico-beyer

@iomedico-beyer I'm not able to reproduce this behavior from this example still :/

We are looking into the possibility that this issue may be the cause: https://github.com/cypress-io/cypress/issues/28443

If you open devTools after the hang, do you see a message like below?

Uncaught Error: Attempting to use a disconnected port object

jennifer-shehane avatar Dec 01 '23 16:12 jennifer-shehane

cypress_136.zip

Hi @jennifer-shehane and @chrisbreiding , I created a video and captured the test execution incl. 2 scenarios when Cypress gets stuck.

  1. During the test exeuction I open the browser console (via F12). As the console is openen, the execution stops and does not resume again. No errors like in #28443 are in the console.
  2. I restart the test execution and then switch to VSCode during the tests are running. Here again, the executions stops and does not resume.

valantic-dev avatar Dec 04 '23 08:12 valantic-dev

@iomedico-beyer I'm not able to reproduce this behavior from this example still :/

I found something interesting after creating a complete code sample:

it("types into a text field", function() {
   cy.visit("https://www.google.com")
   cy.get("button:visible").first().click()
   cy.contains("English").click()
   cy.contains("button", "Reject all").click()
   cy.get("textarea").first().type("foo-bar-baz", { delay: 1000 }).blur()
})

I found that I couldn't reproduce my problem here either. So my (specific?) problem seems to be somehow related with the web app I am trying to test. It also is not Cypress 13.6 specific. Happens the same with Cypress 13.0 (don't know about even older).

iomedico-beyer avatar Dec 04 '23 10:12 iomedico-beyer

@jennifer-shehane In my case I only experienced this in a dual monitor setup I think where my editor and Cypress runner window are on different screens. Maybe you can reproduce it that way?

verheyenkoen avatar Dec 04 '23 10:12 verheyenkoen

@iomedico-beyer I'm not able to reproduce this behavior from this example still :/

I found something interesting after creating a complete code sample:

it("types into a text field", function() {
   cy.visit("https://www.google.com")
   cy.get("button:visible").first().click()
   cy.contains("English").click()
   cy.contains("button", "Reject all").click()
   cy.get("textarea").first().type("foo-bar-baz", { delay: 10000 }).blur()
})

I found that I couldn't reproduce my problem here either. So my (specific?) problem seems to be somehow related with the web app I am trying to test. It also is not Cypress 13.6 specific. Happens the same with Cypress 13.0 (don't know about even older).

Hmm... In my case it is definitely related to v13.6 as rolling back to any prior version of cypress does not reproduce the issue.

@jennifer-shehane In my case I only experienced this in a dual monitor setup I think where my editor and Cypress runner window are on different screens. Maybe you can reproduce it that way?

I am also on a dual monitor setup for what it's worth.

esetnik avatar Dec 04 '23 17:12 esetnik

What happens in my case is: Let's say Cypress is typing into a text field which represents a date. When it already typed e.g. 2023-0 I click on another window => the text field looses its focus => some Ajax (of the web app I am testing) posts the input to the server. The response of the post request somehow clears the text field (because the date is invalid, I guess) => Cypress can't type in the rest (although it does not complain) and also can't blur (probably because the original text field was replaced by a new one).

So I guess my problem is something very different than what is discussed in this issue and may be related to a general constraint of the open mode in Cypress or even (at least Chromium based) browsers in general. Am I right? Cypress just can't suppress the focus loss? Is this documented somewhere, btw?

iomedico-beyer avatar Dec 05 '23 10:12 iomedico-beyer

@iomedico-beyer For me, the issue you describe seems to originate from the behavior of the UI component framework you are using in your app. Not really related to the topic discussed here.

valantic-dev avatar Dec 05 '23 10:12 valantic-dev

@iomedico-beyer For me, the issue you describe seems to originate from the behavior of the UI component framework you are using in your app.

Partly. I think my main problem is that Cypress cannot supress the focus loss which happens when I click on another window. There should not be a focus loss because the simulated user is typing in something, not clicking around. I just want to know if this is documented somewhere and then it's fine for me. @jennifer-shehane Do you know, perhaps?

It's just that I lost almost a week on this until I understood why my tests are so flaky ...

Not really related to the topic discussed here.

I agree.

iomedico-beyer avatar Dec 05 '23 11:12 iomedico-beyer

@jennifer-shehane We've got same issue. Since 13.6, only in Chrome browser, when you get focus out of cypress runner window it hangs without any errors. Also when I try to download a file in a test. it also hangs after the (download) step without any information. (Chrome 119)

JarekSuchocki avatar Dec 06 '23 19:12 JarekSuchocki

Also getting this. New to cypress, but hard refreshes work, because focused on the chrome window. But save in vscode, and it just doesn't run in chrome unless I click over and focus, hard refresh again.

Also, even with the provided sample tests, when running in the middle, if I click out of chrome just to try and see what happens, it instantly hangs the moment I focus away from chrome.

travisanderson avatar Dec 07 '23 17:12 travisanderson

What OS and OS version is everyone using? Just seeing if there's a trend with OS.

jennifer-shehane avatar Dec 07 '23 17:12 jennifer-shehane

MacOS 14.1.1 (23B81)

stephenmday avatar Dec 07 '23 17:12 stephenmday

Windows 10

JarekSuchocki avatar Dec 07 '23 18:12 JarekSuchocki

What OS and OS version is everyone using? Just seeing if there's a trend with OS.

MacOS Ventura 13.3.1

verheyenkoen avatar Dec 07 '23 19:12 verheyenkoen

MacOS Sonoma 14.1.2

esetnik avatar Dec 07 '23 20:12 esetnik

MacOS Ventura 13.4.1 (22F82)

travisanderson avatar Dec 07 '23 23:12 travisanderson

Windows 10 22H2 (Build 19045.3693)

valantic-dev avatar Dec 08 '23 11:12 valantic-dev

I am experiencing the same issue in v13.6.1

xavicom avatar Dec 11 '23 12:12 xavicom

@jennifer-shehane In my case I only experienced this in a dual monitor setup I think where my editor and Cypress runner window are on different screens. Maybe you can reproduce it that way?

Just tested in single monitor mode (both using MacOS spaces/fullscreen mode and browser and VSCode opened in the same space) and problem also exists there but only in Chrome (v120). Not in Edge, Firefox, Electron or Chrome Canary (v122). So doesn't seem to be dual monitor/space related.

verheyenkoen avatar Dec 11 '23 19:12 verheyenkoen

I tried to update to Cypress v13.6.1, but I'm still having this issue.

I don't have any issue when using Cypress v.13.5.1, so the bug must have been introduced by one of this commit https://github.com/cypress-io/cypress/compare/v13.5.1...v13.6.0

I have the problem with Google Chrome Version 119.0.6045.159 (Official Build) (arm64) when running the tests in headed mode, I don't have the problem when running in headless mode.

It might be related to this specific version of Google Chrome.

Julien-Marcou avatar Dec 12 '23 14:12 Julien-Marcou

I think I found a way to fix this issue. Open a new tab and go to chrome://extensions. You should see the Cypress extension and you'll likely see that there's a toggle in the bottom right for it that's off.

Screenshot 2023-12-12 at 3 07 10 PM

  1. Turn that toggle on

Screenshot_2023-12-12_at_3_07_14_PM

  1. Go back to the Cypress tab and refresh the browser

Screenshot_2023-12-12_at_3_10_49_PM

We're going to work on a solution in Cypress itself to prevent this behavior from happening, but this should hopefully fix it for local development in the meantime.

chrisbreiding avatar Dec 12 '23 20:12 chrisbreiding