Skip to main content

getAllCookies

Get all browser cookies.

Syntax

cy.getAllCookies()
cy.getAllCookies(options)

Usage

Correct Usage

cy.getAllCookies() // Get all cookies

Arguments

options (Object)

Pass in an options object to change the default behavior of cy.getAllCookies().

OptionDefaultDescription
logtrueDisplays the command in the Command log
timeoutresponseTimeoutTime to wait for cy.getAllCookies() to resolve before timing out

Yields

cy.getAllCookies() yields an array of cookie objects. Each cookie object has the following properties:

  • domain: (String)
  • expiry: (Number) (if specified)
  • hostOnly: (Boolean) (if specified)
  • httpOnly: (Boolean)
  • name: (String)
  • path: (String)
  • sameSite: (String) (if specified)
  • secure: (Boolean)
  • value: (String)

cy.getAllCookies() is not a query. It will not update the returned list if further cookies are added after it initially executes.

Examples

Get Cookies

Get cookies after logging in

In this example, we log in through an identity provider which sets a cookie and redirects back to our site, which sets a session cookie.

cy.contains('Log in').click()
cy.origin('https://example.cypress.io', () => {
cy.get('[type=password]').type('*****')
cy.contains('Log in').click()
})
cy.url().should('include', 'profile')
cy.getAllCookies()
.should('have.length', 2)
.then((cookies) => {
expect(cookies[0]).to.have.property('name', 'identity_session_id')
expect(cookies[1]).to.have.property('name', 'session_id')
})

Rules

Requirements

  • cy.getAllCookies() requires being chained off of cy.

Assertions

  • cy.getAllCookies() will only run assertions you have chained once, and will not retry.

Timeouts

  • cy.getAllCookies() should never time out.
caution

Because cy.getAllCookies() is asynchronous it is technically possible for there to be a timeout while talking to the internal Cypress automation APIs. But for practical purposes it should never happen.

See also