getAllLocalStorage

Get localStorage data for all origins with which the test has interacted.

Syntax

cy.getAllLocalStorage()
cy.getAllLocalStorage(options)

Usage

Correct Usage

cy.getAllLocalStorage()

Arguments

options (Object)

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

OptionDefaultDescription
logtrueDisplays the command in the Command log

Yields

cy.getAllLocalStorage() yields an object where the keys are origins and the values are key-value pairs of localStorage data.

For example, if key1 is set to value1 on https://example.com and key2 is set to value2 on https://other.com, cy.getAllLocalStorage() will yield:

{
  'https://example.com': {
    key1: 'value1',
  },
  'https://other.com': {
    key2: 'value2',
  },
}

Examples

Get all localStorage

cy.visit('https://example.com', {
  onBeforeLoad(win) {
    win.localStorage.setItem('key', 'value')
  },
})

cy.getAllLocalStorage().then((result) => {
  expect(result).to.deep.equal({
    'https://example.com': {
      key: 'value',
    },
  })
})

Rules

Requirements

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

Assertions

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

Timeouts

  • cy.getAllLocalStorage() cannot time out.

See also