0

Is it possible to access the complete response size in postman with response body and headers ?

I am able to use the below method to get the size of the response body only

pm.response.responseSize

it will return the size in bytes.

My test case in postman to get the response size looks like this.

pm.test("verify the response size of body", function() {
   pm.expect(pm.response.responseSize).to.be.equal(1024);
  
} );

Thank you in advance , if it is possible to get the size of complete response size from postman , since my API gateway does not support size of the response to be greater than 10MB and I am returning the encoded attachments in response, so I need to verify that the size of response does not cross the upperbound.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Sandeep Negi
  • 27
  • 1
  • 11
  • Please refrain from adding solutions to questions (which you added in your edit, and I've now rolled back). Feel free to post a proper answer with your solution, but... it doesn't go in the question. – David Makogon Jun 26 '21 at 06:26

2 Answers2

1
console.log(pm.request.size())
console.log(pm.response.size())

this gives you the computed size of request and response

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Thank you for your answer, your mentioned function is giving the size of the request. But in my test case i wanted to check the size of the complete response. I have edited the question since the heading of the question was wrong. Thank you for your input – Sandeep Negi Jun 25 '21 at 12:02
  • Your solution already works what's the issue then ? – PDHide Jun 25 '21 at 12:13
  • Use response.size() – PDHide Jun 25 '21 at 12:14
  • response.size() --> gives me the json for the body , header and total , I can get the total from the json Thank you so much for your solution , i will add the solution in the question. – Sandeep Negi Jun 25 '21 at 18:32
1
let responseSize=pm.response.size();
pm.test("Verify total response size",()=>{
    pm.expect(Number(responseSize.total)).to.be.below(1800);
    pm.expect(Number(responseSize.body)).to.be.below(1024);
    pm.expect(Number(responseSize.header)).to.be.below(800);
    }
);

Response contains body and header.For total response size use .total, for body size use .body & for header use .header