Skip to content

avdhutssh/UI-API_Automation_Selenium_RestAssured

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UI & API Test Automation Framework Using Selenium & RestAssured

Table of Contents

Introduction

This repository contains a comprehensive test automation framework for the E-commerce application, combining both UI (Selenium) and API (REST Assured) testing capabilities. The framework is built using Java and Maven, designed to automate end-to-end test scenarios for the e-commerce platform

The framework follows industry best practices such as:

  • Page Object Model (POM) for UI test maintainability
  • Modular API architecture with REST Assured
  • Object-oriented design principles (SOLID)
  • Factory and Builder patterns for request/response specifications
  • Data-driven testing with CSV and JSON support
  • Parallel test execution using TestNG
  • Comprehensive reporting with Allure Reports
  • Enhanced logging with Log4J2
  • CI/CD ready with multiple test suites
  • Retry mechanism for handling flaky tests
  • Soft assertions for better test coverage

Prerequisites

Before you start, ensure you have the following installed on your machine:

  • Java Development Kit (JDK): Version 17 or later
  • Maven: To manage project dependencies
  • Git: To clone the repository
  • Chrome Browser: Primary browser for UI testing (or configure other browsers)
  • An IDE: (such as IntelliJ IDEA or Eclipse) with TestNG, Lombok plugins installed

For CI/CD:

  • Jenkins: For automated build and test execution
  • GitHub Actions: Integrated for CI pipeline

Project Structure

This framework follows a hybrid approach combining UI and API testing with modular architecture. The structure is designed for maintainability, scalability, and follows SOLID principles:

