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()
...
}
});
}
这是因为<body>
始终存在,并且您可以通过检查主体上是否存在目标元素来自定义操作。