javascript - 根据请求的响应跳过 cypress 测试
问题描述
我需要一种基于对 IF/ELSE 条件的评估来跳过赛普拉斯中的测试块的方法。下面是我的代码
it("Website testing",function(){
cy.request({
method: 'GET',
url: "http://127.0.0.1:5000/isIPv6",
timeout:300000
}).then(network_result => {
cy.log(network_result.body)
if(network_result.body.isIPv6 == false)
{
statements
}
else
{
cy.log("IPv6 device, stopping the test")
this.skip()
}
})
})
上面的代码片段之所以起作用,是因为this.skip()
它是一个同步语句,而赛普拉斯为此给出了错误。
我也试过it.skip()
,throw()
但在这种情况下它没有用。我需要一种方法,当执行控制进入 else 块时,我可以跳过测试执行/块,并将测试发送到已跳过/挂起状态。
解决方案
我看到你有it(title, function() {...}
允许访问和修改的模式this
,但你可能还需要将它应用于回调.then()
it("Website testing", function() {
cy.request({
...
}).then(function(network_result) {
...
else {
...
this.skip()
}
})
})
刚刚注意到在skip()
里面it()
,但你应该在开始之前跳过测试it()
,所以可能
beforeEach(function() {
cy.request({
...
}).then(function(network_result) {
...
else {
...
this.skip()
}
})
})
it('skipped if the beforeEach calls "this.skip()"', () => {
...
})
推荐阅读
- react-native - 运行时类型错误:hmrClient.send 不是函数
- api - Nuxt 重新加载 api 数据失败
- swift - 从自定义 .plist 文件中读取用户定义的设置
- botframework - Microsoft Bot framework v4 中消息的跨平台文本格式和 UI 设计
- node.js - 如何在另一台机器上运行节点应用程序而不安装 nodemon 作为全局
- html - CSS中图像的文件路径
- typescript - 当泛型类型设置为从不时,泛型条件类型解析为从不
- python-3.x - 没有循环if语句的for循环
- modelica - 替换 Modelica 中已弃用的函数基数(c)
- install4j - Windows 系统上 error.log 文件的位置