cypress: cy.getCookie() does not support timeouts
Current behavior:
Both of the following lines result in expected null to exist
although the cookie becomes available within a timeframe of about 200ms:
cy.getCookie('token').should('exist')
cy.getCookie('token', { timeout: 5000 }).should('exist')
Adding a cy.wait(1000)
above the lines will make them pass without error.
Desired behavior:
cy.getCookie
should use the default timeout when used together with ‘should’cy.getCookie
should support thetimeout
argument as documented here: https://on.cypress.io/getcookie#Arguments
Steps to reproduce:
Use cy.getCookie('someCookie').should('exist')
for a cookie which is saved with a little delay, e.g. session cookie after login.
Versions
cypress 3.4.0, electron 61, 5.2.1-arch1-1-ARCH
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 31
- Comments: 21 (2 by maintainers)
Recording of this issue in action: https://user-images.githubusercontent.com/24389501/168602990-48e7f37f-f25d-487b-859c-ef3bf07d9ae9.mp4
According to the docs for
.should()
:However you can see from the video that this fails on the first assertion, and does not retry
The issue here is
getCookie()
is resolving within the timeout, but it will not retry assertions (or re-querying for the expected value) until the timeout has expired. Thecy.getCookie()
command needs to be updated to become a query command so this behaves as expected by re-pulling the value and running the assertions without workaround suggested above.Hi @jennifer-shehane,
I dont think 30 seconds timeout exists. Any particular version to look out for?
Also, passing a timeout param would be great!
Thanks!
After API login in before, the cookie (in before is too) is null (empty) on the CI. Locally is normal.
A little better workaround is to use https://github.com/NoriSte/cypress-wait-until
I have a similar issue. I’m passing a timeout of 10 seconds, but the test immediately faces a
expects null to exists
in this line and without respecting thetimeout: 10000
cy.getCookie()
looks to use the defaultresponseTimeout
of 30seconds.code: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/cookies.coffee#L80
We do have some tests that this timeout is being sent through correctly to the command - and that it times out if it is not present in this time, but we actually do not have a test for called
cy.getCookie()
with the cookie initially not existing, setting the cookie, and ensuring the test passes.I’ll go ahead and add a test for this in our codebase to see if this is working.