{
  "doc": {
    "id": "api/commands/getcookie",
    "title": "getCookie | Cypress Documentation",
    "description": "Get a browser cookie by its name in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/getcookie.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/commands/getcookie#getcookie",
        "text": "getCookie",
        "level": 1
      },
      {
        "id": "api/commands/getcookie#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#when-a-cookie-matching-the-name-could-not-be-found",
        "text": "When a cookie matching the name could not be found:",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#session-id",
        "text": "Session id",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#get-session-id-cookie-after-logging-in",
        "text": "Get session_id cookie after logging in",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#using-cy-getcookie-to-test-logging-in",
        "text": "Using cy.getCookie() to test logging in",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/getcookie#syntax",
      "doc_id": "api/commands/getcookie",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.getCookie(name)cy.getCookie(name, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.getCookie('auth_key') // Get cookie with name 'auth_key'\n```\n\n### Arguments\n\n**name _(String)_**\n\nThe name of the cookie to get. Required.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.getCookie()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `domain` | Hostname of the current URL | Retrieves the cookie from the specified domain |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookie()` to resolve before [timing out](#Timeouts) |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n`cy.getCookie()` yields a cookie object with the following properties:\n\n*   `domain`\n*   `expiry` _(if specified)_\n*   `hostOnly` _(if specified)_\n*   `httpOnly`\n*   `name`\n*   `path`\n*   `sameSite` _(if specified)_\n*   `secure`\n*   `value`\n\n`cy.getCookie()` is not a query. It will not retry, or wait for the requested cookie to exist.\n\n#### When a cookie matching the name could not be found:\n\n`cy.getCookie()` yields `null`.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 233
    },
    {
      "id": "api/commands/getcookie#arguments",
      "doc_id": "api/commands/getcookie",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**name _(String)_**\n\nThe name of the cookie to get. Required.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.getCookie()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `domain` | Hostname of the current URL | Retrieves the cookie from the specified domain |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookie()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 115
    },
    {
      "id": "api/commands/getcookie#yields-learn-about-subject-management",
      "doc_id": "api/commands/getcookie",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n`cy.getCookie()` yields a cookie object with the following properties:\n\n*   `domain`\n*   `expiry` _(if specified)_\n*   `hostOnly` _(if specified)_\n*   `httpOnly`\n*   `name`\n*   `path`\n*   `sameSite` _(if specified)_\n*   `secure`\n*   `value`\n\n`cy.getCookie()` is not a query. It will not retry, or wait for the requested cookie to exist.\n\n#### When a cookie matching the name could not be found:\n\n`cy.getCookie()` yields `null`.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/getcookie#examples",
      "doc_id": "api/commands/getcookie",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Session id\n\n#### Get `session_id` cookie after logging in\n\nIn this example, on first login, our server sends us back a session cookie.\n\n```\n// 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  })\n```\n\nYou can check the cookie existence without comparing any of its properties\n\n```\ncy.getCookie('my-session-cookie').should('exist')\n```\n\nIf you need the cookie value, for example to use in a subsequent call\n\n```\nlet 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,      },    })  })\n```\n\n#### Using `cy.getCookie()` to test logging in\n\nCheck 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)\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 243
    },
    {
      "id": "api/commands/getcookie#session-id",
      "doc_id": "api/commands/getcookie",
      "heading": "Session id",
      "heading_level": 3,
      "content_markdown": "### Session id\n\n#### Get `session_id` cookie after logging in\n\nIn this example, on first login, our server sends us back a session cookie.\n\n```\n// 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  })\n```\n\nYou can check the cookie existence without comparing any of its properties\n\n```\ncy.getCookie('my-session-cookie').should('exist')\n```\n\nIf you need the cookie value, for example to use in a subsequent call\n\n```\nlet 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,      },    })  })\n```\n\n#### Using `cy.getCookie()` to test logging in\n\nCheck 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)\n",
      "section": "api",
      "anchors": [
        "session-id"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 240
    },
    {
      "id": "api/commands/getcookie#get-session-id-cookie-after-logging-in",
      "doc_id": "api/commands/getcookie",
      "heading": "Get session_id cookie after logging in",
      "heading_level": 4,
      "content_markdown": "#### Get `session_id` cookie after logging in\n\nIn this example, on first login, our server sends us back a session cookie.\n\n```\n// 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  })\n```\n\nYou can check the cookie existence without comparing any of its properties\n\n```\ncy.getCookie('my-session-cookie').should('exist')\n```\n\nIf you need the cookie value, for example to use in a subsequent call\n\n```\nlet 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,      },    })  })\n```\n",
      "section": "api",
      "anchors": [
        "get-session-id-cookie-after-logging-in"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 189
    },
    {
      "id": "api/commands/getcookie#using-cy-getcookie-to-test-logging-in",
      "doc_id": "api/commands/getcookie",
      "heading": "Using cy.getCookie() to test logging in",
      "heading_level": 4,
      "content_markdown": "#### Using `cy.getCookie()` to test logging in\n\nCheck 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)\n",
      "section": "api",
      "anchors": [
        "using-cy-getcookie-to-test-logging-in"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 47
    },
    {
      "id": "api/commands/getcookie#rules",
      "doc_id": "api/commands/getcookie",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.getCookie()` requires being chained off of `cy`.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `cy.getCookie()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.getCookie()` should never time out.\n\nBecause `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.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 101
    },
    {
      "id": "api/commands/getcookie#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/getcookie",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.getCookie()` should never time out.\n\nBecause `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.\n",
      "section": "api",
      "anchors": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/getcookie#command-log",
      "doc_id": "api/commands/getcookie",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Get a browser cookie and make assertions about the object_**\n\n```\ncy.getCookie('fakeCookie1').should('have.property', 'value', '123ABC')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `getCookie` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/getcookie#history",
      "doc_id": "api/commands/getcookie",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [5.0.0](/llm/markdown/app/references/changelog.md#5-0-0) | Removed `experimentalGetCookiesSameSite` and made `sameSite` property always available. |\n| [4.3.0](/llm/markdown/app/references/changelog.md#4-3-0) | Added `sameSite` property when the `experimentalGetCookiesSameSite` configuration value is `true`. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/getcookie.json",
      "token_estimate": 51
    }
  ]
}