mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-02 21:10:47 -05:00
2.6 KiB
2.6 KiB
title, comments
| title | comments |
|---|---|
| getCookies | true |
Get all of the browser cookies.
Syntax
cy.getCookies()
cy.getCookies(options)
Usage
cy.getCookies() cannot be chained off any other cy commands, so should be chained off of cy for clarity.
{% fa fa-check-circle green %} Valid Usage
cy.getCookies() // Get all cookies
Arguments
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of cy.getCookies().
| Option | Default | Notes |
|---|---|---|
log |
true |
Whether to display command in Command Log |
timeout |
responseTimeout |
Total time to wait for the cy.getCookies() command to be processed |
Yields
cy.getCookies() yields an array cookie objects. Each cookie object has the following properties:
namevaluepathdomainhttpOnlysecureexpiry
Timeout
cy.getCookies() will continue to look for cookies for the duration of the defaultCommandTimeout.
Examples
Get Cookies
Get cookies after logging in
In this example, on first login our server sends us back a session cookie.
// assume we just logged in
cy.contains('Login').click()
cy.url().should('include', 'profile')
cy.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) {
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:
See also
- {% url
cy.clearCookie()clearcookie %} - {% url
cy.clearCookies()clearcookies %} - Cypress Cookies API
- getCookie
- setCookie

