[英]Skip cypress test based on response of a request
我需要一種基於對 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 塊時,我可以跳過測試執行/塊,並將測試發送到跳過/掛起的 state。
我看到你有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()"', () => {
...
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.