Using cy.request() with the link URL "http://www.alitots.co.uk/" fails with this error:
The request failed without a response
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
Error: getaddrinfo ENOTFOUND www.alitots.co.ukThe request we sent was:
Method: GET
URL: http://www.alitots.co.uk/
How do I handle this and carry on checking the other links?
This is the full code:
cy.get("a:not([href*='mailto:'])").each(($link, index) => {
const href=$link.prop('href')
cy.log(href)
if (href) {
cy.request({
url: href,
failOnStatusCode:false,
followRedirect:false,
failOnNetworkError:false
})
.then((response)=>{
if(response.status >= 400 || response.status == '(failed)') {
cy.log(` *** link ${index +1} is Broken Link ***`)
//brokenLinks++
} else {
cy.log(` *** link ${index+1} is Active Link ***`)
}
})
}
})
The error code
ENOTFOUNDmeans the server is not running.All you are testing at the moment is the
response, but there is no server to give a response.You need to add a ping. If you do it manually in the terminal
ping http://www.alitots.co.uk:This question gives you a way to ping the server from within the test
Checking if host is online in Cypress
result.stdoutcontains the same message as above.