Skip to content

About

A robust REST API automation framework built with Java, TestNG, Maven, and REST-assured. Features include Data-Driven Testing with Excel, ExtentReports for reporting, log4j2 logging, and properties file management for configurable endpoints.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ REST API Automation TestNG Framework

Java Maven TestNG Rest Assured Apache POI

🎯 Robust & Scalable REST API Testing Framework

Enterprise-grade automation framework with data-driven testing, comprehensive reporting, and intelligent logging

Features β€’ Quick Start β€’ Architecture β€’ Documentation


Build Status Coverage License Maintained


πŸ“– Overview

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.


✨ Features

πŸ” Data-Driven Testing

  • Excel-based test data management
  • Apache POI integration
  • Dynamic data providers
  • Easy test data maintenance

πŸ“Š Rich Reporting

  • ExtentReports HTML dashboards
  • Detailed test execution logs
  • Screenshot attachments
  • Pass/Fail statistics

πŸ”§ Configuration Management

  • Properties-based endpoints
  • Environment-specific configs
  • Centralized settings
  • Easy deployment

🎯 TestNG Integration

  • Parallel test execution
  • Test suite management
  • Flexible assertions
  • Dependency handling

πŸ“ Intelligent Logging

  • Log4j2 implementation
  • Multiple log levels
  • Rotating file appenders
  • Debug-friendly output

πŸ—οΈ Modular Architecture

  • Page Object Model (POM)
  • Reusable components
  • SOLID principles
  • Easy scalability

πŸ”§ Tech Stack & Tools

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

πŸ“ Project Structure

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

🎯 Framework Architecture

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
Loading

πŸš€ Getting Started

πŸ“‹ Prerequisites

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

⚑ Installation

Step 1️⃣: Clone the Repository

git clone https://github.com/mvsaran/RestAPI-Automation-TestNG-Framework.git
cd RestAPI-Automation-TestNG-Framework

Step 2️⃣: Install Dependencies

mvn clean install

Step 3️⃣: Verify Setup

mvn test -Dtest=UserTests

πŸ§ͺ Running Tests

▢️ Run All Tests

mvn clean test

🎯 Run Specific Test Suite

mvn test -DsuiteXmlFile=testng.xml

πŸ” Run Specific Test Class

mvn test -Dtest=UserTests

πŸ”€ Run Tests in Parallel

mvn test -Dparallel=methods -DthreadCount=4

πŸ“Š Run with Custom Report Name

mvn test -DreportName="API-Test-Report"

πŸ“Š Test Reports

πŸ“ˆ ExtentReports

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 # Linux

πŸ“ Log Files

Detailed execution logs are available in logs/automation.log

Log Levels:

  • πŸ”΄ ERROR - Critical issues
  • 🟠 WARN - Warning messages
  • πŸ”΅ INFO - General information
  • 🟒 DEBUG - Detailed debugging info

πŸ“¦ Maven Dependencies

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>

πŸ” Configuration

πŸ“„ routes.properties

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}

πŸ”§ log4j2.xml

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>

πŸ“š Framework Components

🎯 Endpoints Layer

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);
    }
}

πŸ“¦ Payload Classes (POJOs)

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
}

πŸ“Š Data Providers

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;
}

πŸ§ͺ Test Classes

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");
    }
}

🎨 Best Practices Implemented

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

πŸ› Troubleshooting

Common Issues & Solutions

Issue: Maven build fails

Solution:

mvn clean install -U

Issue: Tests not executing

Solution:

  • Verify testng.xml configuration
  • Check if test classes are in correct package
  • Ensure @Test annotations are present

Issue: Excel file not found

Solution:

  • Verify file path in DataProviders class
  • Ensure Excel file is in testData/ directory
  • Check file name spelling

Issue: Reports not generating

Solution:

  • Check ExtentReports configuration
  • Verify reports/ directory exists
  • Ensure proper file permissions

πŸ“ˆ Continuous Integration

πŸ”„ GitHub Actions

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/

🀝 Contributing

Contributions are always welcome! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create your feature branch (git checkout -b feature/AmazingFeature)
  3. ✨ Commit your changes (git commit -m 'Add some AmazingFeature')
  4. πŸ“€ Push to the branch (git push origin feature/AmazingFeature)
  5. πŸŽ‰ Open a Pull Request

πŸ“ Contribution Guidelines

  • Write clear commit messages
  • Follow existing code style
  • Add tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PR

πŸ“ž Support & Contact

Channel Link
πŸ› Report Bug Create Issue
πŸ’‘ Request Feature Create Issue
πŸ“§ Email your.email@example.com
πŸ’Ό LinkedIn Your Profile

πŸ“„ License

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...

πŸ™ Acknowledgments

  • 🌐 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

πŸ“Š Project Statistics

GitHub stars GitHub forks GitHub watchers

GitHub last commit GitHub issues GitHub pull requests


πŸ—ΊοΈ Roadmap

  • πŸ”„ 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

⭐ If you find this project helpful, please give it a star!

Made with ❀️ by Test Automation Engineers

⬆ Back to Top


Happy Testing! πŸš€

About

A robust REST API automation framework built with Java, TestNG, Maven, and REST-assured. Features include Data-Driven Testing with Excel, ExtentReports for reporting, log4j2 logging, and properties file management for configurable endpoints.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages