How to configure Cookies with Cypress?

Viewed 108

I'm trying to configure Cypress to have a Cookie in each request header. How do I achieve this? I'm trying this way:

it('successfully loads', () => {
    cy.visit('http://localhost:4200', { headers: { Cookie: 'JSESSIONID=064063D96094773DACBD93A2FD31736F' } });
});
1 Answers

You can use the cy.setCookie() method.

Usage ✅:

cy.setCookie('auth_key', '123key') // Set the 'auth_key' cookie to '123key'
Related