Search code examples
javascripttestingcookiescypresse2e-testing

How to configure Cookies with Cypress?


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' } });
});

Solution

  • You can use the cy.setCookie() method.

    Usage ✅:

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