Skip to main content

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.cypress.io and key2 is set to value2 on https://www.cypress-dx.com, cy.getAllLocalStorage() will yield:

{
'https://example.cypress.io': {
key1: 'value1',
},
'https://www.cypress-dx.com': {
key2: 'value2',
},
}

Examples​

Get all localStorage​

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

cy.getAllLocalStorage().then((result) => {
expect(result).to.deep.equal({
'https://example.cypress.io': {
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​