Results: 17
check if the response includes certain header
Tests that the response includes header:
Content-Type
pm.test("Content-Type is application/json", function () {
    pm.response.to.have.header("Content-Type");
});
check if the property exists in the response JSON
Tests that the property
status
exists in the response JSON
pm.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"
    }
}
check the response HTTP status code
Tests that the response HTTP
status code
is equal to
400
pm.test("Status code is 400", function () {
    pm.response.to.have.status(400);
});
check if the key exists in the response JSON
Tests that key
text
exists in the response JSON
pm.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"
    }
}
check the response JSON key value
Tests that the value of
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"
    }
}
set and get environment variables
Set an environment variable
allowedMilliseconds
with value
100
pm.environment.set("allowedMilliseconds", 100);
Get the environment variable
pm.environment.get("allowedMilliseconds")
The environment variable in real use case. In this example response time is checked to be below 100ms
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"));
});
set and get global variables
Set an global variable
allowedMilliseconds
with value
100
pm.global.set("allowedMilliseconds", 100);
Get the global variable
pm.global.get("allowedMilliseconds")
The global variable in real use case. In this example response time is checked to be below 100ms
pm.test("Response time is less than "+pm.global.get("allowedMilliseconds")+"ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(pm.global.get("allowedMilliseconds"));
});
Results: 17