- 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
+++
+++
Open "Selector Playground"
+++
Selector playground can suggest much better selectors.
+++
+++
Read best-practices.html#Selecting-Elements
+++
- 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
+++
+++
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)
})
+++
Record tests by clicking on the page
{
"experimentalStudio": true
}
+++
+++
- Use Selector Playground
- follow https://on.cypress.io/best-practices#Selecting-Elements
- bonus: try @testing-library/cypress
+++
- pick elements using Selector Playground
- record tests using Cypress Studio
➡️ Pick the next section