cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.52k stars 3.2k forks source link

Unresolved API calls cause Electron to fail all subsequent tests #1055

Closed QualityADHD closed 6 years ago

QualityADHD commented 6 years ago

Is this a Feature or Bug?

Bug

Current behavior:

Unresolved API calls cause Electron to timeout each subsequent test in the suite. This happens when using the Electron GUI or the CLI. Chrome handles this error gracefully and allows the tests to pass.

In addition, the failure causes the log on the left-hand side of the GUI to disappear, and you have to completely kill Cypress in order for new tests to run.

Desired behavior:

All unresolved API calls should be cancelled before a new test runs. Ideally, the behavior could mimic what Chrome 63 does.

How to reproduce:

Write a test where the API will not resolve then put that test in the middle of a suite. You will see that all tests prior will pass, but any test after will fail.

Additional Info (images, stack traces, etc)

Electron, showing the calls that will timeout:

screen shot 2017-12-11 at 1 40 15 pm

Chrome, showing the aborted calls:

screen shot 2017-12-11 at 1 39 29 pm

Failure showing the log missing:

screen shot 2017-12-11 at 2 04 53 pm

brian-mann commented 6 years ago

This is unfortunately a known issue and its documented in depth here:

https://github.com/cypress-io/cypress/issues/686

There is not really an elegant solution around this - we in fact used to abort current running XHR's specifically for this purpose, but it actually caused other issues. Because Cypress runs async things between tests, it was also possible in that brief moment for your app to make another XHR, which would then demonstrate the same problems as you're describing.

The only real solution for this is doing what is described in that issue.

Today, if you wanted to "work around this" you would have to visit a "blank page" in an afterEach handler, which is really awful and ugly. Essentially this would "wipe out" your application at the end of the test which forces it to be completely torn down. There might be another easier way but I can't think of one.

QualityADHD commented 6 years ago

Thank you for the quick reply! I figured that you guys might have ran into this before, so it's good to know that it's been explored. The discussion in the other thread makes sense; in the meantime, I will do the ugly workaround since this is mission-critical for us.

brian-mann commented 6 years ago

Some other ideas - if your application has a "killswitch" you could directly call that from Cypress itself as long as your app exposed this globally...

afterEach(() => {
  cy.window().its('App').invoke('kill')
})

You could also likely force the app to visit about:blank... I don't think `cy.visit('about:blank') works but you could probably do this..

afterEach(() => {
  cy.window().then((win) => {
    win.location.href = 'about:blank'
  })
})

One final suggestion - conditionally run the afterEach with an environment variable, so that you can disable these when you're working on a single test in the GUI, but enable it when you're doing a complete run.

QualityADHD commented 6 years ago

Awesome tips, thank you very much!

Sadly, no kill switch...looks like I'll have to try the 'about:blank' idea. Luckily, this issue is only happening with 2 tests, so it should not be too invasive. I'll definitely put it into an env variable, would be nice to turn off as needed.

jennifer-shehane commented 6 years ago

Video of test run: https://files.gitter.im/cypress-io/cypress/uJe7/0zezc.mp4

The thing that troubled me the most was the command log disappearing halfway through the video recording.

Gayathri-Kesavakannan commented 2 years ago

Hi , I am facing this issue in electron only in headed mode. Workaround seems to flaky as some time blank page as browser waits for about:blank page to load. Any other workarounds ??