Reputation: 6015
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
Reputation: 2387
In https://www.getpostman.com/docs/postman/scripts/postman_sandbox - paragraph Request/response related properties you can use the 'request' object.
Obsolete use request.name
: gives you the current test case namepm.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
Reputation: 497
Postman v6.5.2 and up uses pm.info.requestName
console.log("Running: "+ pm.info.requestName);
Look at pm.info
object:
Upvotes: 21