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.
- 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
- 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
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
- Java Development Kit (JDK) 21 or higher
- Maven 3.9+ for dependency management
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
- Git for version control
-
Clone the repository
git clone https://github.com/your-repo/orangehrm-automation-framework.git cd orangehrm-automation-framework
-
Install dependencies
mvn clean compile
-
Verify setup
mvn clean test -Dtest=LoginTest#testValidLogin
# 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
mvn clean test
mvn clean test -Dgroups=smoke
# Login module tests
mvn clean test -Dtest=LoginTest
# Admin module tests
mvn clean test -Dtest=AdminTest
# Data-driven tests
mvn clean test -Dgroups=datadriven
# 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 with 3 threads
mvn clean test -DthreadCount=3 -Dparallel=methods
mvn clean test -DsuiteXmlFile=testng.xml
# Smoke tests only
mvn clean test -DsuiteXmlFile=testng.xml -Dgroups=smoke
# Regression tests
mvn clean test -DsuiteXmlFile=testng.xml -Dgroups=regression
-
IntelliJ IDEA / Eclipse
- Right-click on test class or method
- Select "Run as TestNG Test"
- Configure run parameters as needed
-
Command Line with Profiles
# Development environment mvn clean test -Pdev # Staging environment mvn clean test -Pstaging
The framework supports comprehensive data-driven testing using Excel files:
- 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
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
@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");
}
- 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
- Location:
test-output/ExtentReport.html
- Auto-generated after test execution
- Email integration available for stakeholder notifications
- 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/
<!-- 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>
- 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
- BaseTest: Common setup/teardown, WebDriver management, configuration
- BasePage: Reusable web element interactions, wait strategies, utilities
- 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
- 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
- β Valid login with correct credentials
- β Invalid login scenarios (wrong username/password)
- β Empty field validation
- β SQL injection prevention testing
- β Login page element validation
- β User search functionality
- β Add new user with role assignment
- β User management operations
- β Role-based validation
- β Duplicate username prevention
- β Add new employee
- β Employee search functionality
- β Employee profile management
- β Employee ID validation
- β Contact information updates
- β Leave application process
- β Leave balance validation
- β Leave status verification
- β Leave type selection
- β Date validation (future/past dates)
- 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
- Create new page class extending
BasePage
- Define web element locators using
By
objects - Implement page-specific methods with proper logging
- 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;
}
}
- Extend
BaseTest
class for common functionality - Use TestNG annotations for test configuration
- Implement data providers for data-driven testing
- Add appropriate test groups and priorities
public class NewModuleTest extends BaseTest {
@Test(groups = {"smoke", "newmodule"}, priority = 1)
public void testNewFeature() {
// Test implementation
}
}
- Add new properties to
config.properties
- Extend
ConfigReader
with new getter methods - Update TestNG XML for new test configurations
- Modify Maven profiles for different environments
- 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
- 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
- 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
- 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
# Issue: WebDriver not found
# Solution: Ensure WebDriverManager is properly configured
mvn clean test -DwebDriverManagerEnabled=true
# Issue: Test data not loading
# Solution: Verify Excel file path and sheet names
# Check: src/test/resources/testdata/TestData.xlsx
# Issue: Browser not launching
# Solution: Update browser drivers or use WebDriverManager
mvn clean test -DupdateDrivers=true
# Issue: Thread conflicts in parallel execution
# Solution: Ensure ThreadLocal WebDriver usage
# Check: BaseTest.driverThreadLocal implementation
# 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
# 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
- Follow existing code structure and naming conventions
- Add comprehensive JavaDoc for all public methods
- Include unit tests for utility classes
- Update documentation for new features
- Follow Git branching strategy (feature/bugfix branches)
- 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)
- Technical Documentation: Available in
/docs
folder - API Documentation: JavaDoc generated documentation
- Test Reports: Available in
test-output
folder
- 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
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.