-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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,85 @@ | ||
context('Connectors', () => { | ||
beforeEach(() => { | ||
cy.visit('https://example.cypress.io/commands/connectors') | ||
}) | ||
|
||
it('.each() - iterate over an array of elements', () => { | ||
cy.get('.connectors-each-ul>li') | ||
.each(($el, index, $list) => { | ||
console.log($el, index, $list) | ||
}) | ||
}); | ||
|
||
it('.its() - get properties on the current subject', () => { | ||
cy.get('.connectors-its-ul>li').its('length').should('be.gt', 2); | ||
}) | ||
|
||
it('.invoke() - invoke a function on the current subject', () => { | ||
cy.get('.connectors-div').should('be.hidden') | ||
// call the jquery method 'show' on the 'div.container' | ||
.invoke('show') | ||
.should('be.visible') | ||
}) | ||
|
||
it('.spread() - spread an array as individual args to callback function', () => { | ||
const arr = ['foo', 'bar', 'baz'] | ||
|
||
cy.wrap(arr).spread((foo, bar, baz) => { | ||
expect(foo).to.eq('foo') | ||
expect(bar).to.eq('bar') | ||
expect(baz).to.eq('baz') | ||
}) | ||
}) | ||
|
||
describe('.then()', () => { | ||
it('invokes a callback function with the current subject', () => { | ||
cy.get('.connectors-list>li').then(function($lis){ | ||
expect($lis).to.have.length(3) | ||
expect($lis.eq(0)).to.contain('Walk the dog') | ||
expect($lis.eq(1)).to.contain('Feed the cat') | ||
expect($lis.eq(2)).to.contain('Write JavaScript') | ||
}) | ||
}) | ||
|
||
it('yields the returned value to the next command', () => { | ||
cy.wrap(1) | ||
.then((num) => { | ||
expect(num).to.equal(1) | ||
|
||
return 2 | ||
}) | ||
.then((num) => { | ||
expect(num).to.equal(2) | ||
}) | ||
}) | ||
|
||
it('yields the original subject without return', () => { | ||
//But unlike a Promise, if undefined is returned, then the original value passed into the .then(cb) is yielded to the next callback. | ||
cy.wrap(1) | ||
.then((num) => { | ||
expect(num).to.equal(1) | ||
// note that nothing is returned from this callback | ||
}) | ||
.then((num) => { | ||
// this callback receives the original unchanged value 1 | ||
expect(num).to.equal(1) | ||
}) | ||
}) | ||
|
||
it('yields the value yielded by the last Cypress command inside', () => { | ||
cy.wrap(1) | ||
.then((num) => { | ||
expect(num).to.equal(1) | ||
// note how we run a Cypress command | ||
// the result yielded by this Cypress command | ||
// will be passed to the second ".then" | ||
cy.wrap(2) | ||
}) | ||
.then((num) => { | ||
// this callback receives the value yielded by "cy.wrap(2)" | ||
expect(num).to.equal(2) | ||
}) | ||
}) | ||
|
||
}) | ||
}) |
This file contains 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,109 @@ | ||
context('Cookies', () => { | ||
beforeEach(() => { | ||
Cypress.Cookies.debug(true) | ||
|
||
cy.visit('https://example.cypress.io/commands/cookies') | ||
|
||
cy.clearCookies() | ||
}) | ||
|
||
it('cy.getCookie() - get a browser cookie', () => { | ||
// https://on.cypress.io/getcookie | ||
cy.get('#getCookie .set-a-cookie').click() | ||
|
||
// cy.getCookie() yields a cookie object | ||
cy.getCookie('token').should('have.property', 'value', '123ABC') | ||
}) | ||
|
||
it('cy.getCookies() - get browser cookies for the current domain', () => { | ||
cy.getCookies().should('be.empty') | ||
cy.get('#getCookies .set-a-cookie').click() | ||
|
||
cy.getCookies().should('have.length', 1).should((cookies) => { | ||
expect(cookies[0]).to.have.property('name', 'token') | ||
expect(cookies[0]).to.have.property('value', '123ABC') | ||
expect(cookies[0]).to.have.property('httpOnly', false) | ||
expect(cookies[0]).to.have.property('secure', false) | ||
expect(cookies[0]).to.have.property('domain') | ||
expect(cookies[0]).to.have.property('path') | ||
}) | ||
}) | ||
|
||
it('cy.getAllCookies() - get all browser cookies', () => { | ||
cy.getAllCookies().should('be.empty') | ||
|
||
cy.setCookie('key', 'value') | ||
cy.setCookie('key', 'value', { domain: 'example.com' }) | ||
|
||
// cy.getAllCookies() yields an array of cookies | ||
cy.getAllCookies().should('have.length', 2).should((cookies) => { | ||
// each cookie has these properties | ||
expect(cookies[0]).to.have.property('name', 'key') | ||
expect(cookies[0]).to.have.property('value', 'value') | ||
expect(cookies[0]).to.have.property('httpOnly', false) | ||
expect(cookies[0]).to.have.property('secure', false) | ||
expect(cookies[0]).to.have.property('domain') | ||
expect(cookies[0]).to.have.property('path') | ||
|
||
expect(cookies[1]).to.have.property('name', 'key') | ||
expect(cookies[1]).to.have.property('value', 'value') | ||
expect(cookies[1]).to.have.property('httpOnly', false) | ||
expect(cookies[1]).to.have.property('secure', false) | ||
expect(cookies[1]).to.have.property('domain', 'example.com') | ||
expect(cookies[1]).to.have.property('path') | ||
}) | ||
}) | ||
|
||
it('cy.setCookie() - set a browser cookie', () => { | ||
cy.getCookies().should('be.empty') | ||
|
||
cy.setCookie('foo', 'bar') | ||
|
||
// cy.getCookie() yields a cookie object | ||
cy.getCookie('foo').should('have.property', 'value', 'bar') | ||
}) | ||
|
||
it('cy.clearCookie() - clear a browser cookie', () => { | ||
// https://on.cypress.io/clearcookie | ||
cy.getCookie('token').should('be.null') | ||
|
||
cy.get('#clearCookie .set-a-cookie').click() | ||
|
||
cy.getCookie('token').should('have.property', 'value', '123ABC') | ||
|
||
// cy.clearCookies() yields null | ||
cy.clearCookie('token') | ||
cy.getCookie('token').should('be.null') | ||
|
||
}) | ||
|
||
it('cy.clearCookies() - clear browser cookies for the current domain', () => { | ||
// https://on.cypress.io/clearcookies | ||
cy.getCookies().should('be.empty') | ||
|
||
cy.get('#clearCookies .set-a-cookie').click() | ||
|
||
cy.getCookies().should('have.length', 1) | ||
|
||
// cy.clearCookies() yields null | ||
cy.clearCookies() | ||
|
||
cy.getCookies().should('be.empty') | ||
}) | ||
|
||
it('cy.clearAllCookies() - clear all browser cookies', () => { | ||
// https://on.cypress.io/clearallcookies | ||
cy.getAllCookies().should('be.empty') | ||
|
||
cy.setCookie('key', 'value') | ||
cy.setCookie('key', 'value', { domain: '.example.com' }) | ||
|
||
cy.getAllCookies().should('have.length', 2) | ||
|
||
// cy.clearAllCookies() yields null | ||
cy.clearAllCookies() | ||
|
||
cy.getAllCookies().should('be.empty') | ||
}) | ||
|
||
}) |