如何使用 Cypress 配置 Cookie?

How to configure Cookies with Cypress?

我正在尝试将 Cypress 配置为在每个请求 header 中都有一个 Cookie。我如何实现这一目标?我正在尝试这种方式:

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

您可以使用cy.setCookie()方法。

用法✅:

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