A comprehensive test automation framework demonstrating best practices with Selenium WebDriver, TestNG, and Allure reporting. This project showcases parameterized testing, parallel execution, automatic retry logic, and advanced reporting capabilities.
Note: This branch uses TestNG 7 as the testing framework. For a JUnit-based implementation, please check out the
junit6branch.
- Features
- Tech Stack
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- Reporting
- Advanced Features
- Troubleshooting
- License
- Additional Resources
- Useful Links
- π§ Page Object Model (POM) / Page Object design pattern
- π Parallel test execution with configurable thread count
- π― Parameterized tests using TestNG DataProviders
- π§ͺ TestNG listeners for custom test lifecycle management
- π Multiple reporting formats: Allure, TestNG HTML, and Excel
- π Automatic test retry on failure
- πΈ Screenshot capture on test failure
- π Page source capture for debugging
- π Cross-browser support (Chrome, Firefox, Edge)
- π¨ Allure annotations for rich test documentation
- π AssertJ for fluent assertions
- π¦ Automatic WebDriver management via Selenium Manager
- βοΈ Configuration management using Owner library
- π Lombok for reducing boilerplate code
| Technology | Version | Purpose |
|---|---|---|
| Java | 21 | Programming language |
| Gradle | 8.x | Build automation |
| Selenium WebDriver | 4.38.0 | Browser automation |
| TestNG | 7.11.0 | Testing framework |
| Allure Framework (Allure Java) | 2.31.0 | Used inside tests (annotations, listeners). Produces raw results. |
| Allure Report CLI | 2.35.1 | Generates interactive HTML report from test results. |
| AssertJ | 3.27.6 | Fluent assertions |
| Apache POI | 5.5.0 | Excel report generation |
| OpenCSV | 5.12.0 | CSV data handling |
| Owner | 1.0.12 | Configuration management |
| Lombok | 1.18.42 | Code generation |
| Jackson | 2.20.1 | JSON processing |
| Log4j/SLF4J | 2.24.3/2.0.17 | Logging |
Before you begin, ensure you have the following installed:
-
Java Development Kit (JDK) 21 or higher
- Download JDK
- Verify:
java -version
-
Gradle (optional, wrapper included)
- Verify:
gradle -version
- Verify:
-
Git (for cloning the repository)
- Download Git
- Verify:
git --version
-
Web Browser (Chrome, Firefox, or Edge)
- Drivers are managed automatically by Selenium Manager
-
Clone the repository
git clone https://github.com/yourusername/selenium-example.git cd selenium-example -
Verify Gradle installation
.\gradlew.bat --version -
Download dependencies
.\gradlew.bat build --refresh-dependencies -
Compile the project
.\gradlew.bat clean compileTestJava
# Browser configuration
env.browser=Chrome # Options: Chrome, Firefox, Edge
# Application URL
env.url=http://calculator.com # Target application URL
# Timeout settings
default.webdriver.timeout=180 # WebDriver timeout in seconds
# Timezone configuration
env.time.zone=Europe/Warsaw # Timezone for test execution timestampsThe test execution is configured in build.gradle:
test {
useTestNG {
parallel = 'classes'
// Parallel execution at class level
threadCount = 3 // Number of parallel threads
useDefaultListeners = true
outputDirectory = layout.buildDirectory.file("reports/testng").get().asFile
// TestNG report output directory
}
retry {
failOnPassedAfterRetry = true
maxFailures = 100
// Maximum failures before stopping
maxRetries = 1 // Number of retry attempts
}
}To run tests with different browsers:
- Edit
general.propertiesand changeenv.browservalue - Or set system property:
.\gradlew.bat test -Denv.browser=Firefox
Execute the entire test suite:
.\gradlew.bat clean testExecute a single test class:
.\gradlew.bat clean test --tests com.oleynik.gradle.selenium.example.test.CalculatorSanityTestExecute a specific test method:
.\gradlew.bat clean test --tests com.oleynik.gradle.selenium.example.test.CalculatorSanityTest.checkCalculatorOpeningExecute all tests in a specific package:
.\gradlew.bat clean test --tests com.oleynik.gradle.selenium.example.test.*Execute tests with system properties:
.\gradlew.bat clean test -Denv.browser=Firefox -Denv.url=https://example.comGenerate Allure report from existing test results:
.\gradlew.bat allureReportGenerate Excel report:
.\gradlew.bat excelReportCheck for outdated dependencies:
.\gradlew.bat dependencyUpdatesselenium-example/
βββ src/
β βββ test/
β βββ java/
β β βββ com/oleynik/gradle/selenium/example/
β β βββ framework/ # Framework utilities
β β β βββ config/ # Configuration management
β β β βββ listeners/ # TestNG listeners
β β β βββ manager/ # WebDriver management
β β β βββ reporting/ # Custom reporting
β β β βββ utils/ # Utility classes
β β βββ pages/ # Page Object classes
β β βββ steps/ # Test step definitions
β β βββ test/ # Test classes
β β βββ BasicDivisionTest.java
β β βββ BasicOperationsTest.java
β β βββ CalculatorSanityTest.java
β β βββ SoftAssertionTest.java
β βββ resources/
β βββ general.properties # Main configuration
β βββ allure.properties # Allure configuration
β βββ Division.csv # Test data files
βββ build/
β βββ reports/ # Generated reports
β β βββ allure-report/
β β βββ tests/
β β βββ *.xlsx
β βββ test-results/ # Test execution results
βββ drivers/ # WebDriver binaries (managed automatically)
βββ build.gradle # Build configuration
βββ gradlew.bat # Gradle wrapper (Windows)
βββ gradlew # Gradle wrapper (Linux/Mac)
βββ README.md # This file
Location: build/reports/allure-report/allureReport/index.html
Features:
- π Test execution timeline
- π Test result statistics
- πΈ Screenshots on failure
- π Page source capture
- π·οΈ Test categorization
- π Detailed test steps
- π Trend analysis
View Report:
# Generate and open report
.\gradlew.bat allureReport
# Then open: build/reports/allure-report/allureReport/index.htmlLocation: build/reports/tests/test/index.html
Features:
- β Pass/Fail statistics
- β±οΈ Execution time
- π Test class grouping
- β Failure details
- π Test results breakdown
Location: build/excel-results/testExecutionReport_ddmmyy_hhmmss.xlsx
Features:
- π Test execution summary
- π Timestamp information
- β Status tracking
- π’ Test parameters
- β±οΈ Duration metrics
Tests run in parallel at the class level with 3 threads by default. Configure in build.gradle:
test {
useTestNG {
parallel = 'classes' // Options: methods, tests, classes, instances
threadCount = 3 // Number of parallel threads
}
}Failed tests are automatically retried once:
retry {
failOnPassedAfterRetry = true
maxFailures = 100
maxRetries = 1
}Tests support parameterization via TestNG DataProviders:
@DataProvider(name = "additionData")
public Object[][] additionData() {
return new Object[][]{
{2, 3, 5},
{10, 5, 15},
{-1, 1, 0}
};
}
@Test(dataProvider = "additionData")
public void testAddition(int a, int b, int expected) {
// Test implementation
}Load test data from CSV files:
@DataProvider
public Iterator<Object[]> divisionData() {
return CsvDataProvider.getData("src/test/resources/Division.csv");
}Screenshots are automatically captured on test failure and attached to Allure reports:
- Location:
build/screenshots/ - Format:
timestamp-ClassName-testMethod.png
If Chrome drivers are not closing properly:
taskkill /F /IM chromedriver.exe /TIf you encounter build issues:
.\gradlew.bat clean --refresh-dependenciesWebDrivers are managed automatically by Selenium Manager. To force update:
.\gradlew.bat clean test --refresh-dependenciesEnable verbose logging:
.\gradlew.bat test --infoOr debug mode:
.\gradlew.bat test --debugThis project is licensed under the MIT License - see the LICENSE file for details.
- Selenium Documentation
- TestNG Documentation
- Allure Framework
- Gradle User Guide
- Selenium Manager
- Selenium Grid Setup
- Selenium Grid Downloads: https://www.selenium.dev/downloads/
- Java Download: https://www.oracle.com/java/technologies/downloads/
- Gradle Download: https://gradle.org/install/