Skip to content

Commit 485fc33

Browse files
committed
add docs for new local/session storage commands
1 parent 5501639 commit 485fc33

File tree

5 files changed

+375
-1
lines changed

5 files changed

+375
-1
lines changed

content/_data/sidebar.json

Lines changed: 41 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
{
@@ -505,6 +505,26 @@
505505
"title": "clear",
506506
"slug": "clear"
507507
},
508+
{
509+
"title": "clearCookie",
510+
"slug": "clearcookie"
511+
},
512+
{
513+
"title": "clearCookies",
514+
"slug": "clearcookies"
515+
},
516+
{
517+
"title": "clearAllLocalStorage",
518+
"slug": "clearalllocalstorage"
519+
},
520+
{
521+
"title": "clearAllSessionStorage",
522+
"slug": "clearallsessionstorage"
523+
},
524+
{
525+
"title": "clearLocalStorage",
526+
"slug": "clearlocalstorage"
527+
},
508528
{
509529
"title": "click",
510530
"slug": "click"
@@ -599,6 +619,26 @@
599619
"title": "get",
600620
"slug": "get"
601621
},
622+
{
623+
"title": "getAllLocalStorage",
624+
"slug": "getalllocalstorage"
625+
},
626+
{
627+
"title": "getAllSessionStorage",
628+
"slug": "getallsessionstorage"
629+
},
630+
{
631+
"title": "getCookie",
632+
"slug": "getcookie"
633+
},
634+
{
635+
"title": "getCookies",
636+
"slug": "getcookies"
637+
},
638+
{
639+
"title": "go",
640+
"slug": "go"
641+
},
602642
{
603643
"title": "hash",
604644
"slug": "hash"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: clearAllLocalStorage
3+
---
4+
5+
Clear localStorage data for all origins with which the test has interacted.
6+
7+
<Alert type="warning">
8+
9+
Cypress automatically runs this command _before_ each test to prevent state from
10+
being shared across tests. You shouldn't need to use this command unless you're
11+
using it to clear localStorage inside a single test.
12+
13+
</Alert>
14+
15+
## Syntax
16+
17+
```javascript
18+
cy.clearAllLocalStorage()
19+
cy.clearAllLocalStorage(options)
20+
```
21+
22+
### Usage
23+
24+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
25+
26+
```javascript
27+
cy.clearAllLocalStorage()
28+
```
29+
30+
### Arguments
31+
32+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
33+
34+
Pass in an options object to change the default behavior of
35+
`cy.clearAllLocalStorage()`.
36+
37+
| Option | Default | Description |
38+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
39+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
40+
41+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
42+
43+
- `cy.clearAllLocalStorage()` yields `null`.
44+
- `cy.clearAllLocalStorage()` cannot be chained further.
45+
46+
## Examples
47+
48+
### Clear all localStorage
49+
50+
```javascript
51+
cy.clearAllLocalStorage()
52+
```
53+
54+
## Rules
55+
56+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
57+
58+
- `cy.clearAllLocalStorage()` requires being chained off of `cy`.
59+
60+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
61+
62+
- `cy.clearAllLocalStorage()` cannot have any assertions chained.
63+
64+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
65+
66+
<List><li>`cy.clearAllLocalStorage()` cannot time out.</li></List>
67+
68+
## See also
69+
70+
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage)
71+
- [`cy.clearCookies()`](/api/commands/clearcookies)
72+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
73+
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage)
74+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: clearAllSessionStorage
3+
---
4+
5+
Clear data in sessionStorage for all origins with which the test has interacted.
6+
7+
<Alert type="warning">
8+
9+
Cypress automatically runs this command _before_ each test to prevent state from
10+
being shared across tests. You shouldn't need to use this command unless you're
11+
using it to clear sessionStorage inside a single test.
12+
13+
</Alert>
14+
15+
## Syntax
16+
17+
```javascript
18+
cy.clearAllSessionStorage()
19+
cy.clearAllSessionStorage(options)
20+
```
21+
22+
### Usage
23+
24+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
25+
26+
```javascript
27+
cy.clearAllSessionStorage()
28+
```
29+
30+
### Arguments
31+
32+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
33+
34+
Pass in an options object to change the default behavior of
35+
`cy.clearAllSessionStorage()`.
36+
37+
| Option | Default | Description |
38+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
39+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
40+
41+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
42+
43+
- `cy.clearAllSessionStorage()` yields `null`.
44+
- `cy.clearAllSessionStorage()` cannot be chained further.
45+
46+
## Examples
47+
48+
### Clear all sessionStorage
49+
50+
```javascript
51+
cy.clearAllSessionStorage()
52+
```
53+
54+
## Rules
55+
56+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
57+
58+
- `cy.clearAllSessionStorage()` requires being chained off of `cy`.
59+
60+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
61+
62+
`cy.clearAllSessionStorage()` cannot have any assertions chained.
63+
64+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
65+
66+
<List><li>`cy.clearAllSessionStorage()` cannot time out.</li></List>
67+
68+
## See also
69+
70+
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage)
71+
- [`cy.clearCookies()`](/api/commands/clearcookies)
72+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
73+
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage)
74+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: getAllLocalStorage
3+
---
4+
5+
Get data in localStorage for all origins with which the test has interacted.
6+
7+
## Syntax
8+
9+
```javascript
10+
cy.getAllLocalStorage()
11+
cy.getAllLocalStorage(options)
12+
```
13+
14+
### Usage
15+
16+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
17+
18+
```javascript
19+
cy.getAllLocalStorage()
20+
```
21+
22+
### Arguments
23+
24+
**<Icon name="angle-right"></Icon> options** **_(Object)_**
25+
26+
Pass in an options object to change the default behavior of
27+
`cy.getAllLocalStorage()`.
28+
29+
| Option | Default | Description |
30+
| ------ | ------- | ---------------------------------------------------------------------------------------- |
31+
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) |
32+
33+
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)
34+
35+
`cy.getAllLocalStorage()` yields an object where the keys are origins and the
36+
values are key-value pairs of localStorage data.
37+
38+
For example, if `key1` is set to `value1` on `https://example.com` and `key2` is
39+
set to `value2` on `https://other.com`, `cy.getAllLocalStorage()` will yield:
40+
41+
```js
42+
{
43+
'https://example.com': {
44+
key1: 'value1',
45+
},
46+
'https://other.com': {
47+
key2: 'value2',
48+
},
49+
}
50+
```
51+
52+
## Examples
53+
54+
### Get all localStorage
55+
56+
```javascript
57+
cy.visit('https://example.com', {
58+
onBeforeLoad(win) {
59+
win.localStorage.setItem('key', 'value')
60+
},
61+
})
62+
63+
cy.getAllLocalStorage().then((result) => {
64+
expect(result).to.deep.equal({
65+
'https://example.com': {
66+
key: 'value',
67+
},
68+
})
69+
})
70+
```
71+
72+
## Rules
73+
74+
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)
75+
76+
- `cy.getAllLocalStorage()` requires being chained off of `cy`.
77+
78+
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)
79+
80+
<List><li>`cy.getAllLocalStorage()` will only run assertions you have chained
81+
once, and will not [retry](/guides/core-concepts/retry-ability).</li></List>
82+
83+
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)
84+
85+
- `cy.getAllLocalStorage()` cannot time out.
86+
87+
## See also
88+
89+
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage)
90+
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage)
91+
- [`cy.clearCookies()`](/api/commands/clearcookies)
92+
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage)
93+
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage)

0 commit comments

Comments
 (0)