Cypress
yarn add -D cypressUsage
Based off jQuery, Mocha and Chai with many of the same selector and test interfaces
Queues all the commands async so use .then() and such to handle conditionals
Supports ES6 and importing packages out of the box
// Each method is equivalent to its jQuery counterpart. Use what you know!
cy.get('#main-content')
.find('.article')
.children('img[src^="/static"]')
.first()./node_modules/.bin/cypress openYup no imports or anything needed
/* global describe it cy */
describe('My First Test', () => {
it('finds the content "type"', () => {
cy.visit('https://example.cypress.io')
cy.get('.main').contains('New Post')
cy.contains('Like article')
cy.url().should('include', '/commands/actions')
cy.get('.action-email')
.type('fake@email.com')
.should('have.value', 'fake@email.com')
})
})Commands
Cy will retry most commands until it finds the element or timeouts(default 4 secs)
.blur()- Make a focused DOM element blur..focus()- Focus on a DOM element..clear()- Clear the value of an input or textarea..check()- Check checkbox(es) or radio(s)..uncheck()- Uncheck checkbox(es)..select()- Select an<option>within a<select>..dblclick()- Double-click a DOM element..rightclick()- Right-click a DOM element.
Should
Advanced
cy.exec()- to run system commandscy.task()- to run code in Node via thepluginsFilecy.request()- to make HTTP requests
Hooks(Lifecycle?)
Act on A Subject Sync with .then()
Assertions
Explicit Subjects: Using
expect, harder not recommended
Other
Last updated