I have a test which use "for" loop and with every loop it changes the url form the array. Main task is to grab all img tags and check if they have an alt attribute.
But it happens on some sub pages, that they don't have img tags at all. And then my test fails on the current loop, then starts next one.
AssertionError: Timed out retrying: Expected to find element: img, but never found it.
I would like to modify my code to check before, if the sub page include some img, and if not, just to pass the test-case and start another loop.
I tried few times, with "if" statement but I can't handle it on my own...
If someone has some idea, please help :)
Below is a code that check all indexes, also if they dont have img inside...
describe("#13939 - Accessibility - Alt text and link title - Group", () => {
let url = [
"https://index-0",
"https://index-1",
"https://index-2",
"https://index-3"
]
for (let i = 0; i < url.length; i++) {
it(`Accessibility - Alt text ${i}`, () => {
cy.visit(url[i]);
cy.get("img").each((item) => {
cy.wrap(item).should("have.attr", "alt").then((alt) => {
expect(alt).not.be.empty;
});
})
})
}
Thank you for every response!
Aucun commentaire:
Enregistrer un commentaire