Improve this doc

Get a browser cookie by its name.


cy.getCookie(name, options)


Correct Usage

cy.getCookie('auth_key')     // Get cookie with name 'auth_key'


name (String)

The name of the cookie to get. Required.

options (Object)

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

Option Default Description
log true Displays the command in the Command log
timeout responseTimeout Time to wait for cy.getCookie() to resolve before timing out


cy.getCookie() yields a cookie object with the following properties:

  • domain
  • expiry (if specified)
  • httpOnly
  • name
  • path
  • sameSite (if specified)
  • secure
  • value

When a cookie matching the name could not be found:

cy.getCookie() yields null.


Session id

Get session_id cookie after logging in

In this example, on first login, our server sends us back a session cookie.

// assume we just logged in
cy.url().should('include', 'profile')
// retries until cookie with value=189jd09su
// is found or default command timeout ends
  .should('', 'value', '189jd09su')
  .then((cookie) => {
    // cookie is an object with "domain", "name" and other properties

You can check the cookie existence without comparing any of its properties


If you need the cookie value, for example to use in a subsequent call

let cookie

  .then((c) => {
    // save cookie until we need it
    cookie = c

// some time later, force the "cy.request"
// to run ONLY after the cookie has been set
// by placing it inside ".then"
  .then(() => {
      url: '/api/admin',
      headers: {
        'my-token-x': cookie.value

Using cy.getCookie() to test logging in

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



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


  • cy.getCookie() will only run assertions you've chained once, and will not retry.


  • cy.getCookie() should never time out.

Because cy.getCookie() 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.

Command Log

cy.getCookie('fakeCookie1').should('', 'value', '123ABC')

The commands above will display in the Command Log as:

Command Log getcookie

When clicking on getCookie within the command log, the console outputs the following:

Console Log getcookie


Version Changes
5.0.0 Removed experimentalGetCookiesSameSite and made sameSite property always available.
4.3.0 Added sameSite property when the experimentalGetCookiesSameSite configuration value is true.

See also