mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
2.3 KiB
2.3 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| clearcookies | true |
Clears all of the browser cookies.
Cypress automatically invokes this command before each test to prevent state from building up. You shouldn't need to invoke this command unless you're using it to clear cookies inside a single test.
| Returns | null |
| Timeout | cy.clearCookies will wait up for the duration of responseTimeout for the automation server to process this command. |
cy.clearCookies()
Clears all the browser cookies.
Options
Pass in an options object to change the default behavior of cy.clearCookies.
| Option | Default | Notes |
|---|---|---|
timeout |
responseTimeout |
Total time to wait for the cy.clearCookies command to be processed |
log |
true |
whether to display command in command log |
Usage
Clear cookies after logging in
In this example, on first login our server sends us back a session cookie. After invoking cy.clearCookies this clears the session cookie, and upon navigating to an unauthorized page, our server should have redirected us back to login.
cy
.login("bob@example.com", "p@ssw0rd") // example of custom command
.clearCookies()
.visit("/dashboard") // we should be redirected back to login
.url().should("eq", "login")
Command Log
Clear cookies after getting cookies
cy
.getCookies().should('have.length', 1)
.clearCookies()
.getCookies().should('be.empty')
The commands above will display in the command log as:
When clicking on clearCookies within the command log, the console outputs the following:

