Tests pm.request.body output all key value

I’m trying print the request body at “Test Results” :

2019-05-21%2017%2006%2009

My Params and Test Results:

2019-05-21%2017%2013%2029

But name=bbb&password=456 is not my truly request body.
How to only print name=aaa&password=123?

Thanks!

Hey @aisen0921

Welcome to the community :wave:

I’m unsure what you’re asking, would you be able to expand on the information in the question, please?

What are you trying to Test? What is the expected outcome?

If you wanted to check the params for the request, you would probably need to access those via pm.request.url.query.

1 Like

I update my question for more information.

My url like http://url/login.json ,and every url is endwith “.json”
I use pm.request.url.query print empty.

My bad - I think I actually read your question incorrectly. :frowning_face:

I’m still not really sure what you’re trying to do - Do you need a check in place to test for something? Currently, that’s not testing anything.

pm.request.body.urlencoded would be what you need to see those values but this is just going to show you the same thing.

This is not what is actually sent in the request though.

If you use the Postman Console to log that output

console.log(pm.request.body.urlencoded)

You will see that the disabled key/value pairs have the disabled key within the object. Postman uses this during the request to know not to send them through.

You can see the response body in the image that the hidden key/value pairs were not sent as part of the actual request.

If you see here, I’m passing “test1” and “test2”, I’ve unchecked “test3”:

As Danny said, if a parameter is unchecked it’ll have this “disabled: true” key/value.
If I console log “pm.request.body.urlencoded”, it’ll return an array of objects.

18

So I’m doing a filter on all the parameters to only show me ones that DON’T have “disabled: true”

I’m console logging this:
39

And here’s the valid params used as test name (Not sure what your use case for needing this but shrugs:
24

1 Like

This would also add those non hidden values to the Test name but obviously as an object :slight_smile:

pm.test(JSON.stringify(pm.request.body.urlencoded.toObject(true)))

1 Like

@dannydainton
That’s OK.:slightly_smiling_face:

I use “pm.test” because I want see request body、content-type、response content in Run Results, or there has another way ?
(“Export Results” has too many detail for me.)

My requirement like this picture, it’s looks brief, can see all the necessary conditions and responses.

Thank you for providing “console.log” this method,I will use it.

@pfarrell
.filter is what I need, and the example is clearly, thanks.

You’re able to view the details of each of the requests, from the Collection Runner, by selecting the requests name:

This seems like the information that you want to see.

More information about this can be found here:

1 Like