-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add docs for new local/session storage commands #4876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: clearAllLocalStorage | ||
--- | ||
|
||
Clear | ||
[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) | ||
data for all origins with which the test has interacted. | ||
|
||
<Alert type="warning"> | ||
|
||
Cypress automatically runs this command _before_ each test to prevent state from | ||
being shared across tests when | ||
[test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) | ||
is `on`. You shouldn't need to use this command unless you're using it to clear | ||
localStorage inside a single test or test isolation is `off`. | ||
|
||
</Alert> | ||
|
||
## Syntax | ||
|
||
```javascript | ||
cy.clearAllLocalStorage() | ||
cy.clearAllLocalStorage(options) | ||
``` | ||
|
||
### Usage | ||
|
||
**<Icon name="check-circle" color="green"></Icon> Correct Usage** | ||
|
||
```javascript | ||
cy.clearAllLocalStorage() | ||
``` | ||
|
||
### Arguments | ||
|
||
**<Icon name="angle-right"></Icon> options** **_(Object)_** | ||
|
||
Pass in an options object to change the default behavior of | ||
`cy.clearAllLocalStorage()`. | ||
|
||
| Option | Default | Description | | ||
| ------ | ------- | ---------------------------------------------------------------------------------------- | | ||
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) | | ||
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
- `cy.clearAllLocalStorage()` yields `null`. | ||
|
||
## Rules | ||
|
||
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) | ||
|
||
- `cy.clearAllLocalStorage()` requires being chained off of `cy`. | ||
|
||
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions) | ||
|
||
- `cy.clearAllLocalStorage()` cannot have any assertions chained. | ||
|
||
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts) | ||
|
||
<List><li>`cy.clearAllLocalStorage()` cannot time out.</li></List> | ||
|
||
## See also | ||
|
||
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage) | ||
- [`cy.clearCookies()`](/api/commands/clearcookies) | ||
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage) | ||
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage) | ||
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: clearAllSessionStorage | ||
--- | ||
|
||
Clear | ||
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) | ||
data for all origins with which the test has interacted. | ||
|
||
<Alert type="warning"> | ||
|
||
Cypress automatically runs this command _before_ each test to prevent state from | ||
being shared across tests when | ||
[test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) | ||
is `on`. You shouldn't need to use this command unless you're using it to clear | ||
localStorage inside a single test or test isolation is `off`. | ||
|
||
</Alert> | ||
|
||
## Syntax | ||
|
||
```javascript | ||
cy.clearAllSessionStorage() | ||
cy.clearAllSessionStorage(options) | ||
``` | ||
|
||
### Usage | ||
|
||
**<Icon name="check-circle" color="green"></Icon> Correct Usage** | ||
|
||
```javascript | ||
cy.clearAllSessionStorage() | ||
``` | ||
|
||
### Arguments | ||
|
||
**<Icon name="angle-right"></Icon> options** **_(Object)_** | ||
|
||
Pass in an options object to change the default behavior of | ||
`cy.clearAllSessionStorage()`. | ||
|
||
| Option | Default | Description | | ||
| ------ | ------- | ---------------------------------------------------------------------------------------- | | ||
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) | | ||
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
- `cy.clearAllSessionStorage()` yields `null`. | ||
|
||
## Rules | ||
|
||
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) | ||
|
||
- `cy.clearAllSessionStorage()` requires being chained off of `cy`. | ||
|
||
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions) | ||
|
||
`cy.clearAllSessionStorage()` cannot have any assertions chained. | ||
|
||
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts) | ||
|
||
<List><li>`cy.clearAllSessionStorage()` cannot time out.</li></List> | ||
|
||
## See also | ||
|
||
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage) | ||
- [`cy.clearCookies()`](/api/commands/clearcookies) | ||
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage) | ||
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage) | ||
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: getAllLocalStorage | ||
--- | ||
|
||
Get | ||
[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) | ||
data for all origins with which the test has interacted. | ||
|
||
## Syntax | ||
|
||
```javascript | ||
cy.getAllLocalStorage() | ||
cy.getAllLocalStorage(options) | ||
``` | ||
|
||
### Usage | ||
|
||
**<Icon name="check-circle" color="green"></Icon> Correct Usage** | ||
|
||
```javascript | ||
cy.getAllLocalStorage() | ||
``` | ||
|
||
### Arguments | ||
|
||
**<Icon name="angle-right"></Icon> options** **_(Object)_** | ||
|
||
Pass in an options object to change the default behavior of | ||
`cy.getAllLocalStorage()`. | ||
|
||
| Option | Default | Description | | ||
| ------ | ------- | ---------------------------------------------------------------------------------------- | | ||
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/cypress-app#Command-Log) | | ||
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
`cy.getAllLocalStorage()` yields an object where the keys are origins and the | ||
values are key-value pairs of `localStorage` data. | ||
|
||
For example, if `key1` is set to `value1` on `https://example.com` and `key2` is | ||
set to `value2` on `https://other.com`, `cy.getAllLocalStorage()` will yield: | ||
|
||
```js | ||
{ | ||
'https://example.com': { | ||
key1: 'value1', | ||
}, | ||
'https://other.com': { | ||
key2: 'value2', | ||
}, | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
### Get all localStorage | ||
|
||
```javascript | ||
cy.visit('https://example.com', { | ||
onBeforeLoad(win) { | ||
win.localStorage.setItem('key', 'value') | ||
}, | ||
}) | ||
|
||
cy.getAllLocalStorage().then((result) => { | ||
expect(result).to.deep.equal({ | ||
'https://example.com': { | ||
key: 'value', | ||
}, | ||
}) | ||
}) | ||
``` | ||
|
||
## Rules | ||
|
||
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) | ||
|
||
- `cy.getAllLocalStorage()` requires being chained off of `cy`. | ||
|
||
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions) | ||
|
||
<List><li>`cy.getAllLocalStorage()` will only run assertions you have chained | ||
once, and will not [retry](/guides/core-concepts/retry-ability).</li></List> | ||
|
||
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts) | ||
|
||
- `cy.getAllLocalStorage()` cannot time out. | ||
|
||
## See also | ||
|
||
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage) | ||
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage) | ||
- [`cy.clearCookies()`](/api/commands/clearcookies) | ||
- [`cy.clearLocalStorage()`](/api/commands/clearlocalstorage) | ||
- [`cy.getAllSessionStorage()`](/api/commands/getallsessionstorage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: getAllSessionStorage | ||
--- | ||
|
||
Get | ||
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) | ||
data for all origins with which the test has interacted. | ||
|
||
## Syntax | ||
|
||
```javascript | ||
cy.getAllSessionStorage() | ||
cy.getAllSessionStorage(options) | ||
``` | ||
|
||
### Usage | ||
|
||
**<Icon name="check-circle" color="green"></Icon> Correct Usage** | ||
|
||
```javascript | ||
cy.getAllSessionStorage() | ||
``` | ||
|
||
### Arguments | ||
|
||
**<Icon name="angle-right"></Icon> 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](/guides/core-concepts/cypress-app#Command-Log) | | ||
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
`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: | ||
|
||
```js | ||
{ | ||
'https://example.com': { | ||
key1: 'value1', | ||
}, | ||
'https://other.com': { | ||
key2: 'value2', | ||
}, | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
### Get all sessionStorage | ||
|
||
```javascript | ||
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 [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) | ||
|
||
- `cy.getAllSessionStorage()` requires being chained off of `cy`. | ||
|
||
### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions) | ||
|
||
<List><li>`cy.getAllSessionStorage()` will only run assertions you have chained | ||
once, and will not [retry](/guides/core-concepts/retry-ability).</li></List> | ||
|
||
### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts) | ||
|
||
- `cy.getAllSessionStorage()` cannot time out. | ||
|
||
## See also | ||
|
||
- [`cy.clearAllLocalStorage()`](/api/commands/clearalllocalstorage) | ||
- [`cy.clearAllSessionStorage()`](/api/commands/clearallsessionstorage) | ||
- [`cy.clearCookies()`](/api/commands/clearcookies) | ||
- [`cy.clearsessionStorage()`](/api/commands/clearsessionStorage) | ||
- [`cy.getAllLocalStorage()`](/api/commands/getalllocalstorage) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 837c4ad