Javascript Cypress:一旦测试失败,测试运行程序就会停止,即使测试中途失败,我们还能继续测试吗

Javascript Cypress:一旦测试失败,测试运行程序就会停止,即使测试中途失败,我们还能继续测试吗,javascript,automation,cypress,Javascript,Automation,Cypress,这是我正在使用的代码,当找不到第一个元素时,测试将在那里停止,如何使测试继续进行并验证测试套件中的其他内容?您可以通过以下方式执行: getUsertextbox4() { cy.get('#multiselect-field-label-1') } getsubmitButton() { cy.get('.security--button'); } 这是因为始终存在,您可以通过检查主体上是否存在目标元素来定制操作 getUsertextbox4() { cy.get('

这是我正在使用的代码,当找不到第一个元素时,测试将在那里停止,如何使测试继续进行并验证测试套件中的其他内容?

您可以通过以下方式执行:

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

 getsubmitButton() 
{
  cy.get('.security--button');
}
这是因为
始终存在,您可以通过检查主体上是否存在目标元素来定制操作

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()
          ...
      }
  });
}