testing - 如何在 Cypress.io 中强制测试失败
问题描述
在 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 异常来使测试失败:
throw new Error("test fails here")
但是,在您的情况下,我建议改用.should('not.exist')
断言:
cy.contains("Sorry, something went wrong").should('not.exist')
推荐阅读
- salesforce - jsforce metadata.deploy,部署ID
- android - 将 RealmObject 与 Recyclerview ListAdapter 一起使用
- asynchronous - 尝试根据响应其他 API 来响应 Slack
- linux - 按所有者在目录中汇总文件大小的最快方法
- xml - XQuery 按不同类别显示 TITLE 顺序 ORDER BY 年份
- java - 将多个参数传递给 web.xml 中的 org.apache.cxf.jaxrs.swagger.Swagger2Feature
- linux - Ubuntu 18 上的 nginx 网站未在公共 IP 上加载
- php - 如何制作简单的模板?
- java - 改造:向内部 API 发出 Web 请求
- angular - 嵌套 *ngfor。我需要在 Angular.io 的父任务下填充子任务