Ulysses
Ulysses

Reputation: 6015

Is it possible to refer to postman call name within the tests body

App Details:

Postman for Chrome
Version 5.0.1
win / x86-64
Chrome 58.0.3029.110

In my collection, I have various requests within folders. e.g. Collection>CollectionFolder1>Request1, Request2 ...

Is it possible to get a reference of the request names within the tests so that I could write something like:

try {
   ...
} catch (e) {
    tests[Test failed with exception ${e} for call request ${SOME_VARIABLE_THAT_STORES_REQUEST_NAME}] = false
}

This would allow me to duplicate this skeleton in all my requests without having to bother about maintaining it.

Is there any postman variable or structure that would store any such info.

Upvotes: 16

Views: 15825

Answers (2)

A.Joly
A.Joly

Reputation: 2387

In https://www.getpostman.com/docs/postman/scripts/postman_sandbox - paragraph Request/response related properties you can use the 'request' object.

request.name: gives you the current test case name Obsolete use pm.info.requestName

request.method: gives you the method used (PUT, GET, etc.)

request.url: gives you the target url

In order to see all the available data you may use, I suggest you to open the console (View/Show postman console or Alt+Ctrl+C) and see the data returned by this: console.log(request)

Upvotes: 32

Dan Krueger
Dan Krueger

Reputation: 497

Postman v6.5.2 and up uses pm.info.requestName

console.log("Running: "+ pm.info.requestName); 

Look at pm.info object:

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#scripting-with-request-info

Upvotes: 21

Related Questions