Я создал следующий тест: < /p>
Код: Выделить всё
describe('I am testing the Modals on ' + modalUrls.length + ' pages.', () => {
let triggerLinksObj = {};
modalUrls.forEach(function(page, index) {
it(`It accesses ${page}`, () => {
cy.visit(page);
});
it(`Collects modal trigger links on ${page}`, () => {
cy.get('[data-modal-trigger]').each(($triggerLink, index) => {
const modalId = $triggerLink.attr('data-modal-trigger');
if (modalId) {
triggerLinksObj[index] = modalId;
}
})
});
Object.entries(triggerLinksObj).forEach(([key, val]) => {
it(`Processes modal link with ID: ${val}`, () => {
cy.task('log', `Processing modal link with key: ${key}, value: ${val}`);
//do the tests with the modal
});
});
});
});
Я могу поместить foreach в блок It как таковой:
Код: Выделить всё
it(`Processes modal links`, () => {
Object.entries(triggerLinksObj).forEach(([key, val]) => {
cy.task('log', `Processing modal link with key: ${key}, value: ${val}`);
//do the tests with the modal
});
});
Подробнее здесь: https://stackoverflow.com/questions/797 ... t-each-one
Мобильная версия