mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-19 14:49:43 -05:00
2.3 KiB
2.3 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| setcookie | true |
Set a browser cookie.
| Returns | a cookie object |
| Timeout | cy.setCookie will wait up for the duration of responseTimeout for the automation server to process this command. |
cy.setCookie( name, value )
Sets a browser cookie.
Options
Pass in an options object to change the default behavior of cy.setCookie.
cy.setCookie( name, value, options )
| Option | Default | Notes |
|---|---|---|
path |
/ |
the cookie path |
domain |
window.location.hostname |
the domain the cookie is visible to |
secure |
false |
whether the cookie is a secure cookie |
httpOnly |
false |
whether the cookie is an HTTP only cookie |
expiry |
20 years into the future | when the cookie expires, specified in seconds since Unix Epoch. |
timeout |
responseTimeout |
Total time to wait for the cy.setCookie command to be processed |
log |
true |
whether to display command in command log |
Usage
Set a cookie
cy
.getCookies().should('be.empty')
.setCookie('session_id', '189jd09sufh33aaiidhf99d09')
.getCookie('session_id').should('have.property', 'value', '189jd09sufh33aaiidhf99d09')
Command Log
Get cookie
cy
.getCookies().should('be.empty')
.setCookie('fakeCookie1', '123ABC')
.getCookie('fakeCookie1').should('have.property', 'value', '123ABC')
The commands above will display in the command log as:
When clicking on setCookie within the command log, the console outputs the following:

