Skip to content

REST API automation framework using Cucumber, Apache Http Client

License

Notifications You must be signed in to change notification settings

shilesh-r/restapi-cucumber-httpclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restapi-cucumber-httpclient

REST API automation framework using Cucumber, Apache Http Client

Project Description

This project is to implement a framework for REST API automation tests with Cucumber and Apache Http Client for sample ReqRes APIs. Project was developed using:

  1. Cucumber - 6.10.4 - latest version
  2. Apache Http Components - Http Client - 4.5.13 - latest version
  3. Lombok - annotations and clean code
  4. Jackson Core Databind - Object Mapper - to serialize objects to json and to deserialize json to objects

Note: RestAssured, the widely used testing library for API automation is a wrapper built on Apache Http Client

Design

POJO Classes:

  1. To enable easy test creation and maintenance, the request and response json fields are modeled as POJO classes
  2. Use of Lombok annotations helps simplify the creation of classes as only the fields need to be declared
  3. Request: To create request JSON, it is sufficient to create object(s) for the corresponding request model classes and set values according to the tests. Then Object Mapper (Jackson - databind) can be used to serialize the object(s) to json before submitting API calls
  4. Response: To enable ease of access and parsing response JSON, object mapper can parse the response JSON string as object(s) of response model classes
  5. POJO classes can be found at src/test/java/com/automation/demo/models package

Acceptance Tests:

  1. Acceptance Tests written as Cucumber feature file can be found at src/test/resources/features/ReqResApiTests.feature
  2. The tests perform a Get and Post call to APIs hosted at https://reqres.in/

Assertions:

  1. JUnit assertion methods are used to verify response JSON data

Prerequisites to Run the project

  1. Environment Requirements: Maven v3.5.4 or later, Java 1.8 or later, Eclipse or IntelliJ IDE

Execution Instructions

  1. After cloning the project, compile using the IDE Maven plugin or mvn clean compile
  2. Review the code to understand the flow
  3. src/test/java - has the code for Cucumber tests implementation
  4. src/test/resources - has the feature file

Command Line:

mvn clean test - This will run the scenarios in Cucumber feature files

Run Configuration:

Alternative way to run the project is by use of: TestRunner at src/test/java/com/automation/demo/TestRunner.java or Using IDE Run configuration, for IntelliJ:

  1. Right click project and click Run as
  2. Select Maven Build
  3. Enter goals - clean test
  4. Click Run

Reports Location:

After execution, reports can be accessible via the link displayed in the maven logs (provided by Cucumber latest version).

When this project is integrated in a Jenkins pipeline, cucumber.json file in target/cucumber-reports can be integrated in the Build using Jenkins Cucumber plugin

About

REST API automation framework using Cucumber, Apache Http Client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published