Skip to content
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

feat: Add new local and session storage commands #579

Merged
merged 4 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,15 @@ $(() => {
populateStorage(e)
})

// populate local storage to demonstrate cy.clearLocalStorage()
// populate localStorage and sessionStorage to demonstrate cy.clearLocalStorage()
function populateStorage () {
localStorage.setItem('prop1', 'red')
localStorage.setItem('prop2', 'blue')
localStorage.setItem('prop3', 'magenta')

sessionStorage.setItem('prop4', 'cyan')
sessionStorage.setItem('prop5', 'yellow')
sessionStorage.setItem('prop6', 'black')
}

// setting a cookie
Expand Down
2 changes: 1 addition & 1 deletion app/commands/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/aliasing.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/assertions.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<a href="/commands/network-requests">Network Requests</a>
</li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li>
<a href="/commands/spies-stubs-clocks"
Expand Down
2 changes: 1 addition & 1 deletion app/commands/connectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li class="active"><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li class="active"><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/location.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/network-requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li class="active"><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/querying.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<a href="/commands/network-requests">Network Requests</a>
</li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li>
<a href="/commands/spies-stubs-clocks"
Expand Down
2 changes: 1 addition & 1 deletion app/commands/spies-stubs-clocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/fixtures">Fixtures</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li class="active"><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
114 changes: 106 additions & 8 deletions app/commands/local-storage.html → app/commands/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li class="active"><a href="/commands/local-storage">Local Storage</a></li>
<li class="active"><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand All @@ -62,8 +62,8 @@

<div class="banner">
<div class="container">
<h1>Local Storage</h1>
<p>Examples of managing local storage in Cypress, for a full reference of commands, go to <a href="https://on.cypress.io/api" target="_blank">docs.cypress.io</a>
<h1>Storage</h1>
<p>Examples of managing localStorage and sessionStorage in Cypress, for a full reference of commands, go to <a href="https://on.cypress.io/api" target="_blank">docs.cypress.io</a>
</p>
</div>
</div>
Expand All @@ -72,8 +72,8 @@ <h1>Local Storage</h1>
<div class="row">

<div class="col-xs-7">
<h4 id="clearLocalStorage"><a href="https://on.cypress.io/clearlocalstorage">cy.clearLocalStorage()</a></h4>
<p>To clear all data in local storage, use the <a href="https://on.cypress.io/clearlocalstorage"><code>cy.clearLocalStorage()</code></a> command.</p>
<h4><a href="https://on.cypress.io/clearlocalstorage">cy.clearLocalStorage()</a></h4>
<p>To clear all data in localStorage for the current origin, use the <a href="https://on.cypress.io/clearlocalstorage"><code>cy.clearLocalStorage()</code></a> command.</p>
<pre><code class="javascript">cy.get('.ls-btn').click().should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
Expand All @@ -87,7 +87,7 @@ <h4 id="clearLocalStorage"><a href="https://on.cypress.io/clearlocalstorage">cy.
expect(ls.getItem('prop3')).to.be.null
})

// Clear key matching string in Local Storage
// Clear key matching string in localStorage
cy.get('.ls-btn').click().should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
Expand All @@ -100,7 +100,7 @@ <h4 id="clearLocalStorage"><a href="https://on.cypress.io/clearlocalstorage">cy.
expect(ls.getItem('prop3')).to.eq('magenta')
})

// Clear keys matching regex in Local Storage
// Clear keys matching regex in localStorage
cy.get('.ls-btn').click().should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
Expand All @@ -115,13 +115,111 @@ <h4 id="clearLocalStorage"><a href="https://on.cypress.io/clearlocalstorage">cy.
</div>
<div class="col-xs-5">
<div class="well">
<button class="ls-btn btn btn-success">Populate Local Storage</button>
<button class="ls-btn btn btn-success">Populate localStorage and sessionStorage</button>
</div>
</div>

<div class="col-xs-12"><hr></div>
</div>
</div>

<div id="getalllocalstorage">
<div class="row">

<div class="col-xs-7">
<h4><a href="https://on.cypress.io/getalllocalstorage">cy.getAllLocalStorage()</a></h4>
<p>To get all data in localStorage for all origins, use the <a href="https://on.cypress.io/getalllocalstorage"><code>cy.getAllLocalStorage()</code></a> command.</p>
<pre><code class="javascript">cy.get('.ls-btn').click()

// getAllLocalStorage() yields a map of origins to localStorage values
cy.getAllLocalStorage().should((storageMap) => {
expect(storageMap).to.deep.equal({
// other origins will also be present if localStorage is set on them
'http://localhost:8080': {
'prop1': 'red',
'prop2': 'blue',
'prop3': 'magenta',
},
})
})</code></pre>
</div>
<div class="col-xs-5">
</div>

