我必须针对以下API响应测试“ id”和“ prevTrId”
{"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"}}]}]}
柏树代码:
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)
将结果打印为
{result: {code: 200, status: OK}, securities: [Object{7}]}
我收到断言错误
期望{对象(结果,证券)}具有属性“ id”
任何人都可以提供一些想法来从响应中获取“ id”吗?
答案 0 :(得分:0)
尝试以下方法比较id
属性:
expect(response.body.securities[0]).to.have.property('id', '3133H')
这是用来比较d
属性的:
expect(response.body.securities[0].obs[0]).to.have.property('d', 1549918953000);
这是用来比较prevTrId
属性的:
expect(response.body.securities[0].obs[0]).to.have.property('prevTrId', '2019021AM_530');