pm.environment.set("allowedMilliseconds", 100);
pm.test("Response time is less than "+pm.environment.get("allowedMilliseconds")+"ms", function () {
pm.expect(pm.response.responseTime).to.be.below(pm.environment.get("allowedMilliseconds"));
});
pm.test("Body is correct", function () {
pm.response.to.have.body('{"status":{"code":400,"text":"Mobile Number is required"}}');
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}
The test returns true
because the text passed to the test is the same as the response JSONMobile Number
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("Mobile Number");
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}
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"
}
}
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"
}
}