Cookie preservation and multi-domain behavior #22886
Unanswered
dwashko
asked this question in
Questions and Help
Replies: 1 comment 2 replies
-
hello! 👋 have you tried this plugin to keep the whole localStorage between Cypress tests? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Two questions:
Context:
We are testing a wordpress based application using a SAML plugin to Okta. When the page we want to test is visited it does a 302 redirect to okta for login which redirects back to the page. We have multiple spec files, some with more than one context. We were looking for a way to preserve cookies between contexts and/or spec files to avoid having to log in multiple times. The documentation is not clear how cookies are preserved stating it is between tests, but says nothing as whether these tests need to be in the same context and/or spec file.
In our testing it appears the behavior is between tests in the same context in the same spec file. This is where question two comes in. I used the Cypress.Cookies.default function to preserve cookies and added the option {domain: null}. When we visit the page on the baseURL there is a redirection to domain.okta.com where the login happens successfully. That domain redirects back to the baseURL for the rest of the test. When using the cy.getCookies function only the cookies for domain.okta.com get returned, not the cookies set by under the baseURL domain. Passing {domain: null} option will show cookies for the baseURL domain. I see that without cookie preservation the cookies set for domain.okta.com get wiped out between tests but not cookies for any other domain. With cookie preservation in place the cookies for domain.okta.com are preserved. In either configuration no cookies are preserved between contexts or spec files.
Based upon this my understanding is that cookies can only be preserved for what cypress thinks is the current domain between tests in the same context. Cookies cannot be preserved between contexts nor spec files. The exception is that cookies set for the non-current domain are preserved between tests in the same context but not between contexts or spec files. Are these thoughts correct?
Beta Was this translation helpful? Give feedback.
All reactions