I need to print one specific response element from the response body of an API in the test results section of Postman.
2 Answers
Assuming that you want to print a data from the response value
var jsonData = pm.response.json();
var testmessage=jsonData._data[0].UserName //Dev_demo_82
pm.test(testmessage, function () {
//testscript
});
Response value of Property UserName
will be stored in variable testmessage
now your test name will be displayed as shown in image below
Mohamed's step will allow you to do what you wanted, but if you are trying to debug something then postman already have the postman console for this purpose.
so just use console.log() in the prerequisite or test script session and open view>show postman console in the postman menu bar.
Now run the request and you can see that the value is printed in the console.
Opening:
Viewing:
Note: if you click on the request it will show all details like the request header, body, response etc
in newman htmlextra report you can get these details in the report using the --reporter-htmlextra-logs flag
-
1Just for an added bonus, in htmlextra, those log statements are now with each request rather than in a separate section. 😁 May 3, 2020 at 14:04
-
1@DannyDainton you are a life saver Danny . That's an awesome change thank you for that . Hope you will come up with consolidating different Newman reports together as in mocha report– PDHide ♦May 3, 2020 at 14:06
-
1Kinda out of my control as Newman is a one collection at a time type thing...not heard any internal chats for changing that at the moment. 😔 Keep up the great effort in here answering all the questions 🏆 May 3, 2020 at 14:10
-
1@DannyDainton Thanks for the awesome report and will look forward for more aawesome features.– PDHide ♦May 3, 2020 at 14:15
-
1If we're not connected outside of here - let's make that happen. Would love to hear more of your thoughts. Apologies for hijacking the thread. May 3, 2020 at 14:23