This project demonstrates end-to-end API automation testing using Java, RestAssured, and TestNG. It covers real-world e-commerce scenarios such as authentication, cart operations, order creation, and deletion.
The framework showcases:
- API chaining
- Dynamic payload generation
- Response validation
- TestNG-based execution control
- Java
- RestAssured
- TestNG
- Maven
- JSON (JsonPath parsing)
src
└── test
└── java
└── com.rahulshettyacademy
├── tests
│ ├── loginTest.java
│ ├── getAllProductsTest.java
│ ├── productsAddedtoCartTest.java
│ ├── getCartProductsTest.java
│ ├── CreateOrderTest.java
│ └── deleteOrdersTest.java
│
└── utils
└── BaseTest.java
testng.xml
pom.xml
- 🔐 Login → Generate authentication token
- 📦 Fetch all products
- ➕ Add products to cart
- 🛒 Fetch cart products
- 🧾 Create order using cart product IDs
- ❌ Delete created orders
Data is passed between APIs:
productId → orderId
for (String productId : UserCartProductsId) {
Map<String, String> orderMap = new HashMap<>();
orderMap.put("country", "India");
orderMap.put("productOrderedId", productId);
}- Status code validation
- Message validation
- Data integrity checks
Assert.assertEquals(message, "Order Placed Successfully");Centralized setup for:
- Base URI
- Authentication token
- Shared response handling
dependsOnGroupsdependsOnMethods- Ordered execution via
testng.xml
git clone https://github.com/teche74/Api-Testing-using-RestAssured-and-Java.git
mvn clean install
mvn test
Or run directly via:
testng.xml
response = RestAssured.given()
.header("Authorization", token)
.contentType("application/json")
.body(finalPayload)
.when()
.post("/api/ecom/order/create-order")
.then()
.extract()
.response();- ✔ Status Code Validation
- ✔ Response Body Validation
- ✔ JSON Path Extraction
- ✔ Data Matching (Cart → Order)
Ujjwal Bisht
This project demonstrates the transition from:
❌ Static API testing ➡️ ✅ Dynamic, chained API automation framework