How to display actual response values in test results

Hi all,

I am attempting to display an actual value from an API call ‘Body response’ and also a ‘Headers’ item in test results.

I can interrogate both by const response = pm.response.json() and pm.response.headers.get… and display them using console.log but is there a way to display the actual values in test results ?

For example, I might get number of items = 4 in the body response. I can get the value of ‘4’ printed in console.log but how do I get a test result to display ‘4’. Similarly, a ‘correlation id’ is displayed in ‘Headers’, can I get this displayed in test results, not just in console.log.

Thanks in advance.

Hey @dgreen65 :wave:

Welcome back to the Postman Community! :postman:

Could you provide an example of the response body and the test that you have in place so far?

Hi Danny, to give a bit of background, I have a test collection (launched manually) which includes over 100 tests.

At the end of the run I need to export the results which, as they only include high level information (by default), don’t include some data I need such as ‘header’ information.

If I can get the data within the test results themselves then it would be displayed in the report/export.

A test could just be a simple GET call resulting in total number response, the first part of the body response being;

{
      "resultCount": 1;      etc
} 

The same test will have an ID within the ‘Headers’ tab;

Key: Request-Id    Value: xxxxxxxxxxxxxxxxxxxxxxx

I can parse the responses, confirm the resultcount is a number etc etc and I can also convert the request-id to an environment variable.

What I wan to be able to do is DISPLAY both results in test results so they will then be included in the test run export at the end of the run.

e.g result count =, request id =

Hope that makes sense :slight_smile:

Thanks.

Hey @dgreen65,

So you can you template literals in the actual test name to display different pieces of information.

This is a dummy example but this would be resolving the value from the response body and using that in the test name string.

const id = pm.response.json().id
pm.test(`Check for ID - ID equals ${id}`)... 

Is that the type of thing that you’re after?

Hi Danny, thanks for the response, I just need the actual results displaying within the Test Results tab not just confirmtaion that a result exists e.g. PASS Result count = 1 in the above example

I can get both values to be displayed in the console.log so I would have thought the same result could be displayed in the test results themselves, that’s my logic anyway :slight_smile:

That’s what I was explaining, did you try what I suggested? :sweat:

image

You would see that name in the tests tab with the values from the response or a variable or anything else.

Can you show me what you get when you try that out on your side please?

Sorry, I’m no postma/java expert so I didn;t get enough of a hint from your reply :slight_smile:

It’s working great thanks for displaying the result count using;

const count = pm.response.json().resultCount
pm.test (Result count equals ${count])

I’m just trying to work out gtting the same result from the header tab using pm.response.headers.get… but not quite cracked it yet

Thanks for your guidance :slight_smile:

Glad you have something working so you can see how it all comes together. :trophy:

You could get the header value by doing something like this:

let RequestId = pm.response.headers.get('Request-Id');

More information on the pm.* set of APIs can be found here:

Cheers, thanks for your help Danny.

1 Like