https://cypress.io logo
Intercept request and use statusCode in condition
# i-need-help
a
this code is not working, i dont know how to use a condition for the status code
m
Copy code
cy.wait('@req').its('response.statusCode').should('eq', 200);
a
this way the test fails if status code is != 200, i just want it to go to log not fail
g
Search https://cypress.tips/search and read https://on.cypress.io/request docs. For more, I have a paid course about network testing https://cypress.tips/courses/network-testing
m
Copy code
cy.wait('@req').then((res) => {
    if (res.response?.statusCode !== 200) {
      console.log(res.response?.statusCode)
    }
  });
a
this worked, Thank you very much @mammoth-doctor-80867 💜
g
I added similar example to me network testing course (paid) https://cypress.tips/courses/network-testing/lessons/leon1v7gca similar thing, validates the ui depending on the data returned by the server
2 Views