Enterprise-grade automation framework with data-driven testing, comprehensive reporting, and intelligent logging
Features β’ Quick Start β’ Architecture β’ Documentation
A production-ready REST API automation testing framework built with industry best practices. This framework leverages the power of Java, TestNG, and Rest Assured to deliver robust, maintainable, and scalable API test automation with Excel-based data-driven testing and rich HTML reporting.
Perfect for QA Engineers, Test Automation Engineers, and Development Teams looking to implement comprehensive API testing strategies.
|
|
|
|
|
|
| Technology | Purpose | Version |
|---|---|---|
| β Java | Programming Language | 21 |
| π¦ Maven | Build & Dependency Management | Latest |
| π§ͺ TestNG | Test Runner & Assertions | Latest |
| π Rest Assured | REST API Testing | Latest |
| π Apache POI | Excel Data Management | Latest |
| π ExtentReports | HTML Test Reporting | Latest |
| π Log4j2 | Logging Framework | Latest |
| π Git | Version Control | Latest |
PetStoreAutomation/
β
βββ π src/
β βββ π test/
β βββ π java/
β β βββ π api/
β β βββ π endpoints/ # REST endpoints & routes
β β β βββ UserEndpoints.java
β β β βββ StoreEndpoints.java
β β β βββ PetEndpoints.java
β β β
β β βββ π payload/ # POJOs for request/response
β β β βββ User.java
β β β βββ Pet.java
β β β βββ Order.java
β β β
β β βββ π test/ # TestNG test classes
β β β βββ UserTests.java
β β β βββ PetTests.java
β β β βββ DDTests.java
β β β
β β βββ π utilities/ # Helper classes
β β βββ DataProviders.java
β β βββ ExcelUtility.java
β β βββ ExtentReportManager.java
β β βββ Endpoints.java
β β
β βββ π resources/
β βββ log4j2.xml # Logging configuration
β βββ routes.properties # API endpoint URLs
β
βββ π testData/ # Excel test data files
β βββ UserData.xlsx
β
βββ π reports/ # Generated ExtentReports
β βββ Test-Report-{timestamp}.html
β
βββ π logs/ # Application logs
β βββ automation.log
β
βββ π testng.xml # TestNG suite configuration
βββ π pom.xml # Maven dependencies & build
βββ π .gitignore # Git ignore rules
βββ π README.md # Project documentation
graph TB
A[TestNG Test Classes] --> B[Data Provider]
B --> C[Excel Utility]
C --> D[Test Data Excel]
A --> E[Endpoints Layer]
E --> F[Routes Properties]
E --> G[Rest Assured]
G --> H[API Server]
A --> I[ExtentReports]
A --> J[Log4j2]
style A fill:#4ade80
style H fill:#3b82f6
style I fill:#f59e0b
style J fill:#a855f7
Before you begin, ensure you have the following installed:
| Requirement | Version | Installation |
|---|---|---|
| β Java JDK | 21+ | Download |
| π¦ Maven | 3.8+ | Download |
| π» IDE | Any | IntelliJ IDEA / Eclipse / VS Code |
| π Git | Latest | Download |
Step 1οΈβ£: Clone the Repository
git clone https://github.com/mvsaran/RestAPI-Automation-TestNG-Framework.git
cd RestAPI-Automation-TestNG-FrameworkStep 2οΈβ£: Install Dependencies
mvn clean installStep 3οΈβ£: Verify Setup
mvn test -Dtest=UserTestsmvn clean testmvn test -DsuiteXmlFile=testng.xmlmvn test -Dtest=UserTestsmvn test -Dparallel=methods -DthreadCount=4mvn test -DreportName="API-Test-Report"After test execution, detailed HTML reports are generated in the reports/ directory.
Features:
- β Pass/Fail/Skip statistics
- πΈ Request/Response details
- β±οΈ Execution time tracking
- π¨ Beautiful dashboard view
- π Test case details with logs
Viewing Reports:
# Navigate to reports directory
cd reports/
# Open the latest report
open Test-Report-{timestamp}.html # macOS
start Test-Report-{timestamp}.html # Windows
xdg-open Test-Report-{timestamp}.html # LinuxDetailed execution logs are available in logs/automation.log
Log Levels:
- π΄ ERROR - Critical issues
- π WARN - Warning messages
- π΅ INFO - General information
- π’ DEBUG - Detailed debugging info
Click to expand pom.xml dependencies
<dependencies>
<!-- Rest Assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.0</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
</dependency>
<!-- Apache POI for Excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<!-- ExtentReports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
<!-- Log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<!-- JSON Processing -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>Configure your API endpoints in src/test/resources/routes.properties:
# Base URL
base_url=https://petstore.swagger.io/v2
# User Module Endpoints
post_url=/user
get_url=/user/{username}
update_url=/user/{username}
delete_url=/user/{username}
# Store Module Endpoints
store_post_url=/store/order
store_get_url=/store/order/{orderId}
# Pet Module Endpoints
pet_post_url=/pet
pet_get_url=/pet/{petId}
pet_update_url=/pet/{petId}Customize logging behavior in src/test/resources/log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="File" fileName="logs/automation.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>Handles all API endpoint logic with Rest Assured:
public class UserEndpoints {
public static Response createUser(User payload) {
return given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(payload)
.when()
.post(Routes.post_url);
}
public static Response getUser(String userName) {
return given()
.pathParam("username", userName)
.when()
.get(Routes.get_url);
}
}Define request/response structures:
public class User {
private int id;
private String username;
private String firstName;
private String lastName;
private String email;
private String password;
private String phone;
// Getters and Setters
}Excel-based data-driven testing:
@DataProvider(name = "UserData")
public Object[][] getAllData() throws IOException {
String path = System.getProperty("user.dir") + "//testData//UserData.xlsx";
XLUtility xl = new XLUtility(path);
int rownum = xl.getRowCount("Sheet1");
int colcount = xl.getCellCount("Sheet1", 1);
Object[][] apidata = new Object[rownum][colcount];
for (int i = 1; i <= rownum; i++) {
for (int j = 0; j < colcount; j++) {
apidata[i-1][j] = xl.getCellData("Sheet1", i, j);
}
}
return apidata;
}TestNG test implementation:
public class UserTests {
@Test(priority = 1, dataProvider = "UserData", dataProviderClass = DataProviders.class)
public void testPostUser(String userID, String userName, String fname, String lname,
String email, String pwd, String ph) {
User userPayload = new User();
userPayload.setId(Integer.parseInt(userID));
userPayload.setUsername(userName);
userPayload.setFirstName(fname);
userPayload.setLastName(lname);
userPayload.setEmail(email);
userPayload.setPassword(pwd);
userPayload.setPhone(ph);
Response response = UserEndpoints.createUser(userPayload);
Assert.assertEquals(response.getStatusCode(), 200);
logger.info("User created successfully");
}
}| Practice | Implementation |
|---|---|
| ποΈ Separation of Concerns | Endpoints, Payloads, Tests, Utilities separated |
| π¦ DRY Principle | Reusable methods and utilities |
| π Encapsulation | Private fields with getters/setters |
| π Documentation | Comprehensive inline comments |
| π§ͺ Test Independence | Each test can run standalone |
| π Maintainability | Properties-based configuration |
| π Reporting | Detailed logs and HTML reports |
| π― Assertions | Proper validation at each step |
Common Issues & Solutions
Solution:
mvn clean install -USolution:
- Verify
testng.xmlconfiguration - Check if test classes are in correct package
- Ensure @Test annotations are present
Solution:
- Verify file path in DataProviders class
- Ensure Excel file is in
testData/directory - Check file name spelling
Solution:
- Check ExtentReports configuration
- Verify
reports/directory exists - Ensure proper file permissions
Sample workflow configuration
name: API Test Automation
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 2 * * *' # Daily at 2 AM
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Build with Maven
run: mvn clean install -DskipTests
- name: Run Tests
run: mvn test
- name: Upload Test Reports
uses: actions/upload-artifact@v3
if: always()
with:
name: test-reports
path: reports/Contributions are always welcome! Here's how you can help:
- π΄ Fork the repository
- πΏ Create your feature branch (
git checkout -b feature/AmazingFeature) - β¨ Commit your changes (
git commit -m 'Add some AmazingFeature') - π€ Push to the branch (
git push origin feature/AmazingFeature) - π Open a Pull Request
- Write clear commit messages
- Follow existing code style
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
| Channel | Link |
|---|---|
| π Report Bug | Create Issue |
| π‘ Request Feature | Create Issue |
| π§ Email | your.email@example.com |
| πΌ LinkedIn | Your Profile |
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 REST API Automation Framework
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
- π Rest Assured - For making API testing simple and elegant
- π§ͺ TestNG - For powerful test management capabilities
- π Apache POI - For seamless Excel integration
- π ExtentReports - For beautiful test reports
- π Log4j2 - For robust logging framework
- π₯ Open Source Community - For continuous inspiration
- π Add support for GraphQL APIs
- π Implement OAuth 2.0 authentication
- π³ Docker containerization
- βοΈ Cloud deployment support (AWS/Azure)
- π± Add API performance testing
- π€ AI-powered test generation
- π Advanced analytics dashboard
- π Swagger integration
Made with β€οΈ by Test Automation Engineers
Happy Testing! π