Skip to content

Latest commit

 

History

History
74 lines (43 loc) · 1.57 KB

File metadata and controls

74 lines (43 loc) · 1.57 KB

☀️ Part 3: Selector playground

📚 You will learn

  • Cypress Selector Playground tool
  • best practices for selecting elements

+++

  • keep todomvc app running
  • open 03-selector-playground/spec.js

+++

How do we select element in cy.get(...)?

  • Browser's DevTools can suggest selector

+++

Chrome suggests selector

+++

Open "Selector Playground"

Selector playground button

+++

Selector playground can suggest much better selectors.

Selector playground

+++

⚠️ It can suggest a weird selector

Default suggestion

+++

Read best-practices.html#Selecting-Elements

Best practice

+++

Todo

  • add test data ids to todomvc/index.html DOM markup
  • use new selectors to write cypress/integration/03-selector-playground/spec.js

Note: The updated test should look something like the next image

+++

Selectors

+++

Cypress is just JavaScript

import {selectors, tid} from './common-selectors'
it('finds element', () => {
  cy.get(selectors.todoInput).type('something{enter}')

  // "tid" forms "data-test-id" attribute selector
  // like "[data-test-id='item']"
  cy.get(tid('item')).should('have.length', 1)
})