简体   繁体   English

在邮递员的“测试结果”选项卡中打印API响应

[英]Print API response in “Test results” tab in Postman

I'm using Postman automate an API with Newman.But the response body of the API call is not showing in the newman. 我正在使用Postman使用Newman自动化API。但是API调用的响应主体没有在newman中显示。

var body = JSON.parse(responseBody);
tests["Response Body ", body] = true;

I have tried the above code,but even after successful API call the response is not printing in the "Test results" tab. 我已经尝试了上面的代码,但即使在成功调用API之后,响应也不会在“测试结果”选项卡中打印。

the output of above is showing as, 上面的输出显示为,

PASS [object Object]

Any suggestions to print the API response will be of great help. 任何打印API响应的建议都会有很大帮助。

Thanks in advance! 提前致谢!

I assume you're using the cli reporter with Newman, you could just add a console.log(pm.response.json()) statement to the Tests tab. 我假设你正在使用纽曼的cli记者,你可以在Tests选项卡中添加一个console.log(pm.response.json())语句。

That should print out the response body on the console during the Newman run. 这应该在Newman运行期间打印出控制台上的响应主体。

If you wanted something to show you all the details of the Newman run in a separate report, you could also use a different reporter, like this HTML one ;) 如果你想在某个单独的报告中向你显示纽曼的所有细节,你也可以使用另一个报告者,比如这个HTML;)

https://www.npmjs.com/package/newman-reporter-htmlextra https://www.npmjs.com/package/newman-reporter-htmlextra

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM