Reputation: 372
I have an API written in Flask, with URI
"http://127.0.0.1:5000/idpa/isIPv6"
what it does is it checks whether the device I am trying to communicate to has network address belonging to IPv6 or not. Based on the response I am trying to perform further activities, the cypress test that I have written is
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")
cy.wait(10000)
expect(true).to.equal(false)
}
})
})
the API call takes around 90 seconds to return response.
On running the test file, cypress sometimes does not wait from a response, where upon the execution control goes directly to else block wherein it does not log the message or does not wait for 10 seconds, it directly executes the expect
statement. And when expect
is commented then the test ends successfully.
I have tried editing the cypress.json file with
{ "requestTimeout":300000, "responseTimeout":300000 }
But this thing also hasn't worked for me.
How do I make cypress wait for a response ?
Upvotes: 0
Views: 483
Reputation: 3384
Try using Aliases:
it("Website testing",function(){
cy.request({
method: 'GET',
url: "http://127.0.0.1:5000/isIPv6",
timeout:300000
}).as("getData");
cy.wait('@getData'); // <--- wait explicitly for this route to finish
cy.get("@getData").then(network_result => {
cy.log(network_result.body)
if(network_result.body.isIPv6 == false)
{
statements
}
else
{
cy.log("IPv6 device, stopping the test")
//cy.wait(10000)
expect(true).to.equal(false)
}
})
})
Upvotes: 1