[英]Skip cypress test based on response of a request
I need a way to skip a test block in Cypress based on the evaluation of IF/ELSE condition.我需要一种基于对 IF/ELSE 条件的评估来跳过赛普拉斯中的测试块的方法。 Below is the code that I have
下面是我的代码
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()
}
})
})
the above code snippet dosent work because this.skip()
is a synchronous statement, and cypress gives error for it.上面的代码片段之所以起作用,是因为
this.skip()
是一个同步语句,而赛普拉斯为此给出了错误。
I have also tried it.skip()
, throw()
but its not useful in this case.我也试过
it.skip()
, throw()
但在这种情况下它没有用。 I need a method wherein I could skip the test execution/block when execution control comes to else block, and send the test to skipped/pending state.我需要一种方法,当执行控制进入 else 块时,我可以跳过测试执行/块,并将测试发送到跳过/挂起的 state。
I see you have the it(title, function() {...}
pattern which allows access and modification to this
, but you probably also need to apply it to the callback in .then()
我看到你有
it(title, function() {...}
模式,它允许访问和修改this
,但你可能还需要将它应用于.then()
中的回调
it("Website testing", function() {
cy.request({
...
}).then(function(network_result) {
...
else {
...
this.skip()
}
})
})
Just noticed the skip()
is inside the it()
, but you should skip the test before it()
starts, so possibly刚刚注意到
skip()
在it()
里面,但是你应该在it()
开始之前跳过测试,所以可能
beforeEach(function() {
cy.request({
...
}).then(function(network_result) {
...
else {
...
this.skip()
}
})
})
it('skipped if the beforeEach calls "this.skip()"', () => {
...
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.