cy.setCookie() set in beforeAll influence on all cy.request()
See original GitHub issueCurrent behavior
cy.request() set cookie from cy.setCookie(). I use cy.setCookie() for service (X) where I execute UI test, I sent cy.request() to the other service (Y), value from cy.setCookie() for service X is not suitable for service Y
Desired behavior
No response
Test code to reproduce
code in suport/index.ts
beforeEach(() => {
// hide cookie policy box
cy.setCookie('cookieconsent_status', 'dismiss')
});
Code in test
cy.request({
method: 'POST',
url: `${providerPortalURL}/api/provider/`,
form: false,
headers: {
Authorization: authorization,
"Content-Type": "application/json"
},
body: (JSON.stringify(provider))
});
request to be sent
Cypress Version
9.5.3
Node version
16.13.0
Operating System
Ubuntu 20.04
Debug Logs
No response
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
cy.setCookie() set in beforeAll influence on all cy.request() · cypress ...
Fast, easy and reliable testing for anything that runs in a browser. - cy.setCookie() set in beforeAll influence on all cy.request() ...
Read more >setCookie | Cypress Documentation
cy.setCookie() yields a cookie object with the following properties: domain; expiry (if specified); httpOnly ...
Read more >Configurations in Cypress and How to Disable Default ...
This configuration specifies the maximum time in milliseconds to wait until a response in commands such cy.request(), cy.wait(), cy.fixture(),cy ...
Read more >How exactly do before and beforeEach work in Cypress?
before() runs before the next block of code. describe("Some test", function() { before(function() { //something ... cy.request('POST', ...
Read more >How to get cookie value in cypress from a cy.request response?
However, it only returns the value null as it is not looking at the request only whats in the browser and to which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After more investigation, the default
domain
for setCookie should bewindow.location.hostname
. This isn’t what is actually happening as the cookie set on a sub-domain results in the superdomain being set. @Marcelinna you wouldn’t be seeing this bug if the behavior was matching the docs as the second domain (providerPortalUrl
) wouldn’t receive the cookie set on yourbaseUrl
subdomain.I’ve created a reproducible example that makes this behavior clear: https://github.com/cypress-io/cypress-test-tiny/tree/zachw/cookie-subdomain-bug
A summary of what the repro demonstrates:
Current behavior
cy.visit('https://subdomain1.example.com')
cy.setCookie('my_cookie', 'is_really_tasty')
-> domain =.example.com
cy.request('https://subdomain2.example.com')
-> cookie is included in requestExpected behavior
cy.visit('https://subdomain1.example.com')
cy.setCookie('my_cookie', 'is_really_tasty', { domain: window.location.hostname })
-> domain =subdomain1.example.com
cy.request('https://subdomain2.example.com')
-> cookie is not included in requestHere is a (private) Slack Thread with more info.
@Marcelinna as for a workaround, can you try using:
@Marcelinna From the (private) information you provided me, the
baseUrl
and theproviderPortalURL
are on the same domain so the cookie should be shared when making a request to theproviderPortalURL
.Can you try explicitly setting the domain in
cy.setCookie('cookieconsent_status', 'dismiss', { domain: 'xxx' })
? You can check your devtools and copy the domain attached to yourcookieconsent_status