Uploaded June 2023 | Updated September 2026, 1 week ago
This video shows how to check multiple checkboxes and how to validate the number of checked and clear boxes in your Cypress tests
// there are no checked boxes at first
cy.get('input[type=checkbox]:checked').should('have.length', 0)
const n = Cypress._.random(1, 5)
cy.log(`checking the first ${n} boxes`)
for (let k = 0; k less than n; k += 1) {
cy.get('input[type=checkbox]').eq(k).check()
}
cy.get('input[type=checkbox]:checked').should('have.length', n)
// clear boxes
cy.get('input[type=checkbox]:not(:checked)').should(
'have.length',
5 - n,
)
Find this recipe at glebbahmutov.com/cypress-examples
This video shows how to check multiple checkboxes and how to validate the number of checked and clear boxes in your Cypress tests
// there are no checked boxes at first
cy.get('input[type=checkbox]:checked').should('have.length', 0)
const n = Cypress._.random(1, 5)
cy.log(`checking the first ${n} boxes`)
for (let k = 0; k less than n; k += 1) {
cy.get('input[type=checkbox]').eq(k).check()
}
cy.get('input[type=checkbox]:checked').should('have.length', n)
// clear boxes
cy.get('input[type=checkbox]:not(:checked)').should(
'have.length',
5 - n,
)
Find this recipe at glebbahmutov.com/cypress-examples










![Custom Should Read Assertion From Cypress-map Plugin
This video shows a custom read assertion that checks the text of a single or multiple elements using strings or regular expressions:
cy.get(li).should(read, [
Write code,
Add tests,
/^Pay $d+ fine$/,
])
The assertion is part of my cypress-map plugin https://github.com/bahmutov/cypress-map and the full recipe I am showing in this video is at https://glebbahmutov.com/cypress-examples/recipes/should-read.html Custom Should Read Assertion From Cypress-map Plugin](https://i.ytimg.com/vi/AzJx-8VD6yI/mqdefault.jpg)