Selenium test automation framework template using Java with Page Object Model, TestNG, and extensive reporting capabilities.
- Page Object Model (POM) design pattern for maintainable test code
- TestNG framework with parallel execution support
- Multiple Browser Support (Chrome, Firefox, Edge) with headless capabilities
- Comprehensive Reporting with Extent Reports and Allure integration
- Data-Driven Testing with JSON, CSV, and Excel support
- Docker Support for containerized test execution
- CI/CD Integration with GitHub Actions
- Code Quality Checks with Checkstyle, PMD, and SpotBugs
- Cross-Platform Compatibility (Windows, macOS, Linux)
- Selenium Grid Support for distributed test execution
- Screenshot Capture on test failures
- Comprehensive Logging with SLF4J and Logback
- Configuration Management for multiple environments
- Java 11 or higher
- Maven 3.6 or higher
- Git for version control
- Chrome/Firefox/Edge browsers (for local execution)
- Docker (optional, for containerized execution)
git clone https://github.com/Exemplify777/java-selenium-automation-framework.git
cd java-selenium-automation-framework
mvn clean install
Run the framework validation tests to ensure everything is working correctly:
mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng-validation.xml -Djacoco.skip=true
This will run comprehensive validation tests that check:
- Configuration management
- JSON and CSV data readers
- Assertion utilities
- Extent report generation
- Screenshot utilities
- Overall framework integration
./scripts/install-hooks.sh
# Run smoke tests
mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng-smoke.xml
# Run all tests
mvn test
# Run tests with specific browser
mvn test -Dbrowser=firefox
# Run tests in headless mode
mvn test -Dheadless=true
# Run tests for specific environment
mvn test -Denvironment=staging
java-selenium-automation-framework/
βββ src/
β βββ main/java/com/automation/
β β βββ config/ # Configuration management
β β βββ pages/ # Page Object Model classes
β β βββ utils/ # Utility classes
β βββ test/
β βββ java/com/automation/
β β βββ tests/ # Test classes
β β βββ data/ # Test data classes
β βββ resources/
β βββ config/ # Environment configurations
β βββ testdata/ # Test data files
β βββ testng*.xml # TestNG suite files
βββ target/
β βββ reports/ # Test reports
β βββ screenshots/ # Screenshots
β βββ allure-results/ # Allure results
βββ scripts/ # Helper scripts
βββ .github/workflows/ # GitHub Actions workflows
βββ docker-compose.yml # Docker configuration
βββ Dockerfile # Docker image definition
βββ README.md # This file
The framework supports multiple environments through property files:
src/test/resources/config/dev.properties
src/test/resources/config/staging.properties
src/test/resources/config/prod.properties
# Application URL
base.url=https://example.com
# Browser settings
browser=chrome
headless=false
browser.window.maximize=true
# Timeouts
browser.implicit.wait=10
browser.page.load.timeout=30
explicit.wait.timeout=15
# Parallel execution
parallel.tests=true
thread.count=3
# Reporting
reports.path=target/reports
screenshots.path=target/screenshots
screenshot.on.failure=true
@Listeners(TestListener.class)
public class LoginTest extends BaseTest {
@Test(description = "Verify successful login")
public void testSuccessfulLogin() {
LoginPage loginPage = new LoginPage();
loginPage.navigateToLoginPage();
HomePage homePage = loginPage.login("username", "password");
AssertionUtils.assertTrue(homePage.isUserLoggedIn(),
"User should be logged in successfully");
}
}
public class LoginPage extends BasePage {
@FindBy(id = "username")
private WebElement usernameField;
@FindBy(id = "password")
private WebElement passwordField;
@FindBy(id = "loginButton")
private WebElement loginButton;
public HomePage login(String username, String password) {
type(usernameField, username);
type(passwordField, password);
click(loginButton);
return new HomePage();
}
}
# Build and run tests locally
./scripts/docker-run.sh local
# Run tests with Selenium Grid
./scripts/docker-run.sh grid
# Run smoke tests
./scripts/docker-run.sh smoke
# Run tests in debug mode (VNC available on port 5900)
./scripts/docker-run.sh debug
# Run with Selenium Grid
docker-compose up --build
# Run locally without Grid
docker-compose -f docker-compose.local.yml up --build
HTML reports are generated in target/reports/
directory with:
- Test execution summary
- Screenshots on failures
- Detailed test steps
- Environment information
Generate Allure reports:
mvn allure:report
mvn allure:serve
The framework includes pre-configured workflows:
- test-automation.yml: Main test execution workflow
- nightly-tests.yml: Comprehensive nightly test execution
- pr-validation.yml: Pull request validation with code quality checks
# Trigger workflow manually
gh workflow run test-automation.yml -f test_suite=smoke -f browser=chrome
# View workflow status
gh run list
Install Git hooks for automatic code quality checks:
./scripts/install-hooks.sh
# Checkstyle
mvn checkstyle:check
# PMD
mvn pmd:check
# SpotBugs
mvn spotbugs:check
# All quality checks
mvn verify
Configure parallel execution in testng.xml
:
<suite name="Parallel Tests" parallel="methods" thread-count="3">
<!-- Test configuration -->
</suite>
# Run tests in parallel
mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng-parallel.xml
# Specify thread count
mvn test -Dthread.count=5
- Set
headless=false
in configuration - Add breakpoints in your IDE
- Run tests in debug mode
# Start debug environment
./scripts/docker-run.sh debug
# Connect VNC viewer to localhost:5900
- Chrome (default)
- Firefox
- Microsoft Edge
# Run with specific browser
mvn test -Dbrowser=firefox
# Run with multiple browsers (CI)
mvn test -Dbrowser=chrome,firefox,edge
- Use Page Object Model for UI interactions
- Implement data-driven testing for multiple test scenarios
- Use meaningful test names and descriptions
- Group tests logically using TestNG groups
- Implement proper assertions with custom assertion utilities
- Follow coding standards enforced by Checkstyle
- Write clean, readable code with proper comments
- Use dependency injection where appropriate
- Implement proper exception handling
- Follow SOLID principles
- Externalize test data in JSON/CSV/Excel files
- Use environment-specific data when needed
- Avoid hardcoded values in test code
- Implement data factories for complex objects
# Clear WebDriver cache
rm -rf ~/.cache/selenium
# Update WebDriverManager
mvn dependency:resolve
# Update browser to latest version
# Chrome: chrome://settings/help
# Firefox: about:support
# Verify browser installation
google-chrome --version
firefox --version
# Clear Maven cache
mvn dependency:purge-local-repository
# Reload dependencies
mvn clean install -U
# Clean Docker environment
docker system prune -a
# Rebuild images
docker-compose build --no-cache
- Check the logs in
logs/
directory - Review test reports in
target/reports/
- Check screenshots in
target/screenshots/
- Consult the troubleshooting guide in
docs/TROUBLESHOOTING.md
- Open an issue on GitHub with detailed information
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Follow conventional commit format:
type(scope): description
feat(login): add remember me functionality
fix(driver): resolve browser initialization issue
docs: update README with new examples
This project is licensed under the MIT License - see the LICENSE file for details.
- Selenium WebDriver for browser automation
- TestNG for test framework
- Extent Reports for reporting
- WebDriverManager for driver management
- Allure for advanced reporting
For support and questions:
- π Issues: GitHub Issues
Happy Testing! π