0

I'm using Postman to automate an API using Newman.

But the response body of the API call is not showing in the Postman "Test results" tab.

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.

The output of above is showing as,
PASS [object Object]

Any suggestions to print the API response will be of great help. Thanks in advance!

  • Have you tried a console.log? – João Farias Aug 12 '19 at 17:19
0

Please try without parsing, Like below

var body = JSON.parse(responseBody); 
var content = responseBody;
tests["Response Body"+content]= body.length != 0
1

Rather than reinvent the wheel, if you're implementing that then there is a lovely graphical HTML report you can tag onto newman that just does all that for you (newman-reporter-htmlextra).

It auto records the headers / body / etc of the requests and responses. It also helps with providing a "management" friendly colourful report of the results.

You just need to install it into Node.js then add on a switch in the newman call.

e.g.

newman run myFile.json -e environment.json --reporters htmlextra --reporter-htmlextra-export reportfilelocation.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.