cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.77k stars 3.16k forks source link

Cookies are not send in request within cy.origin #30082

Open techwizzdom opened 1 month ago

techwizzdom commented 1 month ago

Current behavior

The part of the flow in my app is signing a contract, provided by DocuSeal. When I visit a desired URL, e.g. https://docuseal.co/s/pPQVsffQSFwiYm, I try to fill in the contract and submit the form.

The submit fails, and the reason for it is that DocuSeal cookie is not included in the request - so I get 422 as a response.

However, when I check the application tab > cookies within Cypress, I can see that _docu_seal_session is set:

Screenshot 2024-08-22 at 12 00 01

Even if I try to get the cookie with cy.getCookie, nothing happens. I've tried to wait for a few seconds to make sure the cookie is set, but it's not.

Desired behavior

The cookie should be sent with the request. The cookie should also be visible when doing cy.getCookie within a different origin.

Test code to reproduce

  cy.visit("/") // just to visit the base origin first
  cy.visit("https://docuseal.co/s/pPQVsffQSFwiYm")

  cy.origin("https://docuseal.co", () => {
    cy.getCookie("_docu_seal_session").then((cookie) => {
      console.log("cookie", cookie)
    })
    cy.contains("button", "Set Today").should("exist").click()
    cy.get('button[id="submit_form_button"]').click()

    cy.contains("a", "Type").should("exist").click()

    cy.get('input[id="signature_text_input"]').should("exist").type(name)
    cy.get('button[id="submit_form_button"]').click()

    cy.contains("button", "Download").should("exist")
  })

Cypress Version

v13.13.3

Node version

v18.12.1

Operating System

macOS 14.6

Debug Logs

No response

Other

Debugs logs are too long, here's the Google drive link.

jennifer-shehane commented 1 month ago

Repro:

// passes
it('cookie not null', () => {
  cy.visit("https://docuseal.co/s/pPQVsffQSFwiYm")
  cy.getCookie("_docu_seal_session").should('not.be.null')
})

//fails
it('cookie null', () => {
 cy.visit("/") // just to visit the base origin first
  cy.visit("https://docuseal.co/s/pPQVsffQSFwiYm")

  cy.origin("https://docuseal.co", () => {
    cy.getCookie("_docu_seal_session").should('not.be.null')
  })
})
conor-mac-aoidh commented 4 weeks ago

I am seeing the same behaviour with cy.origin. I can see the cookies are defined, but they are not sent with the requests.