{
  "doc": {
    "id": "api/cypress-api/session",
    "title": "Cypress.session | Cypress Documentation",
    "description": "A collection of async session-related helper methods intended to be used alongside the cy.session() command.",
    "section": "api",
    "source_path": "/llm/markdown/api/cypress-api/session.md",
    "version": "ce02913654e2655ee63448bdc92bb92c7b46a619",
    "updated_at": "2026-04-22T19:37:51.587Z",
    "headings": [
      {
        "id": "api/cypress-api/session#cypress-session",
        "text": "Cypress.session",
        "level": 1
      },
      {
        "id": "api/cypress-api/session#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/cypress-api/session#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/cypress-api/session#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/cypress-api/session#clearing-the-all-session-data",
        "text": "Clearing the all session data",
        "level": 3
      },
      {
        "id": "api/cypress-api/session#clearing-the-current-session-data-when-testisolation-is-disabled",
        "text": "Clearing the current session data when testIsolation is disabled",
        "level": 3
      },
      {
        "id": "api/cypress-api/session#verified-the-applied-session-data",
        "text": "Verified the Applied Session Data",
        "level": 3
      },
      {
        "id": "api/cypress-api/session#debugging-cached-session-data",
        "text": "Debugging Cached Session Data",
        "level": 3
      },
      {
        "id": "api/cypress-api/session#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "Cypress.session"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`Cypress.session` is a collection of async session-related helper methods\nintended to be used alongside the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/session.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.session()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "\ncommand."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "// Clear all sessions saved on the backend, including cached global sessions.\nCypress.session.clearAllSavedSessions()\n// Clear all storage and cookie date across all origins associated with the current session.\nCypress.session.clearCurrentSessionData()\n// Get all storage and cookie data across all origins associated with the current session.\nCypress.session.getCurrentSessionData()\n// Get all storage and cookie data saved on the backend associated with the provided session id.\nCypress.session.getSession(id)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Clearing all session and automatically re-running the spec\n`Cypress.session.clearAllSavedSessions()` can also be done by clicking the\n\"Clear All Sessions\" button in the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/session.md#The-Instrument-Panel",
            "children": [
              {
                "type": "text",
                "value": "Sessions Instrument Panel"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "id (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The name of the session used to retrieve data storage and cookie data."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Clearing the all session data"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, Cypress will clear the current session data before each test\nwhen `testIsolation` is enabled. You can also remove all cached session data\nwith `Cypress.session.clearAllSavedSessions()`."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "Cypress.session.clearAllSavedSessions()"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Clearing the current session data when testIsolation is disabled"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, Cypress will clear the current session data before each test\nwhen `testIsolation` is enabled. If you have disabled `testIsolation` for a\nsuite, it can be helpful to clear the current session data in a `before()` block\nto ensure the suite started in a clean test slate."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "describe('Dashboard', { testIsolation: false }, () => {\n  before(() => {\n    // ensure clean test slate for these tests\n    cy.then(Cypress.session.clearCurrentSessionData)\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Verified the Applied Session Data"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To check all cookies, localStorage and sessionStorage that was applied after\n`cy.session()` completes, you can use `Cypress.session.getCurrentSessionData()`.\nThis can be helpful for quickly analyzing the current browser context while\nwriting your `cy.session()` command."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Since this is an all-in-one helper of the `cy.getAllCookies()`,\n`cy.getAllLocalStorage()` and `cy.getAllSessionStorage()` commands, we generally\nrecommend leveraging these commands for asserting the correct session data has\nbeen applied in the session validation block."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "it('debug session', () => {\n    cy.session('id', () => {\n        ...\n    })\n    .then(async () => {\n        const sessionData = await Cypress.session.getCurrentSessionData()\n        cy.debug()\n    })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Debugging Cached Session Data"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If your session seems to be recreated more than expected, or doesn't seem to be\napplying the cookies, `localStorage` or `sessionStorage` data that you'd expect,\nyou can use `Cypress.session.getSession(id)` to view what session data has been\ncached by `cy.session()`. If you are missing any data, your setup and/or\nvalidate function may not be waiting long enough for all attributes to be\napplied to there page before the `cy.session()` command saves and finishes."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "it('debug session', () => {\n    cy.session('id', () => {\n        ...\n    })\n    .then(async () => {\n        const sessionData = await Cypress.session.getSession('id')\n        cy.debug()\n    })\n})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/session.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.session()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 601
}