Skip to content

AVelani/selenium-automation-framework

Repository files navigation

OrangeHRM Selenium Automation Framework

A comprehensive, enterprise-grade Selenium WebDriver automation framework built using Java, TestNG, Apache POI, and Maven. This framework follows the Page Object Model (POM) design pattern and implements industry best practices for automated testing of the OrangeHRM web application.

πŸ—οΈ Framework Architecture

Technology Stack

  • Java 21 - Latest LTS version for robust performance
  • Selenium WebDriver 4.35.0 - Latest web automation capabilities
  • TestNG 7.11.0 - Advanced testing framework with powerful annotations
  • Apache POI 5.4.1 - Excel data manipulation for data-driven testing
  • Maven 3.9+ - Dependency management and build automation
  • SLF4J + Logback - Comprehensive logging framework
  • ExtentReports 5.1.2 - Rich HTML test reporting
  • WebDriverManager 5.9.3 - Automatic driver management

Design Patterns

  • Page Object Model (POM) - Clean separation of page elements and test logic
  • Factory Pattern - WebDriver initialization and management
  • Singleton Pattern - Configuration management
  • Builder Pattern - Test data construction
  • Observer Pattern - Test execution listeners

πŸ“ Project Structure

selenium-automation-framework/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com/
β”‚   β”‚   β”‚       └── orangehrm/
β”‚   β”‚   β”‚           β”œβ”€β”€ base/          # Base classes for tests and pages
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ BasePage.java
β”‚   β”‚   β”‚           β”‚   └── BaseTest.java
β”‚   β”‚   β”‚           β”œβ”€β”€ pages/         # Page Object classes
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ LoginPage.java
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ AdminPage.java
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ PIMPage.java
β”‚   β”‚   β”‚           β”‚   └── LeavePage.java
β”‚   β”‚   β”‚           └── utils/         # Utility classes
β”‚   β”‚   β”‚               β”œβ”€β”€ ConfigReader.java
β”‚   β”‚   β”‚               β”œβ”€β”€ ExcelUtils.java
β”‚   β”‚   β”‚               β”œβ”€β”€ ScreenshotUtils.java
β”‚   β”‚   β”‚               β”œβ”€β”€ TestListener.java
β”‚   β”‚   β”‚               └── RetryAnalyzer.java
β”‚   β”‚   └── resources/
β”‚   └── test/
β”‚       β”œβ”€β”€ java/
β”‚       β”‚   └── com/
β”‚       β”‚       └── orangehrm/
β”‚       β”‚           └── tests/         # Test classes
β”‚       β”‚               β”œβ”€β”€ LoginTest.java
β”‚       β”‚               β”œβ”€β”€ AdminTest.java
β”‚       β”‚               β”œβ”€β”€ PIMTest.java
β”‚       β”‚               └── LeaveTest.java
β”‚       └── resources/
β”‚           β”œβ”€β”€ testdata/              # Test data files
β”‚           β”‚   β”œβ”€β”€ TestData.xlsx
β”‚           β”‚   └── TestCases.xlsx
β”‚           β”œβ”€β”€ config/               # Configuration files
β”‚           β”‚   └── extent-config.xml
β”‚           └── logs/                 # Log files directory
β”œβ”€β”€ test-output/                      # Test execution reports
β”œβ”€β”€ target/                          # Maven build directory
β”œβ”€β”€ pom.xml                          # Maven configuration
β”œβ”€β”€ testng.xml                       # TestNG suite configuration
β”œβ”€β”€ config.properties                # Framework configuration
β”œβ”€β”€ logback.xml                      # Logging configuration
└── README.md                        # Project documentation

πŸš€ Getting Started

Prerequisites

  • Java Development Kit (JDK) 21 or higher
  • Maven 3.9+ for dependency management
  • IDE (IntelliJ IDEA, Eclipse, or VS Code)
  • Git for version control

Installation & Setup

  1. Clone the repository

    git clone https://github.com/your-repo/orangehrm-automation-framework.git
    cd orangehrm-automation-framework
  2. Install dependencies

    mvn clean compile
  3. Verify setup

    mvn clean test -Dtest=LoginTest#testValidLogin

Configuration

Framework Configuration (config.properties)

# Application Configuration
app.url=https://opensource-demo.orangehrmlive.com/
default.username=Admin
default.password=admin123

# Browser Configuration
browser.name=chrome
browser.headless=false
browser.maximize=true

# Wait Configuration
webdriver.implicit.wait=10
webdriver.explicit.wait=15
webdriver.page.load.timeout=30

# Reporting Configuration
extent.report.path=test-output/ExtentReport.html
screenshot.on.failure=true

πŸ§ͺ Test Execution

Running Tests via Maven

Execute All Tests

mvn clean test

Execute Smoke Tests

mvn clean test -Dgroups=smoke

Execute Specific Module Tests

# Login module tests
mvn clean test -Dtest=LoginTest

# Admin module tests  
mvn clean test -Dtest=AdminTest

# Data-driven tests
mvn clean test -Dgroups=datadriven

