Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the status of test(i.e. pass or fail or error) in Postman?

Here is my test case in postman

pm.test("verify the JSON object keys for machines - ", function() {
    if (Object.keys(data).length === 0) {
        pm.expect(Object.keys(data).length).to.eq(0);
    }
}

Now if status of this test is PASS then I don't want to execute next test case but if status is FAIL then next test case should get executed Next test case is -

pm.test("verify the JSON object keys for machines- ", function() {
        pm.expect(data[1]).to.have.property('timeStamp');
    }
like image 689
Dev Avatar asked Oct 15 '25 13:10

Dev


1 Answers

Perhaps this can be achieved by programmatically skip the tests. Here is the syntax

(condition ? skip : run)('name of your test', () => {

});

Take one variable, update it if the result of the first test is passed

var skipTest = false;

pm.test("verify the JSON object keys for machines - ", function() {
    if (Object.keys(data).length === 0) {
        pm.expect(Object.keys(data).length).to.eq(0);
        skipTest = true // if the testcase is failed, this won't be updated
    }
}

(skipTest ? pm.test.skip : pm.test)("verify timeStamp keys for machines-", () => {
     pm.expect(data[1]).to.have.property('timeStamp');
});

Result Skip

enter image description here

Result Without Skip

enter image description here

like image 117
Divyang Desai Avatar answered Oct 19 '25 10:10

Divyang Desai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!