简体   繁体   English

如何使用响应正文作为结果让我的 Postman 测试通过?

[英]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.expectpm.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.

相关问题 在Postman中,我如何从“获取请求”中获取响应正文,并将其放入经过细微更改的PUT请求中 - In Postman, how do I take a response body from a Get Request, and put it in a PUT request with minor changes 我可以用 Postman 得到正确的响应,但是获取响应的主体是空的 - I can get correct response with Postman but body of the fetch response is empty 如何在 postman 测试中检查请求正文是否有密钥 - How can I check request body has a key or not in postman tests 如何在 Postman javascript 测试中将响应值复制到剪贴板? - How do you copy response values to the clipboard in Postman javascript tests? 如何使用 postman 验证响应正文中的特定文本 - How to verify a particular text in response body using postman 如何使用 NestJS 将纯文本作为我的请求正文传递? - How do I pass plain text as my request body using NestJS? 无法从邮递员响应机构获得价值 - Not able to get value from postman response body 如何在 GET 方法中传递给 API 主体? - How do I pass to API body in GET method? 如何使用 Express.js 获取 postman 的图像? - How do I get an image to postman using Express.js? 如何在我的图表中传递Ajax响应数据 - how do I pass the Ajax response data in my highcharts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM