API Testing using POSTMAN (Manual Testing)

We can use POSTMAN for REST API Testing
We can either download POSTMAN or Google chrome Add-ons

Pre Requisite Before Start To API Testing
1)POSTMAN
2)API URI
3)Payload for request

HTTP Requests methods require for API Testing using Postman
Create a record (POST)
Retrive/Verify Data (GET)
Update record (PUT)
Delete record (DELETE)


Domain :-https://www.google.com/
URI:- /search?source=hp&ei=NgQcXqDyNKfTz7sPpduz2Aw&q=selnium


EndPoint require for API Testing

Ex.
http://restapi.demoqa.com/utilities/weather/city/

Complete URI:-
http://restapi.demoqa.com/utilities/weather/city/Paris

Request Payload require for POST method
{

"FirstyName" : "Vaibhav",
"lastName" : "Khachane",
"UserName" :"tester",
"Password" : tester@123
"Email" :"test@gmail.com"

}

We should observe following things while doing API Testing manually
1)Response Body
2)Cookies
3)Header
4)Status Code

Practice API :
https://reqres.in/
https://restcountries.eu/
https://openweathermap.org/current

API Testing Validation

Reference API:-http://restapi.demoqa.com/utilities/weather/city/Paris

Step 1: Launch POSTMAN Tool
Step 2: Select GET Method and Enter API ex. "http://restapi.demoqa.com/utilities/weather/city/Paris"
Step 3: Click on SEND Button
Step 4: Verify Response Output Manually.

Now Add Verification Points 

Step 5: Go to the "Test"
Step 6: Click on "Response headers:content-Type header check"
, It will add code example. 
                         pm.test("Content-Type is present", function () {
                         pm.response.to.have.header("Content-Type");
                         });
Step 7: Modify Code as per our requirement. example 
                        pm.test("Content-Type is present", function () {
                        pm.response.to.have.header("Content-Type");
                       });

Above Test Case will check content-Type

We can write test cases for other scenarios also

TC: To verify Status code
                       pm.test("Status code is 200", function () {
                       pm.response.to.have.status(200);
                       });

TC: To verify response time
                      pm.test("Response time is less than 200ms", function () {
                      pm.expect(pm.response.responseTime).to.be.below(1000);
                      });

TC  : To verify response Objects
                     tests["City id is correct"]=responseBody.has("City");
                     tests["Temperature id is correct"]=responseBody.has("Temperature");
                     tests["Humidity id is correct"]=responseBody.has("Humidity");
                     tests["WeatherDescription id is correct"]=responseBody.has("WeatherDescription");
                     tests["WindSpeed id is correct"]=responseBody.has("WindSpeed");
                     tests["WindDirectionDegree id is correct"]=responseBody.has("WindDirectionDegree");

TC : To verify Response Values

                     pm.test("City Name is Correct", function () {
                     var jsonData = pm.response.json();
                     pm.expect(jsonData.City).to.eql("Paris");
                     console.log("I am getting this value from API ",jsonData.City);
                     });

                    pm.test("Temperature value is correct", function () {
                    var jsonData = pm.response.json();
                    pm.expect(jsonData.Temperature).to.eql("9.51 Degree celsius");
                    console.log("I am getting this value from API ",jsonData.Temperature);
                    });

                    pm.test("Humidity value is correct", function () {
                    var jsonData = pm.response.json();
                    pm.expect(jsonData.Humidity).to.eql("70 Percent");
                    console.log("I am getting this value from API ",jsonData.Humidity);
                    });

                    pm.test("WeatherDescription value is correct", function () {
                    var jsonData = pm.response.json();
                    pm.expect(jsonData.WeatherDescription).to.eql("broken clouds");
                    console.log("I am getting this value from API ",jsonData.WeatherDescription);
                    });

                   pm.test("WindSpeed value is correct", function () {
                   var jsonData = pm.response.json();
                   pm.expect(jsonData.WindSpeed).to.eql("8.7 Km per hour");
                   console.log("I am getting this value from API ",jsonData.WindSpeed);
                   });
  
  
                   pm.test("WindDirectionDegree value is correct", function () {
                   var jsonData = pm.response.json();
                   pm.expect(jsonData.WindDirectionDegree).to.eql("210 Degree");
                   console.log("I am getting this value from API ",jsonData.WindDirectionDegree);
                   });

We can view API return values on POSTMAN console . Following are steps
1)Go to view-> Show Postamn console

following line will help to fetch value on console
console.log("I am getting this value from API ",jsonData.City);
TC : To verify Schema use tiny validator for JSON data Use This Link to generate schema 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; }); GUI for Test Result
POSTMAN Tool GUI
                        NOTE:- REST API support JSON format . It is also support XML , Text, HTML format. SOAP only support XML format.