-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Cypress doesn't always clean up cookies #781
Comments
I simplified my |
Do you think this is related to this issue? #408 |
@brian-mann I checked that one. It's not a cross-domain login so I guess not. Am I right that I should never manually call |
Correct, Cypress automatically clears cookies prior to each test. You can use the cookie debug API to print every single modification to every single cookie. |
Is there any way to dump the command log of a |
Can confirm, Cypress does not clear the cookies between tests, it let it leaks. This not happens all the time though. |
We are having this problem intermittently on Mac OS X Sierra w/ Chrome 63 and Electron 53 on the first test in our spec. Printing out It has been hard to replicate this, there doesn't seem to be a pattern to force it to happen. |
On my end also the first test in the spec that fails. Obviously only if other specs have been run before. |
In my case it was silly, I had whitelist configuration to keep session id between different Cypress.Cookies.defaults({whitelist: 'sid'}); So I need to clean up this particular cookie before run whole test spec: |
I'm not using that feature so that's not it. |
Any luck with v2? |
Didn't see this fail anymore. Were there any changes on this part? |
I have noticed it happen still |
Ok now I have too. |
I'm having this issue as well. |
I have some problem with cookies/session, my workaround was first select "electron" and run tests that will not work properly, after that select "Chrome" and run tests that work. Cypress package version: 2.1.0 |
I have the problem too, cookies persist. That means I am always logged in and my login test fails. Problem is on both Windows 7 and Linux (Debian 9.4), in Chrome, Cypress 2.1.0. Can this be an issue of Chrome? I noticed some interesting pattern: cookies are cleared as expected, when I:
|
the same problem |
same problem. cookies are persisting. |
My temporary workaround: describe('Auth', function () {
before(() => {
// remove this when issue will be solved
// https://github.com/cypress-io/cypress/issues/781
cy.visit('/')
cy.clearCookies()
cy.reload()
})
... Place this code at the very beginning of your tests (I guess they are ordered alphabetically). |
@anurbol we went with something similar, but we have several |
@kc-beard You can also define a |
@verheyenkoen thanks for the tip! I didn't know that. Seems like that's covered in the docs too but i missed it (https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Support-file) |
@kc-beard in my experience, placing this in one file (which is starting point of your tests) is enough. verheyenkoen's answer is 2nd option, but as said, overkill (slows down tests execution significally). |
This is definitely a significant issue! Feel like something that requires warnings in the docs until it's resolved, as it took us a while to figure out why tests were failing when the documentation claims that cookies are cleared between tests. |
@verheyenkoen I am upgraded to 8.2.0 and came to this issue due to the problem occurring for me. So this is still an issue. |
Still the same issue for me too on 8.2.0 |
@waldobeest @WinstonN you guys need to enable the new experimental feature- worked for me |
This worked for me! Specifying the actual domain also works but this is even better. Thanks! |
We released If you have any feedback about |
I found something similar to what you describe, although the solution didn't seem to work, sadly. Upon closer inspection, I noticed that the cookies are cleared before each test, and then, for some reason, get reloaded. You can clearly see that the website is resetting to default values every single time, as it is supposed to per described in the documentation, but then the values from a previous session get reloaded. I tried simply disabling the cookies altogether in the web driver (chrome in my case), but this broke cypress, so I had to reset it to allow cookies. PS: I am noob, just trying to help |
Shouldn't this be high prio and not backlog? The issue is now open for years and still not resolved, leaving us with flaky tests when dealing with cookies/session. |
@jremmurd have you tried using the experimental session API? |
I dont want to share cookies between tests (as the original issue description says) and this is what the new API would provide, right? The thing is that I would expect all cookies to be cleared between separate tests, but they are not always. Also manually clearing them does not work reliably. How would the session API help me with that? As from my previous post:
|
@jremmurd I've adopted the Session api because it:
It's possible that some other domain cookie is set causing the second check to fail, but I cannot be sure. With Session API you can decide what cookies to share, if your case is none, you should be able to run |
@jremmurd I'd also be curious, maybe you can print out the cookies that is returned from |
I'm going to close this issue because this is solved by enabling the experimentalSessionAndOrigin flag and utilizing |
Is there a timeline for moving |
@michaelmdresser We will be releasing Session as GA in the upcoming v12 release. We are expecting to release in early December. |
I tried a couple of workarounds above without any help, but strangely enough, calling |
Thanks bro, your answer solved my problem =) |
Still an issues as of march 2024 |
@chlorophant Please open a new issue describing it and providing a full example of it. We recommend using cy.session. |
I just stumbeled on a similar issue right now. I had a full on e2e login & logout test and when I later wanted to just login with a request, upon logout it does not clear the coockie (which does when I do it 'manually' via typing and clicking with cypress (instead of cy.request /login auth endpoint and saving token |
Current behavior:
We have a test that checks if an unauthorized user is redirected to the login page when directly visiting a URL to the "backend" site. This test occasionally fails. From the screenshot it is clear that the user was just sent to the specific backend page without login.
I checked (console props of the
cy.visit
command &cy.getCookies
+cy.writeFile
) and in some cases the auth cookie from the previous test is not cleared. For that I'm using a custom login command that only fetches cookies once (per username) and stores them in the global scope. Then I usecy.setCookie()
to set the cookie again.In this case the cookie was set in the
beforeEach
hook of the previous test.Obviously this never fails if I just run the latter spec.
Desired behavior:
Obviously, by default (unless
Cypress.Cookies.preserveOnce()
is used), all cookies should be cleared before a test run starts.How to reproduce:
This is hard. I couldn't narrow it down to one specific always-reproducable scenario but these are things I can confidently say about it:
cypress run --headed
)cypress open
)I'm not sure but it seems to fail easier if I change the focus to other apps (or spaces) while running the tests, but even that isn't deterministic for me.
The text was updated successfully, but these errors were encountered: