Reputation: 85
I have to test 'id' and "prevTrId" for below API response
{"result":{"code":200,"status":"OK"},"securities":[{"id":"3133H","sec":"USIG//FFCB","xcc":0,"liq":"9","dr":"-434.114562","dur":"5.411709","obs":[{"d":1549918953000,"bps":"0.001751","m":231,"prevTrId":"2019021AM_530","apc":{"tt":"-0.000328","tc":"0.001751","tta":"-0.033","tca":"0.175892"}}]}]}
Cypress code:
describe('API Testing with Cypress', () => {
var responsebodydata
it('Validate the header', () => {
cy.request('http://pTe-GPbt-ws.ga.data.com:9082/v1/testing/raw?dateFrom=01-01-2019&dateTo=07-17-2019&reqId=xxxxxx-secIds=3133EJ5H&tradeSizeFrom=10000&tradeSizeTo=5000&tradeSide=BUY&cepSide=BID&cepCompareToTrades=&cepCompareToQuotes').then((response)=> {
responsebodydata = response.body
cy.log(responsebodydata)
expect(response.body).to.have.property('id', '3133H')
})
})
})
cy.log(responsebodydata)
is printing the result as
{result: {code: 200, status: OK}, securities: [Object{7}]}
and I'm getting an assertion error
Expected { Object (result, securities) } to have a property 'id'
Can anyone provide some ideas how to get the 'id' from the response?
Upvotes: 1
Views: 368
Reputation: 8652
Try this to compare the id
property:
expect(response.body.securities[0]).to.have.property('id', '3133H')
This to compare the d
property:
expect(response.body.securities[0].obs[0]).to.have.property('d', 1549918953000);
This to compare the prevTrId
property:
expect(response.body.securities[0].obs[0]).to.have.property('prevTrId', '2019021AM_530');
Upvotes: 1