A comprehensive, enterprise-grade automation framework for Web UI testing using Selenium WebDriver, Java, TestNG, and Cucumber (BDD).
This framework follows industry best practices with a modular, maintainable structure:
- Page Object Model (POM) - Separation of page logic from test logic
- Thread-safe WebDriver - ThreadLocal implementation for parallel execution
- BDD with Cucumber - Business-readable test scenarios
- TestNG - Powerful test execution and parallelization
- ExtentReports & Cucumber Reports - Comprehensive reporting
- CI/CD Ready - Jenkins and GitHub Actions integration
Automation Framework/
βββ src/
β βββ main/
β β βββ java/
β β β βββ com/automation/
β β β βββ config/ # Configuration management
β β β β βββ ConfigReader.java
β β β βββ core/ # Core framework components
β β β β βββ DriverManager.java
β β β βββ pages/ # Page Object Model classes
β β β β βββ BasePage.java
β β β β βββ LoginPage.java
β β β βββ utils/ # Utility classes
β β β βββ WaitUtil.java
β β β βββ LoggerUtil.java
β β β βββ ScreenshotUtil.java
β β β βββ AssertionUtil.java
β β β βββ RetryUtil.java
β β βββ resources/
β β βββ config/ # Configuration files
β β β βββ config.properties
β β β βββ dev.properties
β β β βββ qa.properties
β β β βββ stage.properties
β β β βββ prod.properties
β β βββ testdata/ # Test data files
β β β βββ testdata.json
β β βββ log4j2.xml # Logging configuration
β βββ test/
β βββ java/
β β βββ com/automation/
β β βββ base/ # Base test classes
β β β βββ BaseTest.java
β β βββ hooks/ # Cucumber hooks
β β β βββ CucumberHooks.java
β β βββ runners/ # Test runners
β β β βββ TestRunner.java
β β βββ stepdefinitions/ # Step definitions
β β βββ LoginStepDefinitions.java
β βββ resources/
β βββ features/ # Cucumber feature files
β β βββ Login.feature
β βββ extent.properties # ExtentReports config
β βββ extent-config.xml
βββ testng.xml # TestNG suite configuration
βββ testng-parallel.xml # Parallel execution config
βββ testng-smoke.xml # Smoke test suite
βββ pom.xml # Maven configuration
βββ Jenkinsfile # Jenkins CI/CD pipeline
βββ .github/workflows/ci.yml # GitHub Actions workflow
βββ README.md # This file
- Java 17 or higher
- Maven 3.6+
- Chrome/Firefox/Edge browsers installed (for local execution)
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
-
Clone the repository
git clone <repository-url> cd "Automation Framework"
-
Install dependencies
mvn clean install
-
Configure environment
- Update
src/main/resources/config/config.propertieswith your application URLs - Update environment-specific properties files (dev.properties, qa.properties, etc.)
- Update
-
Update test data
- Modify
src/main/resources/testdata/testdata.jsonwith your test data
- Modify
mvn clean testmvn clean test -Dbrowser=chrome
mvn clean test -Dbrowser=firefox
mvn clean test -Dbrowser=edgemvn clean test -Denv=qa
mvn clean test -Denv=dev
mvn clean test -Denv=stage
mvn clean test -Denv=prodmvn clean test -Dcucumber.filter.tags=@smoke
mvn clean test -Dcucumber.filter.tags=@regression
mvn clean test -Dcucumber.filter.tags="@smoke or @regression"mvn clean test -Dheadless=truemvn clean test -Dexecution.mode=remote -Dgrid.url=http://localhost:4444/wd/hubmvn clean test -Dbrowser=chrome -Denv=qa -Dcucumber.filter.tags=@smoke -Dheadless=falsemvn clean testmvn clean test -Dsurefire.suiteXmlFiles=testng-parallel.xmlmvn clean test -Dsurefire.suiteXmlFiles=testng-smoke.xml-
IntelliJ IDEA
- Right-click on
testng.xmlβ Run - Or run
TestRunner.javadirectly
- Right-click on
-
Eclipse
- Right-click on
testng.xmlβ Run As β TestNG Suite
- Right-click on
Edit src/main/resources/config/config.properties:
browser=chrome # chrome, firefox, edge
headless=false # true for headless mode
execution.mode=local # local or remoteEnvironment-specific properties are loaded automatically based on the -Denv parameter:
dev.properties- Development environmentqa.properties- QA environmentstage.properties- Staging environmentprod.properties- Production environment
For remote execution, configure Grid URL:
grid.url=http://localhost:4444/wd/hubExtentReports are generated automatically after test execution:
- Location:
test-output/ExtentReports/ExtentReport.html - Includes screenshots, logs, and detailed test information
Cucumber reports are generated in multiple formats:
- HTML:
test-output/cucumber-reports/cucumber.html - JSON:
test-output/cucumber-reports/cucumber.json - XML:
test-output/cucumber-reports/cucumber.xml
After test execution, open:
# ExtentReports
open test-output/ExtentReports/ExtentReport.html
# Cucumber HTML Report
open test-output/cucumber-reports/cucumber.htmlThe framework supports parallel execution at multiple levels:
-
TestNG Parallel Execution
- Configured in
testng-parallel.xml - Set
thread-countandparallelattributes
- Configured in
-
Cucumber Parallel Execution
- Enabled in
TestRunner.javawith@DataProvider(parallel = true) - Scenarios run in parallel threads
- Enabled in
-
Thread-safe WebDriver
- Uses ThreadLocal for isolated WebDriver instances
- Safe for parallel execution
To add a new page to the framework:
-
Create Page Class
package com.automation.pages; public class NewPage extends BasePage { @FindBy(id = "elementId") private WebElement element; public void performAction() { click(element); } }
-
Create Step Definitions
package com.automation.stepdefinitions; public class NewPageStepDefinitions { private NewPage newPage = new NewPage(); @When("I perform action") public void i_perform_action() { newPage.performAction(); } }
-
Create Feature File
Feature: New Feature Scenario: Test scenario When I perform action
# Start Grid Hub
docker run -d -p 4444:4444 --name selenium-hub selenium/hub:latest
# Start Chrome Node
docker run -d -p 5555:5555 --link selenium-hub:hub selenium/node-chrome:latest
# Start Firefox Node
docker run -d -p 5556:5555 --link selenium-hub:hub selenium/node-firefox:latestmvn clean test -Dexecution.mode=remote -Dgrid.url=http://localhost:4444/wd/hub-
Create Pipeline Job
- New Item β Pipeline
- Point to
Jenkinsfilein repository
-
Configure Parameters
- Browser selection
- Environment selection
- Tag selection
- Execution mode
-
Run Pipeline
- Build with parameters
- View reports in Jenkins
The framework includes a GitHub Actions workflow (.github/workflows/ci.yml):
- Automatically runs on push/PR
- Supports manual workflow dispatch
- Matrix strategy for multiple browsers
- Artifact upload for reports
- β Page Object Model (POM) pattern
- β Thread-safe WebDriver with ThreadLocal
- β Multiple browser support (Chrome, Firefox, Edge)
- β Headless execution support
- β Selenium Grid support
- β Environment-specific configuration
- β Parallel execution (TestNG & Cucumber)
- β ExtentReports integration
- β Cucumber reporting
- β Screenshot on failure
- β Logging with Log4j2
- β Retry mechanism for flaky tests
- β Explicit waits and synchronization
- β CI/CD integration (Jenkins & GitHub Actions)
- β Tag-based test execution
- WaitUtil - Explicit waits and synchronization
- ScreenshotUtil - Screenshot capture on failure
- AssertionUtil - Custom assertions with logging
- RetryUtil - Retry mechanism for flaky operations
- LoggerUtil - Centralized logging
-
Page Objects
- Extend
BasePagefor all page classes - Use PageFactory for element initialization
- Keep page logic separate from test logic
- Extend
-
Step Definitions
- One step definition class per feature
- Reuse page object methods
- Keep steps simple and readable
-
Feature Files
- Use descriptive scenario names
- Tag scenarios appropriately
- Follow BDD best practices
-
Configuration
- Use environment-specific properties
- Never hardcode URLs or credentials
- Keep test data in separate files
-
Reporting
- Screenshots are captured automatically on failure
- Log important steps for debugging
- Use meaningful assertion messages
-
WebDriver not found
- WebDriverManager automatically downloads drivers
- Ensure internet connection for first run
-
Tests fail with timeout
- Increase wait times in
config.properties - Check application response time
- Increase wait times in
-
Parallel execution issues
- Ensure ThreadLocal is used (already implemented)
- Check thread-count in TestNG XML
-
Reports not generated
- Run
mvn verifyafter tests - Check
test-outputdirectory permissions
- Run
Key dependencies (see pom.xml for complete list):
- Selenium WebDriver 4.15.0
- TestNG 7.8.0
- Cucumber 7.14.0
- ExtentReports 5.1.1
- Log4j2 2.21.1
- WebDriverManager 5.6.2
- Follow the existing code structure
- Add appropriate logging
- Update documentation
- Ensure all tests pass
This framework is provided as-is for automation testing purposes.
For issues or questions:
- Check the troubleshooting section
- Review logs in
logs/automation.log - Check test output in
test-output/
Happy Testing! π