mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-19 14:49:43 -05:00
2.7 KiB
2.7 KiB
title: getcookie comments: true
Get a browser cookie.
| Returns | a cookie object literal |
| Timeout | cy.getCookie will wait up for the duration of responseTimeout for the automation server to process this command. |
cy.getCookie( name )
Gets a browser cookie by its name.
This object will have the following properties:
| Properties |
|---|
name |
value |
path |
domain |
httpOnly |
secure |
expiry |
Options
Pass in an options object to change the default behavior of cy.getCookie.
cy.getCookie( name, options )
| Option | Default | Notes |
|---|---|---|
timeout |
responseTimeout |
Total time to wait for the cy.getCookie command to be processed |
log |
true |
whether to display command in command log |
Usage
Get session_id cookie after logging in
In this example, on first login our server sends us back a session cookie.
cy
.login('bob@example.com', 'p@ssw0rd') // example of a custom command
.getCookie('session_id')
.should('have.property', 'value', '189jd09sufh33aaiidhf99d09')
{% note info Using cy.getCookie to test login %} Check out our example recipes using cy.getCookie to test logging in using HTML web forms, logging in using XHR web forms and logging in with single sign on {% endnote %}
Command Log
Get cookie
cy
.getCookie('fakeCookie1')
.should('have.property', 'value', '123ABC')
The commands above will display in the command log as:
When clicking on getCookie within the command log, the console outputs the following:

