-
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
cy.setCookie is Not Setting Desired Cookie Expiry #5599
Comments
Hey @toddmkemp, simplifying this test - it does set a cookies expiry and overwrites an existing set when the cookie is set on the same domain here. it('Expiry Problem', function () {
cy.visit('https://example.cypress.io/commands/traversal')
cy.setCookie('foo', 'bar', { expiry: 50000000 })
cy.setCookie('foo', 'bar', { expiry: 10000000000 })
cy.getCookie('foo').then((foo) => {
expect(foo.expiry).to.equal(10000000000)
})
}) We'll need a more specific example of the issue that we can run on our computer exhibiting the exact issue before we can move forward. |
I've investigated a little more and the issue is a little more complex than what I initially thought. Using a similar approach to cookie manipulation that you took, I wrote the following: describe('Cypress Cookie Issue', function () {
beforeEach(function () {
cy.visit('https://en.wikipedia.org/')
})
it('Passes', function () {
cy.getCookie('WMF-Last-Access-Global')
cy.setCookie('WMF-Last-Access-Global', 'value', {expiry: 10000000000})
cy.getCookie('WMF-Last-Access-Global').then((cookie) => {
expect(cookie.expiry).to.equal(10000000000)
})
})
it('Fails', function () {
cy.getCookie('WMF-Last-Access')
cy.setCookie('WMF-Last-Access', 'value', {expiry: 10000000000})
cy.getCookie('WMF-Last-Access').then((cookie) => {
expect(cookie.expiry).to.equal(10000000000)
})
})
}) The first test passes and the second one fails. The only difference between the tests is the cookie itself. Specifically, the domains of the cookies are different which seems to be what is problematic here. Please let me know if you have questions or if there is anything else I can provide to help you diagnose the issue. |
@jennifer-shehane : Did my latest comments provide any clarity on the matter? I'm happy to continue to investigate if you are still unable to reproduce the problem. |
Hello again @jennifer-shehane. I saw in the release notes for Cypress versions since 3.6.0 that there have been a number of fixes for behaviour involving cookies so I upgraded to version 3.8.1 to see if that would fix this issue but I am still seeing the failure here. Again, the only difference between these tests is the cookie itself, so I would expect both tests to pass. Please provide an update on this issue. |
@toddmkemp I have confirmed the behavior you're explaining. There are a couple of other differences in the cookies, mainly one is it('Passes', function () {
cy.visit('https://en.wikipedia.org/')
cy.setCookie('WMF-Last-Access-Global', 'value', { expiry: 10000000000 })
cy.getCookie('WMF-Last-Access-Global').then((cookie) => {
expect(cookie.httpOnly).to.be.false
expect(cookie.secure).to.be.false
expect(cookie.domain).to.eq('.wikipedia.org')
expect(cookie.expiry).to.equal(10000000000)
})
})
it('Fails', function () {
cy.visit('https://en.wikipedia.org/')
cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
cy.getCookie('WMF-Last-Access').then((cookie) => {
expect(cookie.httpOnly).to.be.true
expect(cookie.secure).to.be.true
expect(cookie.domain).to.eq('en.wikipedia.org')
expect(cookie.expiry).to.equal(10000000000) // fails here <---
})
}) |
Hello again @jennifer-shehane . Thanks for investigating; glad to hear you were able to reproduce the problem. I hope that we will see this issue fixed in the near future! :) |
This is still an issue in 9.5.3 |
related to: #20588 |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
The it('Fails', function () {
cy.visit('https://en.wikipedia.org/')
cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
cy.getCookie('WMF-Last-Access').then((cookie) => {
expect(cookie.httpOnly).to.be.true
expect(cookie.secure).to.be.true
expect(cookie.domain).to.eq('en.wikipedia.org')
expect(cookie.expiry).to.equal(10000000000)
})
}) |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
This is still failing with the latest version of Cypress (v13.15.1 as of writing). it('Fails', function () {
cy.log(`Cypress version: ${Cypress.version}`)
cy.visit('https://en.wikipedia.org/')
cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
cy.getCookie('WMF-Last-Access').then((cookie) => {
expect(cookie.httpOnly).to.be.true
expect(cookie.secure).to.be.true
expect(cookie.domain).to.eq('en.wikipedia.org')
expect(cookie.expiry).to.equal(10000000000)
})
}) |
Current behavior:
cy.setCookie
is not setting theexpiry
as desired.Desired behavior:
cy.setCookie
sets theexpiry
that the code provides.Steps to reproduce:
Versions
Cypress 3.6.0, Chrome 78.
I started experiencing this problem when I upgraded from Cypress 3.2.0 to 3.6.0.
The text was updated successfully, but these errors were encountered: