cy.contains
and command retries- two ways to run Cypress
- screenshots and video recording
- keep
todomvc
app running - open Cypress from the root folder with
npm run cy:open
- click on
01-basic/spec.js
(we are using customspecPattern
)
/// <reference types="cypress" />
it('loads', () => {
cy.visit('localhost:3000')
cy.contains('h1', 'Todos App')
})
+++
cy.contains('h1', 'Todos App')
is not working 😟
Note: This is a good moment to show how Cypress stores DOM snapshots and shows them for each step.
+++
- where are the docs for
cy.contains
command? - why is the command failing?
- hint: use DevTools
- can you fix this?
+++
- do you see the command retrying (blue spinner)?
- try using the timeout option to force the command to try for longer
cypress open
cypress run
See https://on.cypress.io/command-line
💡 Hint: npx cypress help
+++
- run just the spec
cypress/integration/01-basic/spec.js
in headless mode?
💡 Hint: npx cypress run --help
+++
Todo: use cypress run
with a failing test.
- video recording https://on.cypress.io/configuration#Videos
cy.screenshot
command
- can you fix the test?
- how would you select an element:
- by text
- by id
- by class
- by attributes
Tip: https://on.cypress.io/best-practices#Selecting-Elements
📝 Read: https://glebbahmutov.com/blog/debug-cy-get-and-contains/
- most commands retry
- run Cypress in headless mode on CI with
cypress run
- screenshots and videos
➡️ Pick the next section or jump to the 02-adding-items chapter