How to verify my value is Greater than or not?

Hi have an scenario, Were my API Requests also only 2500$ in a Request , If i send my Request more than 2500$ , How to verify the value in Tests and displays my error message ?

how to use the condition ? to verify and shows the error.

Please advise
My parameter
Amount : 2500
I have created a Variable as “amnt”
pm.expect(jsonData.data.bill).to.eql(amnt);

What if i pass 2600 in my request and how to verify in Tests and capture the error.

1 Like

Hello @Roshin_08 :wave:

You can try simple greater than symbol or above

 pm.test("Billing amount is less than 2500", function(){
            pm.expect(jsonData.data.bill<2500)
//or based on the req
//pm.expect(jsonData.data.bill<=2500)
});

Else chai below method works too.

 pm.test("Billing amount is less than 2500", function(){
            pm.expect(jsonData.data.bill).to.be.below(2500)
});

It’s better to go with the basic lesser than , greater than options :blush:

5 Likes

Here i have not hardcoded my Bill value , instead i have passed variable as “AMNTT”
pm.expect(jsonData.data.billResponse[0].bill).to.eql(amntt);

IN THIS CASE ABOVE METHODS WORKS LIKE < THAN OR TO.BE.BELOW
or we need to try something else ?? plz confirm it.

Yes it should work, please try both the ways and let me know if you have any issues :blush:

let count = [1,2,3,4]
pm.expect(count.length>4); - step is passing
pm.expect(count.length).to.be.above(4); - receving assertion error failure
kindly help me what is the difference or mistake ?

@harish89

Writing tests in Postman | Postman Blog

The pm.expect assertion uses Chai and that is not a valid assertion as far as I’m aware.

Introduction - Chai (chaijs.com)

Think of its as expected result vs actual result, with the expected and actual results being contained within the parenthesis (). With the words between the two parenthesis being the actual comparison.

Your line is basically just saying pm.expect(expectedresult). You don’t have an assertion included. You can include functions within the parenthesis, which is why its not just erroring when it compiles. It will always pass as its not actually comparing itself with anything. It’s just a statement at this point.

This is incorrect by the way and doesn’t fail the assertion like it should.

let bill = 2600

pm.test("Billing amount is less than 2500", function(){
    pm.expect(bill < 2500)
});

This works and fails the assertion.

pm.test("Billing amount is less than 2500 v2", function(){
    pm.expect(bill).to.be.below(2500)
});

Core advice with any automated test, is to ensure you can make the test fail to rule out any false positives.

3 Likes