Skip to content
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

Workaround idea: Clear cookies in an intercepted request #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

valscion
Copy link
Owner

This PR shows the workaround by @ksazhnev in this reproduction repository

cypress-io/cypress#25841 (comment)

In our case, after the button is clicked, there are two consecutive requests. The first request will respond with a new cookie value, set-cookie, and then the new cookie value will be used in the second request. When seeing the networking tab in dev tools, the browser displays the correct cookies to be sent; however, with debug in Cypress, it does send the old cookies from the cookie jar. I found a temporary workaround in our case, which is deleting cookies after sending the first request and before getting the response with a new cookie value. In this case, Cypress is using cookies from the request header since the jar is empty. I still wonder what the method that updates or syncs the cookie jar value in the Cypress code since the browser cookie jar is correct.

Here the temporary workaround I am currently using: cy.intercept('POST', 'endpoint').as('firstRequest'); cy.get('body').find('button[type="button"]').contains('login').click(); cy.wait('@firstRequest').then((interception) => { // Delete all cookies after sending the request cy.clearCookies(); }); @valscion

However, the workaround seems to require clicking the button triggering the fetch request twice so it is not a satisfiable workaround.

@valscion valscion changed the title Example workaround Workaround idea: Clear cookies in an intercepted request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant