使用cy.request()
链接 URL“http://www.alitots.co.uk/”失败并出现以下错误:
请求失败且没有响应
我们尝试向此 URL 发出 http 请求,但请求失败且没有响应。
我们在网络级别收到此错误:
错误:getaddrinfo ENOTFOUND www.alitots.co.uk我们发送的请求是:
方法:GET
URL:http://www.alitots.co.uk/
我该如何处理这个问题并继续检查其他链接?
这是完整的代码:
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 ***`)
}
})
}
})
Run Code Online (Sandbox Code Playgroud)