Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Conditional check for response in Cypress

enter image description hereI need to put a condition that: if the response body does not meet the criteria so, I need to

cy.log(JSON.stringify(res))

But I do not know how to do it.enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can write something like:

cy.request({
  body: {},
  failOnStatusCode: false,
}).then((res) => {
  if (res.status == 404) {
    cy.log(JSON.stringify(res.body)) //prints the response body
    cy.log(res.body.name) //prints name
    cy.log(res.body.message) //prints message
  } else {
    //Do Something else
  }
})
about 4 years ago · Juan Pablo Isaza Report

0

You can use the fail event to log your response if any criteria fails.

cy.request({
  ...
})
.then(res => {

  Cypress.once('fail', (error, runnable) => {
    cy.log(JSON.stringify(res))
    throw error // throw error to have test still fail
  })

  expect(...
  expect(...
  expect(...
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!