<div class="col-xs-12"><hr></div>
</div>
</div>

<div id="clearalllocalstorage">
<div class="row">

<div class="col-xs-7">
<h4><a href="https://on.cypress.io/clearalllocalstorage">cy.clearAllLocalStorage()</a></h4>
<p>To clear all data in localStorage for all origins, use the <a href="https://on.cypress.io/clearalllocalstorage"><code>cy.clearAllLocalStorage()</code></a> command.</p>
<pre><code class="javascript">cy.get('.ls-btn').click()

// clearAllLocalStorage() yields null
cy.clearAllLocalStorage().should(() => {
expect(sessionStorage.getItem('prop1')).to.be.null
expect(sessionStorage.getItem('prop2')).to.be.null
expect(sessionStorage.getItem('prop3')).to.be.null
})</code></pre>
</div>
<div class="col-xs-5">
</div>

<div class="col-xs-12"><hr></div>
</div>
</div>

<div id="getallsessionstorage">
<div class="row">

<div class="col-xs-7">
<h4><a href="https://on.cypress.io/getallsessionstorage">cy.getAllSessionStorage()</a></h4>
<p>To get all data in sessionStorage for all origins, use the <a href="https://on.cypress.io/getallsessionstorage"><code>cy.getAllSessionStorage()</code></a> command.</p>
<pre><code class="javascript">cy.get('.ls-btn').click()

// getAllSessionStorage() yields a map of origins to sessionStorage values
cy.getAllSessionStorage().should((storageMap) => {
expect(storageMap).to.deep.equal({
// other origins will also be present if sessionStorage is set on them
'http://localhost:8080': {
'prop4': 'cyan',
'prop5': 'yellow',
'prop6': 'black',
},
})
})</code></pre>
</div>
<div class="col-xs-5">
</div>

<div class="col-xs-12"><hr></div>
</div>
</div>

<div id="clearallsessionstorage">
<div class="row">

<div class="col-xs-7">
<h4><a href="https://on.cypress.io/clearallsessionstorage">cy.clearAllSessionStorage()</a></h4>
<p>To clear all data in sessionStorage for all origins, use the <a href="https://on.cypress.io/clearallsessionstorage"><code>cy.clearAllSessionStorage()</code></a> command.</p>
<pre><code class="javascript">cy.get('.ls-btn').click()

// clearAllSessionStorage() yields null
cy.clearAllSessionStorage().should(() => {
expect(sessionStorage.getItem('prop4')).to.be.null
expect(sessionStorage.getItem('prop5')).to.be.null
expect(sessionStorage.getItem('prop6')).to.be.null
})</code></pre>
</div>
<div class="col-xs-5">
</div>

<div class="col-xs-12"><hr></div>
</div>
</div>
</div>

<script src="/assets/js/vendor/jquery-1.12.0.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/traversal.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/viewport.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/waiting.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li class="active"><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/window.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/cypress-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
10 changes: 7 additions & 3 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down Expand Up @@ -222,9 +222,13 @@ <h2>Commands</h2>
</ul>
</li>
<li>
<a href="/commands/local-storage">Local Storage</a>
<a href="/commands/storage">Storage</a>
<ul>
<li><a href="/commands/local-storage">clearLocalStorage</a></li>
<li><a href="/commands/storage#clearlocalstorage">clearLocalStorage</a></li>
<li><a href="/commands/storage#getalllocalstorage">getAllLocalStorage</a></li>
<li><a href="/commands/storage#clearalllocalstorage">clearAllLocalStorage</a></li>
<li><a href="/commands/storage#getallsessionstorage">getAllSessionStorage</a></li>
<li><a href="/commands/storage#clearallsessionstorage">clearAllSessionStorage</a></li>
</ul>
</li>
<li>
Expand Down
4 changes: 2 additions & 2 deletions app/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand All @@ -64,7 +64,7 @@
<!--
Forked from TodoMVC
https://todomvc.com

MIT License © Addy Osmani, Sindre Sorhus, Pascal Hartig, Stephen Sawchuk
-->

Expand Down
2 changes: 1 addition & 1 deletion app/utilities.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<li><a href="/commands/waiting">Waiting</a></li>
<li><a href="/commands/network-requests">Network Requests</a></li>
<li><a href="/commands/files">Files</a></li>
<li><a href="/commands/local-storage">Local Storage</a></li>
<li><a href="/commands/storage">Storage</a></li>
<li><a href="/commands/cookies">Cookies</a></li>
<li><a href="/commands/spies-stubs-clocks">Spies, Stubs &amp; Clocks</a></li>
</ul>
Expand Down
Loading