Various variables are made available by postman runtime and can be references in the test script. Common ones are responseCode
and responseBody
and responseTime
-
Parse response body
var data = JSON.parse(responseBody);
-
Test Format
tests["Test Name"] = {condition}
e.g tests["Has token"] = data.data.login != null; -
Response times
tests["Response time is less than 500ms"] = responseTime < 500;
-
Http codes
tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;
-
env variables
pm.environment.set("auth_header", "Bearer " + data.data.login);
andpm.environment.get