From 485fc33c6625f24c5a44cd5f035790c2dbad26bf Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Tue, 29 Nov 2022 10:37:46 -0500 Subject: [PATCH 1/4] add docs for new local/session storage commands --- content/_data/sidebar.json | 42 ++++++++- content/api/commands/clearalllocalstorage.md | 74 +++++++++++++++ .../api/commands/clearallsessionstorage.md | 74 +++++++++++++++ content/api/commands/getalllocalstorage.md | 93 +++++++++++++++++++ content/api/commands/getallsessionstorage.md | 93 +++++++++++++++++++ 5 files changed, 375 insertions(+), 1 deletion(-) create mode 100644 content/api/commands/clearalllocalstorage.md create mode 100644 content/api/commands/clearallsessionstorage.md create mode 100644 content/api/commands/getalllocalstorage.md create mode 100644 content/api/commands/getallsessionstorage.md diff --git a/content/_data/sidebar.json b/content/_data/sidebar.json index 1293df44a4..59c25a1153 100644 --- a/content/_data/sidebar.json +++ b/content/_data/sidebar.json @@ -174,7 +174,7 @@ { "title": "Svelte API", "slug": "svelte/api" - } + } ] }, { @@ -505,6 +505,26 @@ "title": "clear", "slug": "clear" }, + { + "title": "clearCookie", + "slug": "clearcookie" + }, + { + "title": "clearCookies", + "slug": "clearcookies" + }, + { + "title": "clearAllLocalStorage", + "slug": "clearalllocalstorage" + }, + { + "title": "clearAllSessionStorage", + "slug": "clearallsessionstorage" + }, + { + "title": "clearLocalStorage", + "slug": "clearlocalstorage" + }, { "title": "click", "slug": "click" @@ -599,6 +619,26 @@ "title": "get", "slug": "get" }, + { + "title": "getAllLocalStorage", + "slug": "getalllocalstorage" + }, + { + "title": "getAllSessionStorage", + "slug": "getallsessionstorage" + }, + { + "title": "getCookie", + "slug": "getcookie" + }, + { + "title": "getCookies", + "slug": "getcookies" + }, + { + "title": "go", + "slug": "go" + }, { "title": "hash", "slug": "hash" diff --git a/content/api/commands/clearalllocalstorage.md b/content/api/commands/clearalllocalstorage.md new file mode 100644 index 0000000000..749d6d9ef2 --- /dev/null +++ b/content/api/commands/clearalllocalstorage.md @@ -0,0 +1,74 @@ +--- +title: clearAllLocalStorage +--- + +Clear localStorage data for all origins with which the test has interacted. + + + +Cypress automatically runs this command _before_ each test to prevent state from +being shared across tests. You shouldn't need to use this command unless you're +using it to clear localStorage inside a single test. + + + +## Syntax + +```javascript +cy.clearAllLocalStorage() +cy.clearAllLocalStorage(options) +``` + +### Usage + +** Correct Usage** + +```javascript +cy.clearAllLocalStorage() +``` + +### Arguments + +** 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 [](/guides/core-concepts/introduction-to-cypress#Subject-Management) + +- `cy.clearAllLocalStorage()` yields `null`. +- `cy.clearAllLocalStorage()` cannot be chained further. + +## Examples + +### Clear all localStorage + +```javascript +cy.clearAllLocalStorage() +``` + +## Rules + +### Requirements [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) + +- `cy.clearAllLocalStorage()` requires being chained off of `cy`. + +### Assertions [](/guides/core-concepts/introduction-to-cypress#Assertions) + +- `cy.clearAllLocalStorage()` cannot have any assertions chained. + +### Timeouts [](/guides/core-concepts/introduction-to-cypress#Timeouts) + +
  • `cy.clearAllLocalStorage()` cannot time out.
  • + +## 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) diff --git a/content/api/commands/clearallsessionstorage.md b/content/api/commands/clearallsessionstorage.md new file mode 100644 index 0000000000..38ee46cdd2 --- /dev/null +++ b/content/api/commands/clearallsessionstorage.md @@ -0,0 +1,74 @@ +--- +title: clearAllSessionStorage +--- + +Clear data in sessionStorage for all origins with which the test has interacted. + + + +Cypress automatically runs this command _before_ each test to prevent state from +being shared across tests. You shouldn't need to use this command unless you're +using it to clear sessionStorage inside a single test. + + + +## Syntax + +```javascript +cy.clearAllSessionStorage() +cy.clearAllSessionStorage(options) +``` + +### Usage + +** Correct Usage** + +```javascript +cy.clearAllSessionStorage() +``` + +### Arguments + +** 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 [](/guides/core-concepts/introduction-to-cypress#Subject-Management) + +- `cy.clearAllSessionStorage()` yields `null`. +- `cy.clearAllSessionStorage()` cannot be chained further. + +## Examples + +### Clear all sessionStorage + +```javascript +cy.clearAllSessionStorage() +``` + +## Rules + +### Requirements [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) + +- `cy.clearAllSessionStorage()` requires being chained off of `cy`. + +### Assertions [](/guides/core-concepts/introduction-to-cypress#Assertions) + +`cy.clearAllSessionStorage()` cannot have any assertions chained. + +### Timeouts [](/guides/core-concepts/introduction-to-cypress#Timeouts) + +
  • `cy.clearAllSessionStorage()` cannot time out.
  • + +## 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) diff --git a/content/api/commands/getalllocalstorage.md b/content/api/commands/getalllocalstorage.md new file mode 100644 index 0000000000..932fab8340 --- /dev/null +++ b/content/api/commands/getalllocalstorage.md @@ -0,0 +1,93 @@ +--- +title: getAllLocalStorage +--- + +Get data in localStorage for all origins with which the test has interacted. + +## Syntax + +```javascript +cy.getAllLocalStorage() +cy.getAllLocalStorage(options) +``` + +### Usage + +** Correct Usage** + +```javascript +cy.getAllLocalStorage() +``` + +### Arguments + +** 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 [](/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 [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) + +- `cy.getAllLocalStorage()` requires being chained off of `cy`. + +### Assertions [](/guides/core-concepts/introduction-to-cypress#Assertions) + +
  • `cy.getAllLocalStorage()` will only run assertions you have chained +once, and will not [retry](/guides/core-concepts/retry-ability).
  • + +### Timeouts [](/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) diff --git a/content/api/commands/getallsessionstorage.md b/content/api/commands/getallsessionstorage.md new file mode 100644 index 0000000000..e694bc7a62 --- /dev/null +++ b/content/api/commands/getallsessionstorage.md @@ -0,0 +1,93 @@ +--- +title: getAllSessionStorage +--- + +Get data in sessionStorage for all origins with which the test has interacted. + +## Syntax + +```javascript +cy.getAllSessionStorage() +cy.getAllSessionStorage(options) +``` + +### Usage + +** Correct Usage** + +```javascript +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](/guides/core-concepts/cypress-app#Command-Log) | + +### Yields [](/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 [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) + +- `cy.getAllSessionStorage()` requires being chained off of `cy`. + +### Assertions [](/guides/core-concepts/introduction-to-cypress#Assertions) + +
  • `cy.getAllSessionStorage()` will only run assertions you have chained +once, and will not [retry](/guides/core-concepts/retry-ability).
  • + +### Timeouts [](/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) From 837c4adb1cda54db250ac66863ef4b7000a51e2d Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Tue, 29 Nov 2022 11:54:03 -0500 Subject: [PATCH 2/4] apply feedback suggestions --- content/api/commands/clearalllocalstorage.md | 18 +++++++----------- content/api/commands/clearallsessionstorage.md | 18 +++++++----------- content/api/commands/getalllocalstorage.md | 6 ++++-- content/api/commands/getallsessionstorage.md | 6 ++++-- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/content/api/commands/clearalllocalstorage.md b/content/api/commands/clearalllocalstorage.md index 749d6d9ef2..849606cf63 100644 --- a/content/api/commands/clearalllocalstorage.md +++ b/content/api/commands/clearalllocalstorage.md @@ -2,13 +2,17 @@ title: clearAllLocalStorage --- -Clear localStorage data for all origins with which the test has interacted. +Clear +[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) +data for all origins with which the test has interacted. Cypress automatically runs this command _before_ each test to prevent state from -being shared across tests. You shouldn't need to use this command unless you're -using it to clear localStorage inside a single test. +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`. @@ -43,14 +47,6 @@ Pass in an options object to change the default behavior of - `cy.clearAllLocalStorage()` yields `null`. - `cy.clearAllLocalStorage()` cannot be chained further. -## Examples - -### Clear all localStorage - -```javascript -cy.clearAllLocalStorage() -``` - ## Rules ### Requirements [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) diff --git a/content/api/commands/clearallsessionstorage.md b/content/api/commands/clearallsessionstorage.md index 38ee46cdd2..6705867d09 100644 --- a/content/api/commands/clearallsessionstorage.md +++ b/content/api/commands/clearallsessionstorage.md @@ -2,13 +2,17 @@ title: clearAllSessionStorage --- -Clear data in sessionStorage for all origins with which the test has interacted. +Clear +[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) +data for all origins with which the test has interacted. Cypress automatically runs this command _before_ each test to prevent state from -being shared across tests. You shouldn't need to use this command unless you're -using it to clear sessionStorage inside a single test. +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`. @@ -43,14 +47,6 @@ Pass in an options object to change the default behavior of - `cy.clearAllSessionStorage()` yields `null`. - `cy.clearAllSessionStorage()` cannot be chained further. -## Examples - -### Clear all sessionStorage - -```javascript -cy.clearAllSessionStorage() -``` - ## Rules ### Requirements [](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) diff --git a/content/api/commands/getalllocalstorage.md b/content/api/commands/getalllocalstorage.md index 932fab8340..57d3a31e40 100644 --- a/content/api/commands/getalllocalstorage.md +++ b/content/api/commands/getalllocalstorage.md @@ -2,7 +2,9 @@ title: getAllLocalStorage --- -Get data in localStorage for all origins with which the test has interacted. +Get +[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) +data for all origins with which the test has interacted. ## Syntax @@ -33,7 +35,7 @@ Pass in an options object to change the default behavior of ### Yields [](/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. +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: diff --git a/content/api/commands/getallsessionstorage.md b/content/api/commands/getallsessionstorage.md index e694bc7a62..568d4825df 100644 --- a/content/api/commands/getallsessionstorage.md +++ b/content/api/commands/getallsessionstorage.md @@ -2,7 +2,9 @@ title: getAllSessionStorage --- -Get data in sessionStorage for all origins with which the test has interacted. +Get +[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) +data for all origins with which the test has interacted. ## Syntax @@ -33,7 +35,7 @@ Pass in an options object to change the default behavior of ### Yields [](/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. +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: From 03ccc1bf54693b1c68d7f29d03e605554953a42d Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Tue, 29 Nov 2022 11:58:07 -0500 Subject: [PATCH 3/4] remove cannot be chained further lines --- content/api/commands/clearalllocalstorage.md | 1 - content/api/commands/clearallsessionstorage.md | 1 - 2 files changed, 2 deletions(-) diff --git a/content/api/commands/clearalllocalstorage.md b/content/api/commands/clearalllocalstorage.md index 849606cf63..3f6d4c5155 100644 --- a/content/api/commands/clearalllocalstorage.md +++ b/content/api/commands/clearalllocalstorage.md @@ -45,7 +45,6 @@ Pass in an options object to change the default behavior of ### Yields [](/guides/core-concepts/introduction-to-cypress#Subject-Management) - `cy.clearAllLocalStorage()` yields `null`. -- `cy.clearAllLocalStorage()` cannot be chained further. ## Rules diff --git a/content/api/commands/clearallsessionstorage.md b/content/api/commands/clearallsessionstorage.md index 6705867d09..e63f0bd86a 100644 --- a/content/api/commands/clearallsessionstorage.md +++ b/content/api/commands/clearallsessionstorage.md @@ -45,7 +45,6 @@ Pass in an options object to change the default behavior of ### Yields [](/guides/core-concepts/introduction-to-cypress#Subject-Management) - `cy.clearAllSessionStorage()` yields `null`. -- `cy.clearAllSessionStorage()` cannot be chained further. ## Rules From 76d952ab5bf9be4880c18bc547df8d552e136192 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Tue, 29 Nov 2022 13:43:41 -0500 Subject: [PATCH 4/4] fix sidebar --- content/_data/sidebar.json | 56 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/content/_data/sidebar.json b/content/_data/sidebar.json index 59c25a1153..1f7025b510 100644 --- a/content/_data/sidebar.json +++ b/content/_data/sidebar.json @@ -505,26 +505,6 @@ "title": "clear", "slug": "clear" }, - { - "title": "clearCookie", - "slug": "clearcookie" - }, - { - "title": "clearCookies", - "slug": "clearcookies" - }, - { - "title": "clearAllLocalStorage", - "slug": "clearalllocalstorage" - }, - { - "title": "clearAllSessionStorage", - "slug": "clearallsessionstorage" - }, - { - "title": "clearLocalStorage", - "slug": "clearlocalstorage" - }, { "title": "click", "slug": "click" @@ -619,26 +599,6 @@ "title": "get", "slug": "get" }, - { - "title": "getAllLocalStorage", - "slug": "getalllocalstorage" - }, - { - "title": "getAllSessionStorage", - "slug": "getallsessionstorage" - }, - { - "title": "getCookie", - "slug": "getcookie" - }, - { - "title": "getCookies", - "slug": "getcookies" - }, - { - "title": "go", - "slug": "go" - }, { "title": "hash", "slug": "hash" @@ -733,6 +693,14 @@ "title": "blur", "slug": "blur" }, + { + "title": "clearAllLocalStorage", + "slug": "clearalllocalstorage" + }, + { + "title": "clearAllSessionStorage", + "slug": "clearallsessionstorage" + }, { "title": "clearCookie", "slug": "clearcookie" @@ -769,6 +737,14 @@ "title": "focus", "slug": "focus" }, + { + "title": "getAllLocalStorage", + "slug": "getalllocalstorage" + }, + { + "title": "getAllSessionStorage", + "slug": "getallsessionstorage" + }, { "title": "getCookie", "slug": "getcookie"