krishna chetan
krishna chetan

Reputation: 659

Cypress:The test runner stops as soon as there is a failure in test, can we continue testing even when a test fails in middle

getUsertextbox4() 
{
  cy.get('#multiselect-field-label-1')
}

 getsubmitButton() 
{
  cy.get('.security--button');
}

this is the code im using and when the first element is not found , tests stop there it self , how to make the test continue further and verify others things in the test suite ?

Upvotes: 0

Views: 323

Answers (1)

Yuan Yao
Yuan Yao

Reputation: 26

You can do in this way:

getUsertextbox4() 
{
  cy.get('body').then(($body) => {
      if ($body.find('#multiselect-field-label-1').length) {
          // continue the test
      } else {
          // you can throw error here, or just print out a warning message
          // and keep testing other parts of your code, eg:
          Cypress.log({ warning: 'unable to find the element' });
          getsubmitButton()
          ...
      }
  });
}

This works because <body> is always there, and you can customize the action by checking the existence of target element on body.

Upvotes: 1

Related Questions