Naukri API Testing Framework

0.00 avg. rating (0% score) - 0 votes

Framework is like blueprint for test automation. A good automation framework design helps in achieving more reusable, scalable, beneficial testing and reduce maintenance cost.

Automation test framework provides environment for structured automated testing which includes test scripts writing with the help of reusable functions, test data generation and reporting.

In case of API automation, framework become more challenging because of following tasks

  • Handling JSON/XML based request or response parameter/body.
  • Handling connection with API with different HTTP method.
  • Validating API response data with expected data.

We finalized our framework approach with Java + POJO model + GSON library + jsonschema2pojo library. We wrote a library using java.net that simplified the way we connect with the API. GSON and jsonschema2pojo library help us in setting or extracting data from request or response body.

The flow diagram below will further explain the flow of our API automation framework

api-automation-framework

Handling JSON/XML based request or response parameter/body

The framework uses jsonschema2pojo library for generating POJO(Plain Old Java Object)  classes dynamically from JSON file. It generates the POJO class for request and response JSON structure based on sample JSON file kept inside a directory.

 Code Sample:

 generate-pojo

For example:

example

The POJO class is generated automatically using  jsonschema2pojo library which will be used further to get and set data in request and response.

Handling connection with API with different HTTP method

We wrote a library APIFunctions for handling HTTP connection with API using java.net library. APIFunctions class has method corresponding to HTTP methods which will be used for making connection with the API.

api-library

APIFunctions library provide supports for making a request to API and return a Response object as an output. Response object will have the following information within it.

response-class

Validating API response data with expected data (i.e TestCases)

So with the help of APIFunctions library, writing API automation test case is very simple and easy now. In test script, we will pick data from excel file or any other source and set it on POJO classes. The GSON library will then transform the POJO class into request string and  API request is sent using the APIFunctions library methods. In return we will get a Response object from library that will have all the response details in it.

api-testcase

 

One thought on “Naukri API Testing Framework

Comments are closed.