My test clicks on a link which leads to a page on the same super domain. The request to this url within the same super domain then responds with a redirection to a different domain.
The issue is the cookies of the source page are not sent with. Therefore the request fails and the redirection does not happen.
In Cypress 11 I had the following working solution:
cy.contains('ACTIVATE ACCOUNT').invoke('removeAttr', 'target').click();
In Cypress 13 I need to explicitly set the cookies of the source to the visit:
cy.contains('ACTIVATE ACCOUNT').invoke('attr', 'href')
.then(initialHref => {
cy.getCookies().then(cookies => {
const cookieString = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
cy.visit(initialHref, {
headers: {
'Cookie': cookieString,
}
})
});
});
My question is why did the first solution stop working? I didn't find anything in the changelog
At first I thought this may be related to cy.origin, but the link is within the same super domain. I thought about cy.session but that is for sharing session state between tests. Also Cypress sets the cookie domain to the host domain now instead of to the super domain but that is also not it. The visit does not include the cookies anymore.
Edit: As to why I'm asking. It would be cool to continue to use click because I want to emulate a real user in my e2e.