How can I extract the pass/fail tests results

I want to extract the evaluation results of the tests into an environment variable. This is displayed in the UI as a green box with the test “PASS”, or red with “FAIL”.
App details: Postman App 5.5, IOS 10

@testmonger Not yet. What’s your use-case?

You can use something like this after all your expect statements:
pm.environment.set("TEST - test name", true);

If an assertion failed, this will never be executed, and the value will not be set:

pm.test("response should be okay", function () { 
    pm.response.to.not.be.error; 
    pm.response.to.have.jsonBody(""); 
    pm.response.to.not.have.jsonBody("error"); 
    pm.environment.set("TEST - response should be okay", "TRUE");
});

Hope this helps

3 Likes

Great suggestion abhijit. I would prefer to add the code in a reusable manner, so I will try to implement this at the folder or collection level. I’ve also wondered about creating functions that could be called from any script, perhaps as a library or extension of the SDK. I’m not a programmer, but would like to explore these kinds of options to extend Postman.

My use case is that as a Postman user I want to create or update Test Case issues in JIRA with selected details and test results from each request when executing a Postman Collection Runner. Ideally, I would like to set a flag for each request to signify whether to create/update JIRA (perhaps implemented as a data file for the runner). Also, I would prefer minimize or avoid adding additional code in each request in order to support the JIRA integration.

Were you able to figure this out? I need solution for this as well.

Hi,

Still no news on this topic ? Seems to be a basic feature though…

Anyway here is a homemade proposal to get this reusable:

let checkCnt = 0
let checkPassed = 0

//For each check
pm.test(“response should be okay”, function () {
checkCnt ++;
pm.response.to.not.be.error;
pm.response.to.have.jsonBody(“”);
pm.response.to.not.have.jsonBody(“error”);
checkPassed ++;
});

//Verify that all checks succeeded
if (checkCnt < checkPassed ) {
//Do your stuff
}

Of course you will have to do it at collection / folder / rquest levels if your cecks are spread everywhere.

While it is probably too late to help the original users, if you stumble across this thread with a similar use-case, needing the pass/fail results to report to Jira with reusable code, I’ve written a short series of tutorials explaining how I have approached the task.

1 Like

The solution is simple : just use a try {…} catch {…} pattern

See example here.