Cross-Browser Execution

# Chrome browser
mvn clean test -DbrowserName=chrome

# Firefox browser
mvn clean test -DbrowserName=firefox

# Edge browser
mvn clean test -DbrowserName=edge

# Headless mode
mvn clean test -Dheadless=true

Parallel Execution

# Parallel execution with 3 threads
mvn clean test -DthreadCount=3 -Dparallel=methods

Running Tests via TestNG XML

Execute Complete Test Suite

mvn clean test -DsuiteXmlFile=testng.xml

Execute Specific Test Groups

# Smoke tests only
mvn clean test -DsuiteXmlFile=testng.xml -Dgroups=smoke

# Regression tests
mvn clean test -DsuiteXmlFile=testng.xml -Dgroups=regression

Running Tests from IDE

  1. IntelliJ IDEA / Eclipse

    • Right-click on test class or method
    • Select "Run as TestNG Test"
    • Configure run parameters as needed
  2. Command Line with Profiles

    # Development environment
    mvn clean test -Pdev
    
    # Staging environment
    mvn clean test -Pstaging

πŸ“Š Test Data Management

Excel-Based Data-Driven Testing

The framework supports comprehensive data-driven testing using Excel files:

TestData.xlsx Structure

  • LoginTest Sheet: Login scenarios with various credential combinations
  • AdminTest Sheet: User management test scenarios
  • PIMTest Sheet: Employee management test scenarios
  • LeaveTest Sheet: Leave application test scenarios

Sample Test Data Format

TestCaseID | TestScenario           | Username    | Password     | ExpectedResult
LOGIN_001  | Valid Login Test       | Admin       | admin123     | Login Successful
LOGIN_002  | Invalid Username Test  | InvalidUser | admin123     | Invalid credentials error
LOGIN_003  | Empty Credentials Test |             |              | Required field errors

Using Excel Data in Tests

@Test(dataProvider = "loginTestData")
public void testLoginWithExcelData(String testCaseId, String username, 
                                 String password, String expectedResult) {
    // Test implementation
}

@DataProvider(name = "loginTestData")
public Object[][] getLoginTestData() {
    return ExcelUtils.getSheetDataAsMap("TestData.xlsx", "LoginTest");
}

πŸ“ˆ Reporting & Logging

ExtentReports

  • Rich HTML Reports with test execution details
  • Screenshots automatically attached to failed tests
  • Test execution statistics and trends
  • Cross-browser execution summary
  • Custom styling and branding

Access Reports

  • Location: test-output/ExtentReport.html
  • Auto-generated after test execution
  • Email integration available for stakeholder notifications

Logging Framework

  • SLF4J + Logback for comprehensive logging
  • Multiple appenders: Console, File, Rolling File
  • Log levels: DEBUG, INFO, WARN, ERROR
  • Package-specific log configurations
  • Log files location: src/test/resources/logs/

Log Configuration

<!-- Console logging for development -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<!-- File logging with daily rollover -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/automation.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>logs/automation.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>30</maxHistory>
    </rollingPolicy>
</appender>

πŸ”§ Framework Features

Page Object Model Implementation

  • Separation of Concerns: Page elements and actions separated from test logic
  • Reusability: Page objects can be used across multiple test classes
  • Maintainability: Changes in UI require updates only in page classes
  • Readability: Test methods focus on business logic, not technical implementation

Base Classes

  • BaseTest: Common setup/teardown, WebDriver management, configuration
  • BasePage: Reusable web element interactions, wait strategies, utilities

Utility Classes

  • ConfigReader: Centralized configuration management with Singleton pattern
  • ExcelUtils: Comprehensive Excel file operations for data-driven testing
  • ScreenshotUtils: Screenshot capture for reporting and debugging
  • WaitUtils: Custom wait strategies for dynamic elements

Test Execution Features

  • Cross-browser Support: Chrome, Firefox, Edge with automatic driver management
  • Parallel Execution: TestNG parallel execution with thread-safe WebDriver
  • Retry Mechanism: Automatic retry for flaky tests
  • Test Groups: Smoke, Regression, Module-specific test organization
  • Data-driven Testing: Excel-based test data with dynamic test generation

πŸ” Test Coverage

Functional Modules Covered

1. Login Module

  • βœ… Valid login with correct credentials
  • βœ… Invalid login scenarios (wrong username/password)
  • βœ… Empty field validation
  • βœ… SQL injection prevention testing
  • βœ… Login page element validation

2. Admin Module

  • βœ… User search functionality
  • βœ… Add new user with role assignment
  • βœ… User management operations
  • βœ… Role-based validation
  • βœ… Duplicate username prevention

3. PIM (Personal Information Management) Module

  • βœ… Add new employee
  • βœ… Employee search functionality
  • βœ… Employee profile management
  • βœ… Employee ID validation
  • βœ… Contact information updates

4. Leave Module

  • βœ… Leave application process
  • βœ… Leave balance validation
  • βœ… Leave status verification
  • βœ… Leave type selection
  • βœ… Date validation (future/past dates)

