If you wish to verify the exact texts, you can create an array like this:
const texts = [
'Alcohol Anonymous',
'Cance Research',
'Cancer Trust',
'Drinkware',
] //Add additional texts
cy.get('a').each(($ele, index) => {
cy.wrap($ele).should('have.text', texts[index])
})
Alternatively, if you only want to ensure that all links have some text, you can use:
cy.get('a').each(($ele, index) => {
cy.wrap($ele).invoke('text').should('not.be.empty')
})
To check both content and the hyperlink simultaneously, you can try something like this:
const texts = [
'Alcohol Anonymous',
'Cance Research',
'Cancer Trust',
'Drinkware',
] //Add extra texts
const links = [
'https://example1.com',
'https://example2.com',
'https://example3.com',
'https://example4.com',
] //Add more links
cy.get('a').each(($ele, index) => {
cy.wrap($ele)
.should('have.text', texts[index])
.and('have.attr', 'href', links[index])
})
Or, if you simply want to confirm that both the content and hyperlinks are present, you can use:
cy.get('a').each(($ele, index) => {
cy.wrap($ele).invoke('text').should('not.be.empty')
cy.wrap($ele).invoke('attr', 'href').should('not.be.empty')
})