api-automation-tutorial
api-automation-tutorial copied to clipboard
Learn how to automate REST API's in Java using RESTAssured library
API Automation Tutorial
In this tutorial you are going to learn How to Automate the REST API's in Java using RESTAssured Library
The tech stack used for this tutorial are:
- JAVA as the programming language for writing test code
- TestNg as the framework
- Gradle as the build tool
- IntelliJ as the preferred IDE for writing java code.
Getting Started
Setup your machine.
- Install JDK 1.8
- Install IntelliJ (Community edition is fine)
- Install Gradle
Cloning & Importing the Project
- Clone the project from
git clone https://github.com/vinaykumarvvs/api-automation-tutorial.git
- Import the project (api-automation-tutorial) in IntelliJ
File -> New -> Project from Existing Sources -> Browse Project Location -> build.gradle
- Now click on
auto import -> Ok
wait until the IntelliJ downloads all the dependencies
Running tests
Note:
For 2nd & 3rd steps, you need to follow this way OpenTerminal/CMD -> cd <change-to-project-location>
- You can run the tests directly from the IntelliJ, by right-clicking and Run test.
- For Linux/Mac users:
gradle clean build runTests
orgradle clean build test
- For Windows users:
gradlew clean build runTests
orgradlew clean build test
Tutorial Begins
PetStore - Swagger
Throughout this tutorial, I am going to use PetStore-Swagger. PetStore - Swagger is the open source project which has very good documentation with the various number of examples.
Chapter 1 :: Send a GET Request and validate the Response
- Test-1: Send a get Request of an API and validate the body
- Test-2: Send a get Request of an API by passing the Query Parameters in the URL itself
- Test-3: Send a get Request of an API and retrieve the data from the body
- Test-4: Send a get Request of an API and store the Response
Chapter 2 :: Abstracting the code
- Test-1: Abstracting the Requests for maintenance and readability
Chapter 3 :: POST Request creation and validating the Response Code
- Test-1: Creating the POST Request and validating the Response Code
Chapter 4 :: POST Request creation and validating RequestBody & ResponseBody
- Test-1: Creating the POST Request and validating the RequestBody & ResponseBody
Chapter 5 :: Chaining the API's
- Test-1: Chaining Requests and validate Response Body