Test Types

  • Smoke Tests: Critical functionality verification
  • Regression Tests: Comprehensive feature testing
  • Data-driven Tests: Excel-based test scenarios
  • Negative Tests: Error handling and validation
  • Security Tests: SQL injection, XSS prevention
  • UI Tests: Element presence and interaction validation

πŸ› οΈ Customization & Extension

Adding New Page Objects

  1. Create new page class extending BasePage
  2. Define web element locators using By objects
  3. Implement page-specific methods with proper logging
  4. Add comprehensive JavaDoc documentation
public class NewPage extends BasePage {
    private static final Logger logger = LoggerFactory.getLogger(NewPage.class);
    
    // Element locators
    private final By elementLocator = By.id("element-id");
    
    public NewPage(WebDriver driver) {
        super(driver);
    }
    
    public NewPage performAction() {
        click(elementLocator);
        logger.info("Action performed successfully");
        return this;
    }
}

Adding New Test Classes

  1. Extend BaseTest class for common functionality
  2. Use TestNG annotations for test configuration
  3. Implement data providers for data-driven testing
  4. Add appropriate test groups and priorities
public class NewModuleTest extends BaseTest {
    @Test(groups = {"smoke", "newmodule"}, priority = 1)
    public void testNewFeature() {
        // Test implementation
    }
}

Configuration Extension

  1. Add new properties to config.properties
  2. Extend ConfigReader with new getter methods
  3. Update TestNG XML for new test configurations
  4. Modify Maven profiles for different environments

πŸ“‹ Best Practices Implemented

Code Quality

  • Clean Code: Descriptive naming, proper indentation, code comments
  • SOLID Principles: Single responsibility, open/closed, dependency inversion
  • Design Patterns: Factory, Singleton, Observer, Builder patterns
  • Exception Handling: Comprehensive error handling with meaningful messages

Test Design

  • Independent Tests: Each test can run independently without dependencies
  • Data-driven Approach: External test data management via Excel files
  • Assertions: Comprehensive validations with descriptive error messages
  • Wait Strategies: Explicit waits for reliable element interactions

Framework Architecture

  • Modular Design: Separated concerns with clear package structure
  • Configurability: External configuration for easy environment management
  • Extensibility: Easy to add new modules, pages, and test scenarios
  • Maintainability: Changes isolated to specific components

Reporting & Debugging

  • Detailed Logging: Comprehensive logging at all levels
  • Screenshot Capture: Automatic screenshots on test failures
  • Rich Reports: ExtentReports with detailed test execution information
  • Error Tracking: Stack traces and error context preservation

πŸ”§ Troubleshooting

Common Issues & Solutions

WebDriver Issues

# Issue: WebDriver not found
# Solution: Ensure WebDriverManager is properly configured
mvn clean test -DwebDriverManagerEnabled=true

Excel Data Issues

# Issue: Test data not loading
# Solution: Verify Excel file path and sheet names
# Check: src/test/resources/testdata/TestData.xlsx

Browser Issues

# Issue: Browser not launching
# Solution: Update browser drivers or use WebDriverManager
mvn clean test -DupdateDrivers=true

Parallel Execution Issues

# Issue: Thread conflicts in parallel execution
# Solution: Ensure ThreadLocal WebDriver usage
# Check: BaseTest.driverThreadLocal implementation

Debug Mode Execution

# Enable debug logging
mvn clean test -Dlogback.debug=true

# Verbose TestNG execution
mvn clean test -Dverbose=2

# Skip tests and compile only
mvn clean compile -DskipTests=true

Performance Optimization

# Headless execution for CI/CD
mvn clean test -Dheadless=true

# Reduced wait timeouts for faster execution
mvn clean test -DimplicitWait=5 -DexplicitWait=10

# Parallel execution optimization
mvn clean test -DthreadCount=3 -DdataProviderThreadCount=2

🀝 Contributing

Development Guidelines

  1. Follow existing code structure and naming conventions
  2. Add comprehensive JavaDoc for all public methods
  3. Include unit tests for utility classes
  4. Update documentation for new features
  5. Follow Git branching strategy (feature/bugfix branches)

Code Review Checklist

  • Code follows established patterns and conventions
  • Comprehensive logging added for debugging
  • Error handling implemented properly
  • Test cases cover positive and negative scenarios
  • Documentation updated for new features
  • No hardcoded values (use configuration)

πŸ“ž Support & Contact

Documentation

  • Technical Documentation: Available in /docs folder
  • API Documentation: JavaDoc generated documentation
  • Test Reports: Available in test-output folder

Issue Reporting

  • GitHub Issues: For bug reports and feature requests
  • Log Analysis: Check src/test/resources/logs/ for detailed execution logs
  • Screenshot Evidence: Available in test-output/screenshots/ for failed tests

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Framework Version: 1.0.0
Last Updated: August 14, 2024
Maintained By: Automation Framework Team


This framework demonstrates enterprise-grade automation testing practices and can serve as a reference implementation for Selenium-based test automation projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages