- Introduction
- Prerequisites
- Project Structure
- Technologies Used
- Getting Started
- Test Execution
- Test Suites
- Data-Driven Testing
- Framework Features
- Reporting
- CI/CD Integration
- Contacts
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
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
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
- Java - Programming language
- Selenium - Web automation
- TestNG - Test framework
- REST Assured - API testing
- Allure - Reporting
- Maven - Build tool
- Jackson - JSON processing
- Log4J2 - Logging framework
- Clone the repository:
git clone https://github.com/avdhutssh/UI-API_Automation_Selenium_RestAssured.git
- Navigate to the project directory:
cd UI-API_Automation_Selenium_RestAssured
- Install dependencies:
mvn clean install
This will download all required dependencies including Selenium, REST Assured, TestNG, Allure Reports, and Log4J2.
mvn clean test
# 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
# Chrome browser (default)
mvn clean test -Dbrowser=chrome
# Headless mode
mvn clean test -Dheadless=true
The framework includes multiple pre-configured test suites:
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
Comprehensive feature testing:
- Extended login scenarios with CSV data
- Multiple product interactions
- Advanced cart management
- Detailed UI validations
- API integration testing
- Error handling scenarios
Complete test coverage:
- All smoke tests
- All regression tests
- Full UI and API integration
- End-to-end workflows
The framework supports multiple data-driven testing approaches:
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);
}
// Reading JSON test data
JSONDataReader jsonReader = new JSONDataReader();
Map<String, Object> testData = jsonReader.getTestData("loginTestData.json");
// Using configuration-driven test data
String productName = ConfigurationUtils.getProperty("productName");
String countryName = ConfigurationUtils.getProperty("countryName");
- 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
- 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
- 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
- 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
- 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
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
Basic HTML reports are generated automatically:
- Location:
target/surefire-reports/index.html
- Includes test results, execution time, and basic statistics
Setup Steps:
- Install required plugins: Maven, TestNG, Allure, HTML Publisher
- Create Maven project in Jenkins
- Configure SCM with your repository
- 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