question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress clears cookies before JavaScript is terminated

See original GitHub issue

Current behavior

When Cypress starts executing a new test, it will clear all cookies even if the JavaScript code in the old test is still executing. This can be the source of confusing errors reporting 401 responses from the backend where Cypress wrongly reports them as having been triggered by beforeEach.

Desired behavior

Make sure that the JavaScript code from the previous test has stopped or block all network traffic between tests before clearing all cookies.

Versions

6.4.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
geigerzaehlercommented, May 31, 2021

Here’s a minimal example to reproduce the issue. It’s still present in 7.4.0

<!DOCTYPE html>
<script>
  document.cookie = "foo=bar"
  let interval = setInterval(() => {
    if (document.cookie !== "foo=bar") {
      clearInterval(interval)
      throw new Error(`Invalid cookie ${document.cookie}. Hash: ${document.location.hash}`)
    }
  }, 10)
</script>
it("first", () => {
  cy.visit("./index.html#first")
  cy.wait(1000)
})

it("second", () => {
  cy.visit("./index.html#second")
  cy.wait(1000)
})

The first test case always passes. The second always errors because the first instance of the app (as witnessed by the #first location) crashes.

0reactions
cypress-bot[bot]commented, Dec 6, 2022

Released in 12.0.0.

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

clearCookies - Cypress Documentation
Cypress automatically clears all cookies before each test to prevent state from being shared across tests when test isolation is enabled.
Read more >
Cypress not re-using cookies or session in headless mode
What I have tried: I have managed to get a code snippets from here that stores the cookies after each test, which works...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
intercept happens in the Command Log was a user experience failure. The solution. Make sure the network intercept is registered before the ...
Read more >
Cypress Tutorial - Tutorialspoint
Before proceeding with the tutorial, you should have a fair knowledge on JavaScript and object oriented programming concepts.
Read more >
Testing Browser Alerts, Confirmations, and Prompts with ...
How can we use automation tools like Cypress to test them? ... testing frameworks take advantage of JavaScript's ability to query selectors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found