Skip to main content

getAllSessionStorage

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

Syntax​

cy.getAllSessionStorage()
cy.getAllSessionStorage(options)

Usage​

Correct Usage

cy.getAllSessionStorage()

Arguments​

options (Object)

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

OptionDefaultDescription
logtrueDisplays the command in the Command log

Yields ​

cy.getAllSessionStorage() yields an object where the keys are origins and the values are key-value pairs of sessionStorage 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.getAllSessionStorage() will yield:

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

Examples​

Get all sessionStorage​

cy.visit('/users', {
onBeforeLoad(win) {
win.sessionStorage.setItem('key', 'value')
},
})

cy.getAllSessionStorage().then((result) => {
expect(result).to.deep.equal({
'http://localhost:8080': {
key: 'value',
},
})
})

Rules​

Requirements ​

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

Assertions ​

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

Timeouts ​

  • cy.getAllSessionStorage() cannot time out.

See also​