UI-API_Automation_Selenium_RestAssured/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com/
β”‚   β”‚   β”‚       └── ecom/
β”‚   β”‚   β”‚           └── app/
β”‚   β”‚   β”‚               β”œβ”€β”€ constants/                    # API endpoints and HTTP status codes
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ Endpoints.java           # REST API endpoint constants
β”‚   β”‚   β”‚               β”‚   └── StatusCode.java          # HTTP status code constants
β”‚   β”‚   β”‚               β”œβ”€β”€ PageObjects/                 # Page Object Model classes
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ CartPage.java            # Shopping cart page interactions
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ CheckoutPage.java        # Checkout process page
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ LoginPage.java           # Login page interactions
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ OrderConfirmationPage.java # Order confirmation handling
β”‚   β”‚   β”‚               β”‚   └── ProductPage.java         # Product listing and details
β”‚   β”‚   β”‚               β”œβ”€β”€ pojo/                        # Plain Old Java Objects for API data models
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ auth/                    # Authentication related models
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ LoginRequest.java    # Login request payload
β”‚   β”‚   β”‚               β”‚   β”‚   └── LoginResponse.java   # Login response model
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ common/                  # Common API models
β”‚   β”‚   β”‚               β”‚   β”‚   └── ErrorResponse.java   # Error response structure
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ order/                   # Order management models
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ OrderDetails.java    # Order details structure
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ OrderHistoryResponse.java # Order history response
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ OrderRequest.java    # Order creation request
β”‚   β”‚   β”‚               β”‚   β”‚   └── OrderResponse.java   # Order creation response
β”‚   β”‚   β”‚               β”‚   └── product/                 # Product related models
β”‚   β”‚   β”‚               β”‚       β”œβ”€β”€ Product.java         # Product information model
β”‚   β”‚   β”‚               β”‚       └── ProductsResponse.java # Products listing response
β”‚   β”‚   β”‚               └── Utilities/                   # Core utility classes
β”‚   β”‚   β”‚                   β”œβ”€β”€ BasePage.java            # Base page class with common wait functions
β”‚   β”‚   β”‚                   β”œβ”€β”€ BrowserDriverFactory.java # Multi-browser driver management
β”‚   β”‚   β”‚                   β”œβ”€β”€ ConfigurationUtils.java  # Configuration file handling
β”‚   β”‚   β”‚                   β”œβ”€β”€ CsvDataProviders.java    # CSV data provider utilities
β”‚   β”‚   β”‚                   β”œβ”€β”€ ElementUtils.java        # Web element interaction utilities
β”‚   β”‚   β”‚                   β”œβ”€β”€ JSONDataReader.java      # JSON test data reader
β”‚   β”‚   β”‚                   └── ScreenshotUtils.java     # Screenshot capture utilities
β”‚   β”‚   └── resources/
β”‚   β”‚       β”œβ”€β”€ config.properties                        # Application configuration
β”‚   β”‚       └── log4J2.xml                              # Logging configuration
β”‚   └── test/
β”‚       β”œβ”€β”€ java/
β”‚       β”‚   └── com/
β”‚       β”‚       └── ecom/
β”‚       β”‚           └── app/
β”‚       β”‚               β”œβ”€β”€ BaseComponents/              # Base test infrastructure
β”‚       β”‚               β”‚   β”œβ”€β”€ BaseTest.java           # Base test class with setup/teardown
β”‚       β”‚               β”‚   β”œβ”€β”€ RetryTestListener.java  # Test retry mechanism
β”‚       β”‚               β”‚   └── TestListener.java       # Custom TestNG listener
β”‚       β”‚               β”œβ”€β”€ generic/                    # API testing core components
β”‚       β”‚               β”‚   β”œβ”€β”€ RequestFactory.java     # Factory for API request creation
β”‚       β”‚               β”‚   └── RestClient.java         # REST client wrapper for RestAssured
β”‚       β”‚               β”œβ”€β”€ specs/                      # Request/Response specifications
β”‚       β”‚               β”‚   β”œβ”€β”€ RequestSpecificationBuilder.java  # Request spec builder
β”‚       β”‚               β”‚   └── ResponseSpecificationBuilder.java # Response spec builder
β”‚       β”‚               β”œβ”€β”€ Tests/                      # Test case classes
β”‚       β”‚               β”‚   β”œβ”€β”€ _01_Login_Tests.java    # Login functionality tests
β”‚       β”‚               β”‚   β”œβ”€β”€ _02_Product_Tests.java  # Product related tests
β”‚       β”‚               β”‚   β”œβ”€β”€ _03_Cart_Tests.java     # Shopping cart tests
β”‚       β”‚               β”‚   └── _04_E2E_Tests.java      # End-to-end scenario tests
β”‚       β”‚               β”œβ”€β”€ utils/                      # Test utilities
β”‚       β”‚               β”‚   β”œβ”€β”€ AllureReportUtils.java  # Allure reporting utilities
β”‚       β”‚               β”‚   β”œβ”€β”€ AllureRestAssuredFilter.java # API request/response capture
β”‚       β”‚               β”‚   └── AssertionUtils.java     # Custom assertion utilities
β”‚       β”‚               └── standAloneScripts.java      # Independent test scripts
β”‚       └── resources/
β”‚           β”œβ”€β”€ allure.properties                       # Allure reporting configuration
β”‚           β”œβ”€β”€ TestData/                              # Test data files
β”‚           β”‚   β”œβ”€β”€ _01_Login_Tests/                   # Login test specific data
β”‚           β”‚   β”‚   └── test_03_API_verifyMultipleInvalidLoginAttempts.csv
β”‚           β”‚   β”œβ”€β”€ loginTestData.json                 # JSON login test data
β”‚           β”‚   β”œβ”€β”€ standAloneScripts/                 # Standalone script data
β”‚           β”‚   β”‚   └── test_03_API_verifyMultipleInvalidLoginAttempts.csv
β”‚           β”‚   └── testdata.json                      # General test data
β”‚           └── TestSuites/                            # TestNG suite configurations
β”‚               β”œβ”€β”€ SmokeSuite.xml                     # Smoke test suite
β”‚               β”œβ”€β”€ RegressionSuite.xml                # Regression test suite
β”‚               └── WholeSuite.xml                     # Complete test suite
β”œβ”€β”€ screenshots/                                        # Runtime screenshot storage
β”œβ”€β”€ target/                                            # Maven build output
β”œβ”€β”€ pom.xml                                            # Maven project configuration

Technologies Used

  • Java - Programming language
  • Selenium - Web automation
  • TestNG - Test framework
  • REST Assured - API testing
  • Allure - Reporting
  • Maven - Build tool
  • Jackson - JSON processing
  • Log4J2 - Logging framework

Getting Started

  1. Clone the repository:
git clone https://github.com/avdhutssh/UI-API_Automation_Selenium_RestAssured.git
  1. Navigate to the project directory:
cd UI-API_Automation_Selenium_RestAssured
  1. Install dependencies:
mvn clean install

This will download all required dependencies including Selenium, REST Assured, TestNG, Allure Reports, and Log4J2.

Test Execution

Run All Tests (Default - Smoke Suite)

mvn clean test

Run Specific Test Suite

# Smoke Tests (7 tests)
mvn clean test -Psmoke allure:serve

# Regression Tests (14 tests)  
mvn clean test -Pregression allure:serve

# All Tests (21 tests)
mvn clean test -Pall-tests allure:serve

