Reputation: 372
I need a way to skip a test block in Cypress based on the evaluation of IF/ELSE condition. 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.
I have also tried it.skip()
, throw()
but its not useful in this case.
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.
Upvotes: 1
Views: 2068
Reputation:
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("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
beforeEach(function() {
cy.request({
...
}).then(function(network_result) {
...
else {
...
this.skip()
}
})
})
it('skipped if the beforeEach calls "this.skip()"', () => {
...
})
Upvotes: 1