Skip to content

Commit 94d1f2c

Browse files
chrisbreidingdebrisapron
authored andcommitted
Add docs for new local/session storage commands (#4876)
1 parent 2cae49b commit 94d1f2c

File tree

5 files changed

+345
-1
lines changed

5 files changed

+345
-1
lines changed

content/_data/sidebar.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
{
175175
"title": "Svelte API",
176176
"slug": "svelte/api"
177-
}
177+
}
178178
]
179179
},
180180
{
@@ -693,6 +693,14 @@
693693
"title": "blur",
694694
"slug": "blur"
695695
},
696+
{
697+
"title": "clearAllLocalStorage",
698+
"slug": "clearalllocalstorage"
699+
},
700+
{
701+
"title": "clearAllSessionStorage",
702+
"slug": "clearallsessionstorage"
703+
},
696704
{
697705
"title": "clearCookie",
698706
"slug": "clearcookie"
@@ -729,6 +737,14 @@
729737
"title": "focus",
730738
"slug": "focus"
731739
},
740+
{
741+
"title": "getAllLocalStorage",
742+
"slug": "getalllocalstorage"
743+
},
744+
{
745+
"title": "getAllSessionStorage",
746+
"slug": "getallsessionstorage"
747+
},
732748
{
733749
"title": "getCookie",
734750
"slug": "getcookie"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: clearAllLocalStorage
3+
---
4+
5+
Clear
6+
[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)
7+
data for all origins with which the test has interacted.
8+
9+
<Alert type="warning">
10+
11+
Cypress automatically runs this command _before_ each test to prevent state from
12+
being shared across tests when
13+
[test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
14+
is `on`. You shouldn't need to use this command unless you're using it to clear
15+
localStorage inside a single test or test isolation is `off`.
16+
17+
</Alert>
18+
19+
## Syntax
20+
21+
```javascript
22+
cy.clearAllLocalStorage()
23+
cy.clearAllLocalStorage(options)
24+
```
25+
26+
### Usage
27+
28+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
29+
30+
```javascript
31+
cy.clearAllLocalStorage()
32+
```
33+
34+
### Arguments
35+
36+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
37+
38+
Pass in an options object to change the default behavior of
39+
`cy.clearAllLocalStorage()`.
40+
41+
| Option | Default | Description |
42+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
43+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
44+
45+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
46+
47+
- `cy.clearAllLocalStorage()` yields `null`.
48+
49+
## Rules
50+
51+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
52+
53+
- `cy.clearAllLocalStorage()` requires being chained off of `cy`.
54+
55+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
56+
57+
- `cy.clearAllLocalStorage()` cannot have any assertions chained.
58+
59+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
60+
61+
<List><li>`cy.clearAllLocalStorage()` cannot time out.</li></List>
62+
63+
## See also
64+
65+
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage)
66+
- [`cy.clearCookies()`](/api/commands/clearcookies)
67+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
68+
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage)
69+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: clearAllSessionStorage
3+
---
4+
5+
Clear
6+
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
7+
data for all origins with which the test has interacted.
8+
9+
<Alert type="warning">
10+
11+
Cypress automatically runs this command _before_ each test to prevent state from
12+
being shared across tests when
13+
[test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
14+
is `on`. You shouldn't need to use this command unless you're using it to clear
15+
localStorage inside a single test or test isolation is `off`.
16+
17+
</Alert>
18+
19+
## Syntax
20+
21+
```javascript
22+
cy.clearAllSessionStorage()
23+
cy.clearAllSessionStorage(options)
24+
```
25+
26+
### Usage
27+
28+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
29+
30+
```javascript
31+
cy.clearAllSessionStorage()
32+
```
33+
34+
### Arguments
35+
36+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
37+
38+
Pass in an options object to change the default behavior of
39+
`cy.clearAllSessionStorage()`.
40+
41+
| Option | Default | Description |
42+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
43+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
44+
45+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
46+
47+
- `cy.clearAllSessionStorage()` yields `null`.
48+
49+
## Rules
50+
51+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
52+
53+
- `cy.clearAllSessionStorage()` requires being chained off of `cy`.
54+
55+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
56+
57+
`cy.clearAllSessionStorage()` cannot have any assertions chained.
58+
59+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
60+
61+
<List><li>`cy.clearAllSessionStorage()` cannot time out.</li></List>
62+
63+
## See also
64+
65+
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage)
66+
- [`cy.clearCookies()`](/api/commands/clearcookies)
67+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
68+
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage)
69+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: getAllLocalStorage
3+
---
4+
5+
Get
6+
[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)
7+
data for all origins with which the test has interacted.
8+
9+
## Syntax
10+
11+
```javascript
12+
cy.getAllLocalStorage()
13+
cy.getAllLocalStorage(options)
14+
```
15+
16+
### Usage
17+
18+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
19+
20+
```javascript
21+
cy.getAllLocalStorage()
22+
```
23+
24+
### Arguments
25+
26+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
27+
28+
Pass in an options object to change the default behavior of
29+
`cy.getAllLocalStorage()`.
30+
31+
| Option | Default | Description |
32+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
33+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
34+
35+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
36+
37+
`cy.getAllLocalStorage()` yields an object where the keys are origins and the
38+
values are key-value pairs of `localStorage` data.
39+
40+
For example, if `key1` is set to `value1` on `https://example.com` and `key2` is
41+
set to `value2` on `https://other.com`, `cy.getAllLocalStorage()` will yield:
42+
43+
```js
44+
{
45+
'https://example.com': {
46+
key1: 'value1',
47+
},
48+
'https://other.com': {
49+
key2: 'value2',
50+
},
51+
}
52+
```
53+
54+
## Examples
55+
56+
### Get all localStorage
57+
58+
```javascript
59+
cy.visit('https://example.com', {
60+
onBeforeLoad(win) {
61+
win.localStorage.setItem('key', 'value')
62+
},
63+
})
64+
65+
cy.getAllLocalStorage().then((result) => {
66+
expect(result).to.deep.equal({
67+
'https://example.com': {
68+
key: 'value',
69+
},
70+
})
71+
})
72+
```
73+
74+
## Rules
75+
76+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
77+
78+
- `cy.getAllLocalStorage()` requires being chained off of `cy`.
79+
80+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
81+
82+
<List><li>`cy.getAllLocalStorage()` will only run assertions you have chained
83+
once, and will not [retry](/guides/core-concepts/retry-ability).</li></List>
84+
85+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
86+
87+
- `cy.getAllLocalStorage()` cannot time out.
88+
89+
## See also
90+
91+
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage)
92+
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage)
93+
- [`cy.clearCookies()`](/api/commands/clearcookies)
94+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
95+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: getAllSessionStorage
3+
---
4+
5+
Get
6+
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
7+
data for all origins with which the test has interacted.
8+
9+
## Syntax
10+
11+
```javascript
12+
cy.getAllSessionStorage()
13+
cy.getAllSessionStorage(options)
14+
```
15+
16+
### Usage
17+
18+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
19+
20+
```javascript
21+
cy.getAllSessionStorage()
22+
```
23+
24+
### Arguments
25+
26+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
27+
28+
Pass in an options object to change the default behavior of
29+
`cy.getAllSessionStorage()`.
30+
31+
| Option | Default | Description |
32+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
33+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
34+
35+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
36+
37+
`cy.getAllSessionStorage()` yields an object where the keys are origins and the
38+
values are key-value pairs of `sessionStorage` data.
39+
40+
For example, if `key1` is set to `value1` on `https://example.com` and `key2` is
41+
set to `value2` on `https://other.com`, `cy.getAllSessionStorage()` will yield:
42+
43+
```js
44+
{
45+
'https://example.com': {
46+
key1: 'value1',
47+
},
48+
'https://other.com': {
49+
key2: 'value2',
50+
},
51+
}
52+
```
53+
54+
## Examples
55+
56+
### Get all sessionStorage
57+
58+
```javascript
59+
cy.visit('https://example.com', {
60+
onBeforeLoad(win) {
61+
win.sessionStorage.setItem('key', 'value')
62+
},
63+
})
64+
65+
cy.getAllSessionStorage().then((result) => {
66+
expect(result).to.deep.equal({
67+
'https://example.com': {
68+
key: 'value',
69+
},
70+
})
71+
})
72+
```
73+
74+
## Rules
75+
76+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
77+
78+
- `cy.getAllSessionStorage()` requires being chained off of `cy`.
79+
80+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
81+
82+
<List><li>`cy.getAllSessionStorage()` will only run assertions you have chained
83+
once, and will not [retry](/guides/core-concepts/retry-ability).</li></List>
84+
85+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
86+
87+
- `cy.getAllSessionStorage()` cannot time out.
88+
89+
## See also
90+
91+
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage)
92+
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage)
93+
- [`cy.clearCookies()`](/api/commands/clearcookies)
94+
- [`cy.clearsessionStorage()`](/api/commands/clearsessionStorage)
95+
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage)

0 commit comments

Comments
 (0)