[英]How do I get my Postman tests to pass using response body as the results?
I am attempting to write tests in Postman for the first time.我第一次尝试在 Postman 中编写测试。 I am using the
pm.test
method containing pm.expect
.我正在使用包含
pm.expect
的pm.test
方法。
Here is my test:这是我的测试:
//contract details tests
pm.test("Contract data is correct", function() {
pm.expect(pm.response.json().results.contractNb).to.equal("00002");
pm.expect(pm.response.json().results.progSrvcNm).to.equal("009");
});
My response appears like so:我的回答是这样的:
{
"contractNb": "00002",
"progSrvcNm": "009",
"contractPartyNm": "testContract",
"terms": 30,
"startDt": "2018-01-01"
}
Given your response body data - If you just remove the .results
part of the expect
statement, the check will pass.给定您的响应正文数据 - 如果您只是删除
expect
语句的.results
部分,则检查将通过。
pm.test("Contract data is correct", () => {
pm.expect(pm.response.json().contractNb).to.equal("00002")
pm.expect(pm.response.json().progSrvcNm).to.equal("009")
})
The correct code was as Danny Dainton posted.正确的代码是 Danny Dainton 发布的。
pm.test('Contract details are correct for the passed in contract ID', () => {
pm.expect(pm.response.json().contractNb).to.equal("00002");
pm.expect(pm.response.json().progSrvcNm).to.equal("009");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.