Skip to content

writetoprabha/APIAutomation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Automation

Dependencies used:

  • RestAssured api - for invoking webservices and validate responses
  • Apachi POI api - for data driven testing
  • Json simple api - for parsing the json responses
  • TestNG - to execute tests

  • To invoke a REST service with Java:

    1. Set the baseURI property of the RESTASSURED static class
      Example:
      RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city";
    2. Create the RequestSpecification object and assign it with RestAssured.Given() method.
      Example:
      RequestSpecification httpRequest = ResetAssured.Given();
    3. Create the Response object and assign it with requestSpecificationObject.request() method
      Example:
      Response response = httpRequest.Request(METHOD.GET, "/Hyderabad");
      Note: "/Hyderabad" is the parameter passed in GET request
    4. The Response of the request invoked can be accessed using the response object
      Example:
      System.out.println(response.getResponseBody());

    Notes:

  • For POST requests, we need to add the payload and header as below:

    JSONObject requestPayload = new JSONObject();
    requestPayload.put("FirstName", firstName);
    requestPayload.put("LastName", lastName);
    requestPayload.put("UserName", userName);
    requestPayload.put("Password", password);
    requestPayload.put("Email", emailId);

    httpRequest.header("Content-Type", "application/json");
    httpRequest.body(requestPayload.toJSONString());

  • About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

     
     
     

    Contributors

    Languages