0

I need to print one specific Response element from the response body of an API in the Test results Section of postman.

1

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

enter image description here

| improve this answer | |
1

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:

enter image description here

Viewing:

enter image description here

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

| improve this answer | |
  • 1
    Just for an added bonus, in htmlextra, those log statements are now with each request rather than in a separate section. 😁 – Danny Dainton May 3 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 at 14:06
  • 1
    Kinda 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 🏆 – Danny Dainton May 3 at 14:10
  • 1
    @DannyDainton Thanks for the awesome report and will look forward for more aawesome features. – PDHide May 3 at 14:15
  • 1
    If 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. – Danny Dainton May 3 at 14:23

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.