Can you try to use cy.get()
and .each()
for the entire test logic ?
describe('I am testing the Modals on ' + modalUrls.length + ' pages.', () => {
modalUrls.forEach(function(page) {
it(`should open and close all modals on ${page}`, () => {
cy.visit(page);
cy.get('[data-modal-trigger]').each(($triggerLink) => {
const modalId = $triggerLink.attr('data-modal-trigger');
if (modalId) {
cy.log(`Processing modal with ID: ${modalId}`);
cy.wrap($triggerLink).click();
cy.get(`#${modalId}`).should('be.visible');
cy.get(`#${modalId} [data-modal-close]`).click();
cy.get(`#${modalId}`).should('not.be.visible');
}
});
});
});
});