Missed the train? : Assertions in API Testing using POSTMAN

pm.test("Verify the status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test(“Successful POST request”, function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
pm.test(“Status is OK”, function () {
pm.response.to.be.ok;
});
pm.test(“Body matches string”, function () {
pm.expect(pm.response.text()).to.include(“string_you_want_to_search”);
});
pm.test(“Content-Type is present”, function () {
pm.response.to.have.header(“Content-Type”);
});
pm.test(“Response if Json”, function(){
pm.response.to.be.json;
});
pm.test(“Response time is less than 100ms”, function () {
pm.expect(pm.response.responseTime).to.be.below(100);
});
pm.test("environment to be production", function () {pm.expect(pm.environment.get("env")).to.equal("production");});
pm.expect(pm.cookies.has(‘sessionID’)).to.be.true;
pm.test(“Cookies_Value_Check”, function(){
pm.expect(pm.cookies.get(‘sessionID’)).to.eql(‘abc123’);
});
pm.test(“ISBN Count”, function () {
pm.expect(2).to.eql(pm.response.json().arrayName.length);
});
pm.test(“Test Name”, function () {
var result;
for (var loop = 0; loop < pm.response.json().arrayName.length; loop++)
{
if (pm.response.json().arrayName[loop].arrayElement=== pm.variables.get(“arrayElementValue”)){
result=true;
break;
}
}
pm.expect(true).to.eql(result);
});
pm.test(“Empty Array”, function(){
pm.expect([2]).to.be.an(‘array’).that.is.empty;
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store