在 Cypress.io 中,如果满足特定条件,有没有一种方法可以强制测试失败?
例如,在我的网页上,如果字符串“抱歉,出了点问题”。出现在我希望测试失败的页面上。目前这就是我正在做的事情。
/// <reference types="Cypress" />
describe("These tests are designed to fail if certain criteria are met.", () => {
beforeEach(() => {
cy.visit("");
});
specify("If 'Sorry, something went wrong.' is present on page, FAIL ", () => {
cy.contains("Sorry, something went wrong.");
});
});
现在,如果“抱歉,出了点问题”。找到,则测试成功。如果满足此条件,我如何测试失败?
你可以直接扔一个JavaScript 异常 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw测试失败:
throw new Error("test fails here")
但是,根据您的情况,我建议使用.should('not.exist')
而是断言:
cy.contains("Sorry, something went wrong").should('not.exist')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)