How to test if something is greater than certain number with POSTMAN

Viewed 39925

I'm trying to make a test in POSTMAN where the size has to be greater than 0 but I haven't been able to make the test correctly.

What I did was to make it fail when the size is smaller than 0.

Is there a function in postman to check if the size is greater than x number?

    pm.test("Step 7/ Getting the resources and availabilites list " , function(){

    pm.expect(pm.response.code).to.be.oneOf([200]);
    if(pm.response.code === 200){
        var jsonData = JSON.parse(responseBody);
        var sizeOK= 1;
        if(jsonData.resources.length>0){

        }else{
            //I will make the test fail if there is not data available on the response.
            pm.test("Response body is empty ", function () {
                pm.expect(pm.response.json().resources.length).to.equal(1);
            });

        }
        console.log(Boolean(jsonData.resources.length>1))
    }

});
3 Answers

Though I'm not sure the degree of precision you need, you get a response size in Postman. It is made of Body size and Headers size (just point on Size's value in the app). In your test area, you can recover Body size doing:

var size=0;
for (var count in responseBody) {
    if(responseBody.hasOwnProperty(count))
        size += 1;
}
console.log("BODY SIZE = " + size); // you'll see the correct value in the console for the body part

and then test against this value ...

Related