---
id: api/commands/getcookie
title: getCookie | Cypress Documentation
description: Get a browser cookie by its name in Cypress.
section: api
source_path: docs/api/commands/getcookie.mdx
version: 7ada28c0cd90e81cf56fd3fc73de6e6d45c16de6
updated_at: '2026-05-13T21:55:41.935Z'
---
# getCookie

Get a browser cookie by its name.

## Syntax

```
cy.getCookie(name)cy.getCookie(name, options)
```

### Usage

**Correct Usage**

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

### Arguments

**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 |
| --- | --- | --- |
| `domain` | Hostname of the current URL | Retrieves the cookie from the specified domain |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |
| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookie()` to resolve before [timing out](#Timeouts) |

### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

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

*   `domain`
*   `expiry` _(if specified)_
*   `hostOnly` _(if specified)_
*   `httpOnly`
*   `name`
*   `path`
*   `sameSite` _(if specified)_
*   `secure`
*   `value`

`cy.getCookie()` is not a query. It will not retry, or wait for the requested cookie to exist.

#### When a cookie matching the name could not be found:

`cy.getCookie()` yields `null`.

## Examples

### 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 incy.contains('Login').click()cy.url().should('include', 'profile')// retries until cookie with value=189jd09su// is found or default command timeout endscy.getCookie('session_id')  .should('have.property', '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

```
cy.getCookie('my-session-cookie').should('exist')
```

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

```
let cookiecy.getCookie('session_id')  .should('exist')  .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"cy.get('#submit')  .click()  .then(() => {    cy.request({      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](/llm/markdown/app/references/recipes.md#Logging-In), [logging in using XHR web forms](/llm/markdown/app/references/recipes.md#Logging-In) and [logging in with single sign on](/llm/markdown/app/references/recipes.md#Logging-In)

## Rules

### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

*   `cy.getCookie()` requires being chained off of `cy`.

### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)

*   `cy.getCookie()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).

### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)

*   `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

**_Get a browser cookie and make assertions about the object_**

```
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:

## History

| Version | Changes |
| --- | --- |
| [5.0.0](/llm/markdown/app/references/changelog.md#5-0-0) | Removed `experimentalGetCookiesSameSite` and made `sameSite` property always available. |
| [4.3.0](/llm/markdown/app/references/changelog.md#4-3-0) | Added `sameSite` property when the `experimentalGetCookiesSameSite` configuration value is `true`. |

## See also

*   [Cypress Cookies API](/llm/markdown/api/cypress-api/cookies.md)
*   [`cy.clearCookie()`](/llm/markdown/api/commands/clearcookie.md)
*   [`cy.clearCookies()`](/llm/markdown/api/commands/clearcookies.md)
*   [`cy.getCookies()`](/llm/markdown/api/commands/getcookies.md)
*   [`cy.setCookie()`](/llm/markdown/api/commands/setcookie.md)
*   [`Cypress.Cookies.debug()`](/llm/markdown/api/cypress-api/cookies.md)
