-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cookies not being set after cy.request() even though set-cookie is present in response header #1074
Comments
I'm going to guess and say that the URL you are making the Whenever you look at the Cookies in the browser it is always partitioned by origin policy. What is the URL that you are Also you can use |
Actually yes I can tell in your image this is exactly what is happening. You are inspecting cookies for These origins do not match and cookies are not applied between them. However |
|
However if you were to then visit |
Also - this is likely happening to you because when Cypress starts it starts on a random port if you have not set What you're likely doing is immediately making a request to programmatically log in a user. This works, you just wont "see" the cookies until you then visit your origin. If you set |
Your last comment describes the problem exactly. Seems like my situation fell somewhere BETWEEN points 2 and 3 here though - the first command I issue is |
Also, I did have host set in |
Cypress does not do anything meaningful or ever look at environment variables you've set. So It's actually an antipattern to use something like We recently updated the docs to note that here: https://docs.cypress.io/guides/guides/environment-variables.html# I'm going to move that section into Best Practices soon, and call this out explicitly. We've seen other users do the same anti pattern. As a final note - you didn't ever really need the Setting |
Current behavior:
I have the following custom command to perform a login and am running it from a simple test (with username/password being supplied from Cypress.env variables):
A 200 status is returned, and in both the request and response in Chrome Dev Tools, the cookies appear as expected:
However, the cookies are not being set in the browser even though they're coming back in the response header. I'm console logging the cookie value after
cy.login()
executes in order to verify the absence/presence of cookies:In the Django backend I have verified that the user is, in fact, being logged in. This Django logged-in state is verified by the presence of the sessionid that Django includes with the response after a successful login along with the csrftoken that it always passes (whether logged in or not).
I have a smoke test set up to test login functionality using
cy.visit()
, and cookies are set fine after execution ofcy.visit()
:Am I missing something, or is
cy.request()
perhaps not always handling the setting of cookies correctly?The text was updated successfully, but these errors were encountered: