Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amitasehrawat/957d23ad063b9dd00eb09df73d3cbaf6 to your computer and use it in GitHub Desktop.
Save amitasehrawat/957d23ad063b9dd00eb09df73d3cbaf6 to your computer and use it in GitHub Desktop.
Cypress: How to verify if all child element contains a expected text str
// type definitions for Cypress object "cy"
/// <reference types="cypress" />
describe('My First Cypress Test', function() {
it('verifies that each child element of myElement contains the expected text str.', () => {
const myElement = cy.get('#my-element');
let str = TextToValidate;
myElement.its('length')
.then(count => {
cy.log('count='+count);
if(count>0)
for (let i = 0; i < count; i += 1) {
myElement.eq(i).children().should('include.text', str);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment