I am testing a large number of really long forms (ca 50 forms, most of them are 150+ fields), and one set of tests is checking whether all fields exist in each form. Using the latest Cypress 10 version. Need ideas how to make the tests most bullet proof in two dimensions:
Thank you in advance and sorry for the long and theoretical question.
I guess you are performing cy.get()
on each selector from a list of expected field selectors?
If you are concerned about page loading taking too long, just increase the timeout for each selector (there's no need to cy.wait() for the page).
Skipping failures makes sense, and you could do it with soft assertions but a more straight-forward way is to use cypress-if
An example
const fails = []
cy.fixture('field-selectors.json').then(selectors => {
cy.wrap(selectors).each(selector => {
cy.get(selector, {timeout:10_000})
.if()
.else() // fails go to the following command in chain
.then(() => fails.push(selector)
})
.then(() => {
if (fails.length) {
throw new Error('Some selectors failed: ' + fails.join(', '))
}
})
})