Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update example docs to match tests
Browse files Browse the repository at this point in the history
rubysolo authored and Solomon White committed Mar 14, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 9755df4 commit 5cdf74e
Showing 8 changed files with 164 additions and 89 deletions.
170 changes: 118 additions & 52 deletions app/commands/actions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/commands/cookies.html
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ <h4 id="clearCookie"><a href="https://on.cypress.io/clearcookie">cy.clearCookie(
cy.getCookie('token').should('have.property', 'value', '123ABC')

// cy.clearCookies() yields null
cy.clearCookie('token').should('be.null')
cy.clearCookie('token')

cy.getCookie('token').should('be.null')</code></pre>
</div>
2 changes: 1 addition & 1 deletion app/commands/misc.html
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ <h4 id="end"><a href="https://on.cypress.io/end">.end()</a></h4>
// and force Cypress to re-query from the root element
cy.get('.misc-table').within(() => {
// ends the current chain and yields null
cy.contains('Cheryl').click().end()
cy.contains('Cheryl').click()

// queries the entire table again
cy.contains('Charles').click()
3 changes: 3 additions & 0 deletions app/commands/spies-stubs-clocks.html
Original file line number Diff line number Diff line change
@@ -135,6 +135,7 @@ <h4 id="clock"><a href="https://on.cypress.io/clock">cy.clock()</a></h4>
cy.clock(now)
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
cy.get('#clock-div').click()
cy.get('#clock-div')
.should('have.text', '1489449600')</code></pre>
</div>
<div class="col-xs-5">
@@ -157,9 +158,11 @@ <h4 id="tick"><a href="https://on.cypress.io/tick">cy.tick()</a></h4>
cy.clock(now)
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
cy.get('#tick-div').click()
cy.get('#tick-div')
.should('have.text', '1489449600')
cy.tick(10000) // 10 seconds passed
cy.get('#tick-div').click()
cy.get('#tick-div')
.should('have.text', '1489449610')</code></pre>
</div>
<div class="col-xs-5">
53 changes: 30 additions & 23 deletions app/commands/storage.html
Original file line number Diff line number Diff line change
@@ -74,43 +74,48 @@ <h1>Storage</h1>
<div class="col-xs-7">
<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(() => {
<pre><code class="javascript">cy.get('.ls-btn').click()
cy.get('.ls-btn').should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
expect(localStorage.getItem('prop3')).to.eq('magenta')
})

// clearLocalStorage() yields the localStorage object
cy.clearLocalStorage().should((ls) => {
expect(ls.getItem('prop1')).to.be.null
expect(ls.getItem('prop2')).to.be.null
expect(ls.getItem('prop3')).to.be.null
cy.clearLocalStorage()
cy.getAllLocalStorage().should(() => {
expect(localStorage.getItem('prop1')).to.be.null
expect(localStorage.getItem('prop2')).to.be.null
expect(localStorage.getItem('prop3')).to.be.null
})

// Clear key matching string in localStorage
cy.get('.ls-btn').click().should(() => {
cy.get('.ls-btn').click()
cy.get('.ls-btn').should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
expect(localStorage.getItem('prop3')).to.eq('magenta')
})

cy.clearLocalStorage('prop1').should((ls) => {
expect(ls.getItem('prop1')).to.be.null
expect(ls.getItem('prop2')).to.eq('blue')
expect(ls.getItem('prop3')).to.eq('magenta')
// Clear key matching string in localStorage
cy.clearLocalStorage('prop1')
cy.getAllLocalStorage().should(() => {
expect(localStorage.getItem('prop1')).to.be.null
expect(localStorage.getItem('prop2')).to.eq('blue')
expect(localStorage.getItem('prop3')).to.eq('magenta')
})

// Clear keys matching regex in localStorage
cy.get('.ls-btn').click().should(() => {
cy.get('.ls-btn').click()
cy.get('.ls-btn').should(() => {
expect(localStorage.getItem('prop1')).to.eq('red')
expect(localStorage.getItem('prop2')).to.eq('blue')
expect(localStorage.getItem('prop3')).to.eq('magenta')
})

cy.clearLocalStorage(/prop1|2/).should((ls) => {
expect(ls.getItem('prop1')).to.be.null
expect(ls.getItem('prop2')).to.be.null
expect(ls.getItem('prop3')).to.eq('magenta')
// Clear keys matching regex in localStorage
cy.clearLocalStorage(/prop1|2/)
cy.getAllLocalStorage().should(() => {
expect(localStorage.getItem('prop1')).to.be.null
expect(localStorage.getItem('prop2')).to.be.null
expect(localStorage.getItem('prop3')).to.eq('magenta')
})</code></pre>
</div>
<div class="col-xs-5">
@@ -159,10 +164,11 @@ <h4><a href="https://on.cypress.io/clearalllocalstorage">cy.clearAllLocalStorage
<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
cy.clearAllLocalStorage()
cy.getAllLocalStorage().should(() => {
expect(localStorage.getItem('prop1')).to.be.null
expect(localStorage.getItem('prop2')).to.be.null
expect(localStorage.getItem('prop3')).to.be.null
})</code></pre>
</div>
<div class="col-xs-5">
@@ -208,7 +214,8 @@ <h4><a href="https://on.cypress.io/clearallsessionstorage">cy.clearAllSessionSto
<pre><code class="javascript">cy.get('.ls-btn').click()

// clearAllSessionStorage() yields null
cy.clearAllSessionStorage().should(() => {
cy.clearAllSessionStorage()
cy.getAllSessionStorage().should(() => {
expect(sessionStorage.getItem('prop4')).to.be.null
expect(sessionStorage.getItem('prop5')).to.be.null
expect(sessionStorage.getItem('prop6')).to.be.null
21 changes: 11 additions & 10 deletions app/utilities.html
Original file line number Diff line number Diff line change
@@ -88,10 +88,9 @@ <h4 id="$"><a href="https://on.cypress.io/$">Cypress.$</a></h4>
<p>To call a jQuery method, use the <a href="https://on.cypress.io/$"><code>Cypress.$</code></a> command.</p>
<pre><code class="javascript">let $li = Cypress.$('.utility-jquery li:first')

cy.wrap($li)
.should('not.have.class', 'active')
.click()
.should('have.class', 'active')</code></pre>
cy.wrap($li).should('not.have.class', 'active')
cy.wrap($li).click()
cy.wrap($li).should('have.class', 'active')</code></pre>
</div>
<div class="col-xs-5">
<div class="well">
@@ -115,21 +114,23 @@ <h4 id="$"><a href="https://on.cypress.io/$">Cypress.$</a></h4>
<div class="col-xs-7">
<h4 id="Blob"><a href="https://on.cypress.io/blob">Cypress.Blob</a></h4>
<p>To work with blobs, convert strings, and other utility functions, use the <a href="https://on.cypress.io/blob"><code>Cypress.Blob</code></a> library.</p>
<pre><code class="javascript">cy.get('.utility-blob').then(($div) =>
// https://github.com/nolanlawson/blob-util#imgSrcToDataURL
// get the dataUrl string for the javascript-logo
Cypress.Blob.imgSrcToDataURL('/assets/img/javascript-logo.png', undefined, 'anonymous')
<pre><code class="javascript">cy.get('.utility-blob').then(($div) => {
// https://github.com/nolanlawson/blob-util#imgSrcToDataURL
// get the dataUrl string for the javascript-logo
return Cypress.Blob.imgSrcToDataURL('/assets/img/javascript-logo.png', undefined, 'anonymous')
.then((dataUrl) => {
// create an <img> element and set its src to the dataUrl
let img = Cypress.$('<img />', { src: dataUrl })

// need to explicitly return cy here since we are initially returning
// the Cypress.Blob.imgSrcToDataURL promise to our test
// append the image
$div.append(img)

cy.get('.utility-blob img').click()
.should('have.attr', 'src', dataUrl)
}))</code></pre>
cy.get('.utility-blob img').should('have.attr', 'src', dataUrl)
})
})</code></pre>
</div>
<div class="col-xs-5">
<div class="well">
1 change: 0 additions & 1 deletion cypress/e2e/2-advanced-examples/cookies.cy.js
Original file line number Diff line number Diff line change
@@ -83,7 +83,6 @@ context('Cookies', () => {

// cy.clearCookies() yields null
cy.clearCookie('token')
cy.getCookie('token').should('be.null')

cy.getCookie('token').should('be.null')
})
1 change: 0 additions & 1 deletion cypress/e2e/2-advanced-examples/misc.cy.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ context('Misc', () => {
cy.get('.misc-table').within(() => {
// ends the current chain and yields null
cy.contains('Cheryl').click()
//.end()

// queries the entire table again
cy.contains('Charles').click()

0 comments on commit 5cdf74e

Please sign in to comment.