×
Clear all filters including search bar
Valeri Tandilashvili's Postman Notes
Content-Type
pm.test("Content-Type is application/json", function () {
pm.response.to.have.header("Content-Type");
});
status
exists in the response JSONpm.test('Has "status" property', function() {
var jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('status');
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}
status code
is equal to 400
pm.test("Status code is 400", function () {
pm.response.to.have.status(400);
});
text
exists in the response JSONpm.test("status text key exists", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.status.text !== undefined).to.eql(true);
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}
code
key is equal to 400
pm.test("status code is equal to invalid HTTP request", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.status.code).to.eql(400);
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}
allowedMilliseconds
with value 100
pm.environment.set("allowedMilliseconds", 100);
Get the environment variablepm.environment.get("allowedMilliseconds")
The environment variable in real use case. In this example response time is checked to be below 100mspm.test("Response time is less than "+pm.environment.get("allowedMilliseconds")+"ms", function () {
pm.expect(pm.response.responseTime).to.be.below(pm.environment.get("allowedMilliseconds"));
});
allowedMilliseconds
with value 100
pm.global.set("allowedMilliseconds", 100);
Get the global variablepm.global.get("allowedMilliseconds")
The global variable in real use case. In this example response time is checked to be below 100mspm.test("Response time is less than "+pm.global.get("allowedMilliseconds")+"ms", function () {
pm.expect(pm.response.responseTime).to.be.below(pm.global.get("allowedMilliseconds"));
});