Results: 17
Console notification types
List of all types of console notifications
console.log('console log');
console.info('console info');
console.warn('console warn');
console.error('console error');
check response time in milliseconds using environment variable
Tests that response time is below 100ms
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"));
});
check that the response JSON text is equal to the specified text
Tests that the response JSON is equal to the specified text
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 JSON
check if the response JSON includes certain text
Tests that the response JSON includes text:
Mobile 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"
    }
}
Get the first and last days of the current month
Gets the first and last days of the current month and passes it to the request using
start_date
and
end_date
variables. The following script should be located in
Pre-request Script
let date = new Date();
let year = date.getFullYear()
let month = ("0" + (date.getMonth() + 1)).slice(-2)
let start_date = year+'-'+month+'-01';
let days = new Date(year, month, 0).getDate()
let end_date = year+'-'+month+'-'+days;

pm.collectionVariables.set("start_date", start_date);
pm.collectionVariables.set("end_date", end_date);
Get URL of the request
https://httpbin.org/get?start_date={{start_date}}&end_date={{end_date}}
Postman Snippets
Get variables
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.collectionVariables.get("variable_key");
Set variables
pm.environment.set("variable_key", "variable_value");
pm.globals.set("variable_key", "variable_value");
pm.collectionVariables.set("variable_key", "variable_value");
Unset variables
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.collectionVariables.unset("variable_key");
Send a request
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
    console.log(response.json());
});
Status code: Code is 200
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
Response body: Contains string
pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});
Response body: JSON value check
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.value).to.eql(100);
});
Response body: is equal to a string
pm.test("Body is correct", function () {
    pm.response.to.have.body("response_body_string");
});
Response headers: Content-Type header check
pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});
Response time is less than 200ms
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});
Status code: Successful POST request
pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
Status code: Code name has string
pm.test("Status code name has string", function () {
    pm.response.to.have.status("Created");
});
Response body: Convert XML body to a JSON Object
var jsonObject = xml2Json(responseBody);
Use Tiny Validator for JSON data
var schema = {
    "items": {
        "type": "boolean"
    }
};
var data1 = [true, false];
var data2 = [true, 123];
pm.test('Schema is valid', function () {
    pm.expect(tv4.validate(data1, schema)).to.be.true;
    pm.expect(tv4.validate(data2, schema)).to.be.true;
});
Basic authentication
Postman request
Authorization type: Basic Auth
Username: usr
Password: pwd
PHP cURL request
curl_setopt($ch, CURLOPT_USERPWD, "usr:pwd");
Script execution levels
Script execution levels ordered by execution time
Collection Pre
Folder Pre
Request Pre
HERE GOES REQUEST
Collection Test
Folder Test
Request Test
variable levels and priorities
Variable levels list (ordered by priority - the highest at the top):
Local
Data
Environment 
Collection 
Global
check response header value
Tests that the header
Content-Type
is equal to
application/json; charset=utf-8
pm.test("Content-Type is application/json", function () {
    pm.response.to.be.header("Content-Type", "application/json; charset=utf-8");
});
Results: 17