1.Status Code :Code is 200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
2.Response Body:Contains String
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});
3.Response Body:JSON Value Check
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.value).to.eql(100);
});
4.Response Body:Is Equal to a String
pm.test("Body is correct", function () {
pm.response.to.have.body("response_body_string");
});
5.Response Headers:Content-Type headers chenck
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
6.Response Time is less than 200ms
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
7.Status code: Successful POST request
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
8.Status code: Code name has String
pm.test("Status code name has string", function () {
pm.response.to.have.status("Created");
});
9.Response Body:Convert XML body to a JSON Object
var jsonObject = xml2Json(responseBody);
10.Use Tiny Valldator 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;
});