Skip to main content

More Response Parameter Variables

response.raw:Raw Response Data

Example of Invocation:

response.raw.status // Response status code (e.g., 200, 301, 404, etc.)
response.raw.responseTime // Response time (in milliseconds)
response.raw.type // Response type (e.g., json, xml, html, etc.)
response.raw.responseText // Response text

response.json:JSON Response Data

image.png

Example of Invocation:

response.json.headers.Token //or response.headers.data["Token"]

response.headers:Headers

image.png Example of Invocation:

response.headers.Server //or response.headers["Server"]

image.png Example of Invocation:

response.cookies.freeform //or response.cookies["freeform"]

Assertion expressions for testing API responses

1、Check if the response body contains a specific string.

pm.assert('response.raw.responseText=="test"');  // Check if the response text is equal to the "test" string 
pm.assert('response.raw.responseText.indexOf("test") > -1'); // Check if the response text contains the "test" string

2、Verify if a particular value in the returned JSON is equal to the expected value.

pm.assert('response.json.hasOwnProperty("errcode")'); // Verify if the JSON object contains the "errcode" field
pm.assert('response.json.errcode=="success"'); // Check if the "errcode" field in the JSON object is equal to the "success" string
pm.assert('response.json.errcode.indexOf("success") > -1'); // Check if the "errcode" field in the JSON object contains the "success" string
pm.assert('response.json.errcode!="success"'); // Verify if the "errcode" field in the JSON object is not equal to the "success" string
pm.assert('response.json.errcode>=1'); // Check if the "errcode" field in the JSON object is greater than 1
pm.assert('response.json.errcode==null'); // Verify if the "errcode" field in the JSON object is null

3、Test if a specific element exists in the response headers (e.g., Content-Type).

pm.assert('response.headers.hasOwnProperty("content-type")');

4、Validate that the status code value is equal to 200.

pm.assert('response.raw.status==200');

5、Verify if the response time exceeds a certain value.

pm.assert('response.raw.responseTime>=100');

6、Confirm that the response type is JSON.

pm.assert('response.raw.type=="json"');