Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retreive API response data with cy.intercept

I'm intercepting request URL: https://api-stg.geneplanet.com/api/nipt-exporters/tasks/407ff05afdec42caa17a660d2c855117/status Response of requested URL is

{
  "name": "ExportN2DStatisticsOrchestrator",
  "instanceId": "407ff05afdec42caa17a660d2c855117",
  "runtimeStatus": "Completed",
  "input": {
  "BlobUri": "https://niptexportersstgsa.blob.core.windows.net/nipt-exports/N2D statistics 
  export_11.04.2022 13.38.49.xlsx?sv=2018-03- 
  28&sr=c&sig=V0pXmIQUccUdkm0WtsZ3ENjfr%2FtYiCvYDztgZ6JWaYk%3D&se=2022-04- 
  11T12%3A38%3A49Z&sp=rc",
  "From": "2022-03-11T00:00:00+00:00",
  "To": "2022-04-11T23:59:59+00:00"
  },
  "customStatus": {
    "message": "done"
  },
  "output": null,
  "createdTime": "2022-04-11T11:38:49Z",
  "lastUpdatedTime": "2022-04-11T11:38:50Z"
}

I want to make the assertion on runtimeStatus equals Completed.

Following code is not working:

cy.intercept('https://api-stg.geneplanet.com/api/nipt-exporters/tasks/*/status').as('exp')
cy.get('.col-sm-12').should('be.visible').and('contain','Export').click()
cy.get('.ng-star-inserted > .p-4 > .mb-2').should('be.visible').and('contain','N2D Statistics export')
cy.get('.ng-star-inserted > .p-4 > .mb-2').should('be.visible').and('contain',' Preparing a document. Please wait.')
cy.wait('@exp').its('response.runtimeStatus').should('eq', 'Completed')

I've also tried should('include') and should('contain') in the last line. What am I doing wrong?

like image 830
enroberte Avatar asked Nov 27 '25 04:11

enroberte


1 Answers

The cy.wait('@exp') yields an interception object, see Using the yielded object

// interception object
{
  request: {...},
  response: {
    headers: {...},
    body: {
      "name": "ExportN2DStatisticsOrchestrator",
      "instanceId": "407ff05afdec42caa17a660d2c855117",
      "runtimeStatus": "Completed",
      ...
}

so this should work

cy.wait('@exp').its('response.body.runtimeStatus').should('eq', 'Completed')

or

cy.wait('@exp').its('response.body').should('have.property', '.runtimeStatus', 'Completed')
like image 146
Fody Avatar answered Nov 30 '25 00:11

Fody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!