Chr*_*try 16 testing qa cypress
在 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.");
});
});
Run Code Online (Sandbox Code Playgroud)
现在,如果“抱歉,出了点问题”。找到了,测试成功。如果满足此条件,我如何无法通过测试?
Zac*_*ist 37
你可以抛出一个JavaScript 异常来使测试失败:
throw new Error("test fails here")
Run Code Online (Sandbox Code Playgroud)
但是,在您的情况下,我建议改用.should('not.exist')断言:
cy.contains("Sorry, something went wrong").should('not.exist')
Run Code Online (Sandbox Code Playgroud)