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()
.
Option | Default | Description |
---|---|---|
log | true | Displays 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.com
and key2
is
set to value2
on https://other.com
, cy.getAllSessionStorage()
will yield:
{
'https://example.com': {
key1: 'value1',
},
'https://other.com': {
key2: 'value2',
},
}
Examples
Get all sessionStorage
cy.visit('https://example.com', {
onBeforeLoad(win) {
win.sessionStorage.setItem('key', 'value')
},
})
cy.getAllSessionStorage().then((result) => {
expect(result).to.deep.equal({
'https://example.com': {
key: 'value',
},
})
})
Rules
Requirements
cy.getAllSessionStorage()
requires being chained off ofcy
.
Assertions
-
cy.getAllSessionStorage()
will only run assertions you have chained once, and will not retry .
Timeouts
cy.getAllSessionStorage()
cannot time out.