Created
June 7, 2023 14:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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