Search code examples
cypressassertion

Cypress: testing long form


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:

  1. Test stability. As the forms are long, they consist of several sections on separate pages, but not all pages are loading with the same speed. I don't like adding cy.wait() everywhere, previously I also used checking if the page loader is rolling but here we don't have the loader. Are there any more nice ways to make sure the page has loaded before it tests the assertions?
  2. Does skipping failed assertions make any sense or again there's something better to use if I want to get the list of all missing fields as a result of the test? Or is it not a good idea at all?

Thank you in advance and sorry for the long and theoretical question.


Solution

  • 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(', '))
        }    
      })
    })