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 |
timeout | defaultCommandTimeout | Time to wait for cy.getAllSessionStorage() to resolve before timing out |
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',
},
}
cy.getAllSessionStorage() is a query, and it is safe to chain further
commands. It will automatically retry until
all chained assertions have passed, or until it times out, re-reading
sessionStorage from all origins on each retry so the yielded object stays up to
date.
Because cy.getAllSessionStorage() is a query, it re-reads sessionStorage on
every retry, and assertions you chain with .should()
drive those retries until they pass or the command times out. A
.then() callback, by contrast, runs only once after the
command settles and is not retried — so prefer chaining
.should() assertions over asserting inside .then()
when you need Cypress to wait for storage to be populated.
When no sessionStorage data is present:​
On each read, cy.getAllSessionStorage() yields the current object of origins to
sessionStorage data, or an empty object if none exists yet. The yielded object
is the subject your chained assertions run against. If an assertion fails, because
the object is empty, or because its contents don't match yet, the query re-reads
sessionStorage and re-runs the assertion, looping until it passes or the command
times out.
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 ofcy.
Assertions ​
cy.getAllSessionStorage()will automatically retry until all chained assertions have passed.
Timeouts ​
cy.getAllSessionStorage()can time out waiting for assertions you've added to pass.
History​
| Version | Changes |
|---|---|
| 16.0.0 | cy.getAllSessionStorage() is now a query and retries assertions until they pass or time out. |