API Automation Testing Script to check Response

pm.test("Status code is 200"function () {
    pm.response.to.have.status(200);
});

pm.test("Check Status Code is 200"function () {
    var jsonData = pm.response.json();
     var statusCode = jsonData.StatusCode
    pm.expect(statusCode).is.equal("200")
});
// To check response string or parameters
 pm.expect(pm.response.text()).to.include("EmploymentStatus_ID");


pm.test("To Check Existancy of Fields"function () {
    pm.expect(jsonData.Result.user.UserName).exist
    pm.expect(jsonData.Result.Token).exist
    pm.expect(jsonData.Result.RefreshToken).exist
});

// To get collection variable
var c_Email = pm.collectionVariables.get("User_Email");

//To set collection variable
pm.collectionVariables.set("User_Token"User_Token);

// To validate affected rows
pm.test("Check Ptype>=3 && bed=3 && bath>2"function () {
    var jsonData = pm.response.json();
    var res = jsonData.RecordAffectted
    if (res > 0) {
        _.each(jsonData.Result, (item=> {
            var pType = item.Property_Type
            console.log(pType)
            pm.expect(pType).is.gte(3&&
                pm.expect(bed).is.eql(3&&
                pm.expect(bath).is.greaterThan(2)
        })
    } else {
        pm.expect.fail("No rows efefcted")
    }
})

// Check sorting order
pm.test("Check Sorting Order"function () {
    var res = jsonData.RecordAffectted
    if (res > 0) {
        _.each(jsonData.Result, (item=> {
            var expectedSortedOrder = lodash.orderBy(item, ['UserName'], ['desc']);
            pm.expect(item).to.eql(expectedSortedOrder);
        })
    } else {
        pm.expect.fail("No rows efefcted")
    }
})

// Validate error is null
pm.test("Validate Error should be Null"function () {
    _.each(jsonData.Errors, (item=> {
        var err = item
        console.log(err)
        pm.expect(err).to.equal("")
    })
})

pm.test("validate result should not be null", function(){

    var res = jsonData.Result

    if(res == '') {

         pm.expect.fail("Result is null")

    }

    else{

        pm.test("Result is not null")

    }

})

 

pm.test("Validate Error should be Null", function () {

    _.each(jsonData.Errors, (item) => {

        var err = item

        console.log(err)

        pm.expect(err).to.equal("")

    })

})

 

pm.test("Check affected records", function () {

    var res = jsonData.RecordAffectted

    if (res > 0) {

        pm.test("Affected Rows", res)

    } else {

        pm.expect.fail("No rows affected")

    }

})





 

Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

What is data driven testing?

How to handle frame window in selenium?

How to work with mouse hover menu in selenium?

How does Selenium Webdriver handle SSL certificate in Chrome?