Run Tests with Browser Selection

# Chrome browser (default)
mvn clean test -Dbrowser=chrome

# Headless mode
mvn clean test -Dheadless=true

Test Suites

The framework includes multiple pre-configured test suites:

1. Smoke Suite (SmokeSuite.xml) - 7 Tests

Critical functionality validation:

  • User login/logout validation
  • Invalid login handling
  • Product search functionality
  • Basic cart operations
  • Cart clearing functionality
  • Complete E2E order flow
  • API order history verification

2. Regression Suite (RegressionSuite.xml) - 14 Tests

Comprehensive feature testing:

  • Extended login scenarios with CSV data
  • Multiple product interactions
  • Advanced cart management
  • Detailed UI validations
  • API integration testing
  • Error handling scenarios

3. Whole Suite (WholeSuite.xml) - 21 Tests

Complete test coverage:

  • All smoke tests
  • All regression tests
  • Full UI and API integration
  • End-to-end workflows

Data-Driven Testing

The framework supports multiple data-driven testing approaches:

CSV Data Providers

Example usage in test methods:

@Test(dataProvider = "csvFileReader", dataProviderClass = CsvDataProviders.class)
public void test_03_API_verifyMultipleInvalidLoginAttempts(Map<String, String> testData) {
    String email = testData.get("email");
    String password = testData.get("password");
    String expectedMessage = testData.get("expectedMessage");
    
    // Test implementation
    LoginResponse response = getRequestFactory().login(email, password);
    AssertionUtils.assertEquals(response.getMessage(), expectedMessage);
}

JSON Data Support

// Reading JSON test data
JSONDataReader jsonReader = new JSONDataReader();
Map<String, Object> testData = jsonReader.getTestData("loginTestData.json");

Dynamic Test Data

// Using configuration-driven test data
String productName = ConfigurationUtils.getProperty("productName");
String countryName = ConfigurationUtils.getProperty("countryName");

Framework Features

1. Enhanced REST Assured Architecture

  • RestClient: Generic HTTP operations with logging and Allure integration
  • RequestFactory: E-commerce specific API operations
  • Specification Builders: Reusable request/response specifications
  • AllureRestAssuredFilter: Automatic API request/response capture

2. Robust UI Automation

  • Page Object Model: Clean separation of test logic and UI elements
  • ElementUtils: Common web element operations with explicit waits
  • BasePage: Shared functionality across all page objects
  • Multi-browser support: Chrome, Firefox, Edge with configurable options

3. Advanced Test Management

  • BaseTest: Comprehensive setup with UI and API components
  • TestListener: Custom TestNG listener with screenshot capture
  • RetryListener: Automatic retry mechanism for flaky tests
  • Soft Assertions: Continue execution after assertion failures

4. Intelligent Reporting

  • AllureReportUtils: Enhanced step logging and test data attachment
  • Screenshot Integration: Automatic capture on failures
  • API Documentation: Request/Response logging with formatting
  • Test Categorization: Epic, Feature, Story annotations

5. Data Management

  • Multiple Data Sources: CSV, JSON, Properties files
  • Configuration Management: Environment-specific settings
  • Test Data Isolation: Separate data files per test class
  • Dynamic Data Generation: Runtime test data creation

Reporting

Allure Reports (Primary)

Generate and view comprehensive Allure reports:

# Clean previous results and generate fresh report
mvn clean test allure:serve

# Generate report without serving
mvn clean test allure:report

Allure Report Features:

  • Test execution timeline
  • Step-by-step test breakdown
  • Request/Response details for API tests
  • Screenshots for UI test failures
  • Test categorization with @Epic, @Feature, @Story
  • Retry information and failure analysis
  • Environment information and test data
  • Trends and historical data

Allure Report

TestNG Reports (Secondary)

Basic HTML reports are generated automatically:

  • Location: target/surefire-reports/index.html
  • Includes test results, execution time, and basic statistics

CI/CD Integration

Jenkins Integration

Setup Steps:

  1. Install required plugins: Maven, TestNG, Allure, HTML Publisher
  2. Create Maven project in Jenkins
  3. Configure SCM with your repository
  4. Add build steps:
# Clean and run tests
clean test -Psmoke

# For parameterized builds
clean test -P${PROFILE} -Dbrowser=${BROWSER}

Post-build Actions:

  • Publish TestNG Results: target/surefire-reports/testng-results.xml
  • Allure Report: target/allure-results
  • Archive Screenshots: screenshots/

Happy Learning!

Avdhut Shirgaonkar

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages