mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-21 23:59:33 -05:00
2.5 KiB
2.5 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| getcookies | true |
Gets all of the browser cookies.
| Returns | an array of cookie objects |
| Timeout | cy.getCookies will wait up for the duration of responseTimeout for the automation server to process this command. |
cy.getCookies()
Gets the browser cookies.
Each cookie 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.getCookies.
| Option | Default | Notes |
|---|---|---|
timeout |
responseTimeout |
Total time to wait for the cy.getCookies command to be processed |
log |
true |
whether to display command in command log |
Usage
Get cookies 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
.getCookies()
.should('have.length', 1)
.then(function(cookies) {
expect(cookies[0]).to.have.property('name', 'session_id')
})
Command Log
Get cookies
cy
.getCookies()
.should('have.length', 1)
.then( function(cookies) {
// each cookie has these properties
expect(cookies[0]).to.have.property('name', 'fakeCookie1')
expect(cookies[0]).to.have.property('value', '123ABC')
expect(cookies[0]).to.have.property('domain')
expect(cookies[0]).to.have.property('httpOnly')
expect(cookies[0]).to.have.property('path')
expect(cookies[0]).to.have.property('secure')
})
The commands above will display in the command log as:
When clicking on getCookies within the command log, the console outputs the following:

