50

How do I output some information in Postman tests?

console.log(tv4.error);
tests["Valid Data1"] = tv4.validate(data1, schema);

console.log() seems to be working but I want to output my info into the same panel where my assertions go (for easier correlation):

enter image description here

UserControl
  • 14,766
  • 20
  • 100
  • 187

7 Answers7

80

Just make a fake test that passes:

var jsonData = JSON.parse(responseBody);
tests["id = " + jsonData.id] = true;              // debug message
tests["name = " + jsonData.name] = true;          // debug message
Veener
  • 4,771
  • 2
  • 29
  • 37
  • 2
    I know that this is the "correct" way to do this in postman but it really seems like a hack. The problem is that if you run several tests in the collection runner those statements are not shown in the order that they happened. This makes me have to do both console.log + console.error + test[''] to really understand what is happening. PostMan should just pipe the tests[] data directly to console.log and console.eror messages based on if the test passes or fails. – sjdirect Oct 21 '16 at 22:17
  • 7
    Postman is chrome application, it always has dev tools and console, you can open it from menu `View > Show DevTools` or `View > Show Postman Console` – ilumin May 05 '17 at 04:55
  • I am using the following to write to console logs. console.log(request.name + ": Application is missing, skipping validation"); – Diceyus Mar 30 '20 at 10:11
12

Reference for the people who just want to use Chrome’s Developer Tools (which will let you see console output and give you many more features)

To enable it

  1. Type chrome://flags inside your Chrome URL window
  2. Search for "Debugging for packed apps" setting
  3. Enable the setting
  4. Restart Chrome

You can access the Developer Tools window by right clicking anywhere inside Postman and selecting "inspect element".

You can also go to chrome://inspect/#apps and then click "inspect"

Reference

cilerler
  • 9,010
  • 10
  • 56
  • 91
9

I used this, which isn't the prettiest, but it works for what I needed.

tests["your test name here " + data.data.length] = data.data.length > 100;
Swagin9
  • 1,002
  • 13
  • 24
4

Piggybacking on the other answers, just define a function in your Postman test code

var print = function(s){
  tests[s] = true;  
};

then consume it like

print("current value of x: " + x);
Patrick
  • 1,227
  • 14
  • 17
2

Now You have got sth called "Postman Console" To run it please type CTRL + ALT + C For mor info see here: https://blog.getpostman.com/2016/08/26/the-postman-console/

Daniel Hornik
  • 1,957
  • 1
  • 14
  • 33
0

One of the way is use the tests[""+value].

e.g

http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=Your_API_Key.

Response :

Blockquote

Pramod Dutta
  • 111
  • 2
  • 12
0

Similar to a previous answer regarding an alternate option: using dev tools. However, if you are using the native app, right clicking to get the dev tools won't work.

Instead,

  1. Head to View in the application menu, and click on "Show DevTools".
  2. In the DevTools window, clicking on the top level Console tab should show the app’s debug logs.

Reference: https://learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run

bdphilly
  • 3
  • 2