I was trying to log the API response time in Cypress, but could not find any solution. What to use, cy.intercept()
or cy.request()
?
I was trying to use the advice like this:
cy.intercept('POST', '**/create-insurance-view-model', (req) => {
const start = Date.now()
req.continue(res => {
res.responseTime = Date.now() - start;
})
}).as('apiViewModel')
cy.wait('@apiViewModel').then(intercept => {
cy.log(`Time to get the license plate data was: ${intercept.response.responseTime} seconds`)
})
And I am getting undefined in the log.