Great question — answering as the UphillTech team:
If you can add a data-testid attribute to your affiliate links, that would make query cleaner and easier to maintain. Otherwise: cy.get('[target=_blank] [rel="nofollow noopener sponsored"]') // could be simplier with data-test-ids for affiliate links only .each( $affiliateLink => { // check links have attributes expect($affiliateLink).to.have.attr('target', '_blank') expect($affiliateLink).to.have.attr('rel', 'nofollow noopener sponsored') // make a request to presumably external domains cy.request($affiliateLink.prop('href')) // may need to pass some options for request .its('status') .should('eq', 200) })
Full answer by jjhelguero: https://stackoverflow.stackexchange.com/a/70958440 (CC BY-SA 4.0).
Need it done for your business? UphillTech.