Adding PASSED/FAILED to a variable from Test Result

Hi all!

I can get two status in the Test Result tab - PASSED or FAILED.
I want to extract this information (PASSED or FAILED) and get it to the variable. I need only word - Passed or Failed. I attached screenshots what I want to get.


How can I extract this information? Please help!

BR,
Sergey

You can’t access the test results programmatically.

Please see the following topic for more information.

https://community.postman.com/t/get-testresults-value-passed-failed-saved-in-a-variable

What you can do though is edit the test cast and create the variable and result here instead.

For example.

pm.test("Status code is 200", () => {
    // set inital status to fail
    pm.collectionVariables.set("testStatus", "FAILED")
    // your assertion
    pm.response.to.have.status(200);
    // If the assertion fails, then the current pm.test execution will end immediately.
    // No further code in this test block will execute.
    // The testStatus will remain as failed.
    // If the next line executes, it means that the assertion passed.
    pm.collectionVariables.set("testStatus", "PASSED")
});

image

If I force the assertion to fail by changing the status code to 201.

image

The status of the variable is now failed.

Hi! Thank you for reply.