Uploaded March 2025 | Updated November 2026, 5 days ago
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 github.com/bahmutov/cypress-map and the full recipe I am showing in this video is at glebbahmutov.com/cypress-examples/recipes/should-read.html
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 github.com/bahmutov/cypress-map and the full recipe I am showing in this video is at glebbahmutov.com/cypress-examples/recipes/should-read.html
![Compare Text In An Element Against Several Possible Values Using oneOf Assertion
You can confirm an element has text that matches string A OR string B OR string C etc using the Chai oneOf assertion.
cy.get(#guest-name)
.invoke(text)
.should(be.oneOf, [Joe, Mary, Anna])
I prefer the above code to a regular expression. Find this example at https://glebbahmutov.com/cypress-examples Compare Text In An Element Against Several Possible Values Using oneOf Assertion](https://i.ytimg.com/vi/B6LqwUHXCcg/mqdefault.jpg)



![The Text Of Each Element Starts With The Given String
Lets confirm the search results when searching for text mi all start with this text (ignoring the case)
cy.get([name=state]).type(mi)
cy.get(#search-results li)
.should(exist)
.each(function ($li, k) {
const text = $li.text()
expect(text, `state ${k + 1}`).to.match(/^mi/i)
})
Find this example at https://glebbahmutov.com/cypress-examples/ The Text Of Each Element Starts With The Given String](https://i.ytimg.com/vi/BWuWf8mqe3k/mqdefault.jpg)





