https://cypress.io logo
How can I skip a failure on a response code on a n...
# i-need-help
f
Hey everyone. I have a strange case, pointless to test really but I was asked by a customer. They have settled a limit of 100 requests to a page, and at 100 they show a recaptcha. The test I need to do is basically visit a page 100 times, and at that point the page will return a 405 and the test will crash. So I added a loop. Simply:
Copy code
var count = 100 
for(var i = 0; i < count: i++) {
  cy.visit("https://mypage.com")
}
Now at some point between 95 and 100 (because it depends on other tests that could visit this page more than once) the test will crash saying the page responded with a 405 and did not respond with 20x code. That all makes sense and it is the correct behavior. My question is, what would be the correct way to stop the loop (or complete it, doesn't matter) when I get this response and just continue till the end so I land on the captcha page. I just need to verify the captcha appeared so it is pretty straight forward. I just can't make the
failOnStatusCode: false
because it is not a request block. Any recommendations?e
g
well, cy.visit does have an option not to fail, but then you don't know the status of the page. Instead I would use
cy.request
to ping the page and check the status code until the 405 is returned. You can use
cypress-recurse
to do this easily
f
yeah we already have that in place with request and verify the code, but they wanted to check the UI of the captcha page. How does the option not to fail work in the cy.visit?
Basically the test doesn't care in this case about the failure just needs to land on the fail page to verify the UI there.
Oh
cy.visit("htttps://mypage.com", { failOnStatusCode: false })
seems to be the way 🤔 but it is not picking up, strange.