A streamlined Java-based Selenium automation framework built with Maven, TestNG, and ExtentReports. Features industry-standard test cases using SauceDemo - a fully-featured e-commerce application designed for testing.
- Page Object Model (POM) - Maintainable and reusable page objects
- Maven - Dependency management and build automation
- TestNG - Test execution and reporting framework
- ExtentReports - Beautiful HTML reports with screenshots (auto-opens after tests)
- WebDriverManager - Automatic driver management
- Firefox Default - Stable headless execution out of the box
- Simplified Architecture - Clean, focused test suite (31 core tests)
- Auto-Report Opening - Reports automatically open in browser after execution
- Smart Cleanup - Automatic old report cleanup on each run
- Custom Maven Wrapper - Easy-to-use commands for all operations
- Configuration Management - Centralized configuration
- Java 21 - Latest LTS Java version
Java Selenium Framework/
βββ pom.xml # Maven configuration with auto-cleanup
βββ README.md # This documentation
βββ mvn-wrapper.sh # Custom Maven wrapper (auto-opens reports)
βββ .gitignore # Git ignore rules
βββ src/main/java/com/framework/
β βββ config/
β β βββ WebDriverConfig.java # WebDriver setup & management (Firefox default)
β β βββ ConfigReader.java # Configuration file reader
β β βββ EnvironmentConfig.java # Environment variable support
β βββ pages/
β β βββ BasePage.java # Base page class with common methods
β β βββ LoginPage.java # SauceDemo login page
β β βββ ProductsPage.java # Products listing page
β β βββ CartPage.java # Shopping cart page
β βββ reports/
β β βββ ExtentReportManager.java # HTML report management
β β βββ ScreenshotUtils.java # Screenshot utilities
β βββ utils/
β βββ WebDriverUtils.java # Common WebDriver operations
β βββ ExcelUtils.java # Excel file operations
βββ src/test/
βββ java/com/framework/tests/
β βββ LoginTest.java # Login tests (6 tests)
β βββ ProductTest.java # Product tests (8 tests)
β βββ CartTest.java # Cart tests (17 tests)
βββ resources/
βββ config/
β βββ config.properties # Configuration settings
βββ testdata/
β βββ testdata.json # Test data
βββ testng.xml # TestNG suite (sequential execution)
- Java 21 (LTS - Latest Long Term Support)
- Maven 3.6+
- Firefox browser (default) or Chrome/Edge
- macOS/Linux/Windows
-
Clone or download the project
-
Navigate to project directory
cd "Java Selenium Framework"
-
Set up environment variables (Important!)
# Copy the example environment file cp .env.example .env # Edit .env with your credentials (optional for demo) # The default values work for SauceDemo
-
Install dependencies
mvn clean install
Use the custom Maven wrapper script - it auto-cleans old reports and opens results:
# Run all tests with Firefox (default) + auto-open report
./mvn-wrapper.sh test
# Run with Chrome + auto-open report
./mvn-wrapper.sh test-chrome
# Run in headless mode + auto-open report
./mvn-wrapper.sh test-headless
# Just open the latest report (without running tests)
./mvn-wrapper.sh report
# Show all available commands
./mvn-wrapper.sh help| Command | Description |
|---|---|
./mvn-wrapper.sh test |
Run all tests (Firefox) + open report |
./mvn-wrapper.sh test-chrome |
Run with Chrome + open report |
./mvn-wrapper.sh test-firefox |
Run with Firefox + open report |
./mvn-wrapper.sh test-headless |
Run in headless mode + open report |
./mvn-wrapper.sh test-only |
Run tests WITHOUT opening report |
./mvn-wrapper.sh report |
Open the latest test report |
./mvn-wrapper.sh clean |
Clean project and old reports |
./mvn-wrapper.sh compile |
Compile project only |
./mvn-wrapper.sh install |
Install all dependencies |
mvn clean test# Run login tests (6 tests)
mvn test -Dtest=LoginTest
# Run product tests (8 tests)
mvn test -Dtest=ProductTest
# Run cart tests (17 tests)
mvn test -Dtest=CartTest# Run specific login test
mvn test -Dtest=LoginTest#testSuccessfulLogin
# Run specific product test
mvn test -Dtest=ProductTest#testSortProductsLowToHigh
# Run specific cart test
mvn test -Dtest=CartTest#testAddItemToCart# Firefox (default, headless)
mvn test
# Chrome
mvn test -Dbrowser=chrome
# Edge
mvn test -Dbrowser=edge
# Safari
mvn test -Dbrowser=safariReports automatically open when using mvn-wrapper.sh commands.
Manual opening:
# Open latest report (after cleaning, only one exists)
open test-output/reports/TestReport_*.html
# Or use the wrapper
./mvn-wrapper.sh reportmvn clean compilemvn clean installmvn test -Xexport PATH="/opt/homebrew/opt/openjdk@11/bin:$PATH"
mvn test# View ExtentReports
open test-output/reports/TestReport_*.html
# View TestNG reports
open target/surefire-reports/index.html
# List all reports
ls -la test-output/reports/# Quick test run
mvn test -Dtest=SimpleTestRunner
# Full test suite with Chrome
mvn test -Dbrowser=chrome
# Headless testing
mvn test -Dbrowser=chrome -Dheadless=true
# Parallel execution
mvn test -Dparallel=methods -DthreadCount=2This framework tests SauceDemo (https://www.saucedemo.com), a fully-featured e-commerce application designed for test automation practice.
- standard_user - Standard user with full access
- locked_out_user - User that has been locked out
- problem_user - User experiencing problems (images, sorting)
- performance_glitch_user - User with performance issues
- Password for all users:
secret_sauce
Total: 31 Comprehensive Tests across 3 core areas
- β Successful login with valid credentials
- β Login failure with invalid username
- β Login failure with invalid password
- β Login failure with empty credentials
- β Login failure with empty password
- β Locked out user validation
- β Verify all products are displayed
- β Sort products A to Z
- β Sort products Z to A
- β Sort products by price (low to high)
- β Sort products by price (high to low)
- β Verify specific product details
- β Add single product to cart
- β Add multiple products to cart
- β Access cart page
- β Verify empty cart
- β Verify items appear in cart after adding
- β Verify multiple items in cart
- β Remove items from cart
- β Continue shopping functionality
- β Verify item quantities
- β Verify item prices in cart
- β Add/remove multiple items workflow
- β Cart badge count validation
- β Cart state persistence
- β Item details in cart
- β Remove last item from cart
- β Multiple additions/removals
- β Cart navigation
- β Product to cart integration
- β Complete cart workflow
The framework supports .env files for managing sensitive data like passwords, API keys, and credentials:
# Create your .env file
cp .env.example .env
# Edit with your values
nano .envAvailable in .env:
- User credentials (passwords, API keys)
- Database credentials
- Remote execution configuration (BrowserStack, Sauce Labs)
- Email/Slack notifications
- Cloud service credentials (AWS, etc.)
See Environment Setup Guide for complete documentation.
Edit src/test/resources/config/config.properties for non-sensitive settings:
- Application URL (default: https://www.saucedemo.com)
- Browser settings
- Timeouts
- Report settings
Priority: .env values override config.properties values.
After running tests, reports will be generated in:
- ExtentReports:
test-output/reports/TestReport_[timestamp].html - Screenshots:
test-output/screenshots/ - TestNG Reports:
test-output/
- Create a new page class extending
BasePage(PageFactory handled by BasePage) - Add page elements using
@FindByannotations - Create test methods in test classes
- Update testng.xml to include new test classes
public class NewPage extends BasePage {
@FindBy(id = "elementId")
private WebElement element;
public NewPage(WebDriver driver) {
super(driver); // BasePage handles PageFactory initialization
}
public void performAction() {
clickElement(element);
}
}@Test(description = "Test description")
public void testMethod() {
try {
WebDriver driver = WebDriverConfig.getDriver();
// Test steps
ExtentReportManager.logInfo("Test step executed");
Assert.assertTrue(condition, "Assertion message");
ExtentReportManager.logPass("Test passed");
} catch (Exception e) {
ExtentReportManager.logFail("Test failed: " + e.getMessage());
throw e;
}
}
@AfterMethod
public void tearDown() {
WebDriverConfig.quitDriver(); // Always use quitDriver()
}Use ExcelUtils class to read/write Excel files:
List<Map<String, String>> testData = ExcelUtils.readExcelData("testdata.xlsx", "Sheet1");Place JSON test data files in src/test/resources/testdata/ directory.
- Use Page Object Model - Keep page logic separate from test logic
- Use explicit waits - Avoid Thread.sleep()
- Take screenshots on test failures
- Use meaningful test names and descriptions
- Keep tests independent - Each test should be able to run standalone
- Use configuration files - Avoid hardcoding values
- Clean up resources - Always quit WebDriver in @AfterMethod
-
WebDriver not found
- Ensure browser is installed
- Check WebDriverManager setup
-
Tests failing
- Check element locators
- Verify application is accessible
- Check timeout settings
-
Reports not generating
- Ensure test-output directory exists
- Check ExtentReportManager initialization
- Follow existing code structure
- Add proper documentation
- Include test cases for new features
- Update README if needed
| Command | Description |
|---|---|
./mvn-wrapper.sh test |
Run all tests (Firefox) + auto-open report |
./mvn-wrapper.sh test-chrome |
Run with Chrome + auto-open report |
./mvn-wrapper.sh test-firefox |
Run with Firefox + auto-open report |
./mvn-wrapper.sh test-headless |
Run in headless mode + auto-open report |
./mvn-wrapper.sh test-only |
Run tests WITHOUT opening report |
./mvn-wrapper.sh report |
Open the latest test report only |
./mvn-wrapper.sh clean |
Clean project and old reports |
./mvn-wrapper.sh compile |
Compile project only |
./mvn-wrapper.sh install |
Install all dependencies |
./mvn-wrapper.sh help |
Show all available commands |
| Command | Description |
|---|---|
mvn clean test |
Clean and run all tests |
mvn test |
Run all tests |
mvn test -Dtest=LoginTest |
Run specific test class |
mvn test -Dtest=LoginTest#testSuccessfulLogin |
Run specific test method |
mvn test -Dbrowser=chrome |
Run with Chrome browser |
mvn test -Dbrowser=firefox |
Run with Firefox browser (default) |
mvn test -Dbrowser=edge |
Run with Edge browser |
mvn clean install |
Install dependencies |
mvn clean compile |
Clean and compile only |
mvn test -X |
Run with debug information |
| Variable | Description | Example |
|---|---|---|
JAVA_HOME |
Java installation path | /opt/homebrew/opt/openjdk@21 |
PATH |
Include Java bin directory | export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH" |
MAVEN_OPTS |
Maven JVM options | -Xmx1024m |
| Report Type | Location | Description |
|---|---|---|
| ExtentReports | test-output/reports/ |
Beautiful HTML reports with screenshots |
| TestNG Reports | target/surefire-reports/ |
Standard TestNG test results |
| Screenshots | test-output/screenshots/ |
Test failure screenshots |
| Logs | logs/ |
Application and test logs |
| Property | Description | Default |
|---|---|---|
app.url |
Application base URL | https://www.google.com |
browser.name |
Default browser | chrome |
app.timeout |
Global timeout | 30 |
app.implicit.wait |
Implicit wait time | 10 |
browser.headless |
Headless mode | false |
browser.maximize |
Maximize window | true |
-
Navigate to project directory
cd "Java Selenium Framework"
-
Install dependencies (first time only)
./mvn-wrapper.sh install
-
Run all tests (auto-opens report)
./mvn-wrapper.sh test
That's it! The framework will:
- β Clean old reports
- β Run all 31 tests with Firefox (headless)
- β Generate HTML report with screenshots
- β Automatically open the report in your browser
# Run specific test class during development
mvn test -Dtest=LoginTest
# Run specific test method
mvn test -Dtest=LoginTest#testSuccessfulLogin
# Run without auto-opening report
./mvn-wrapper.sh test-only
# Open latest report manually
./mvn-wrapper.sh report# Run tests in headless mode (default)
./mvn-wrapper.sh test-headless
# Or use Maven directly
mvn clean test# Firefox (default, headless)
./mvn-wrapper.sh test
# Chrome
./mvn-wrapper.sh test-chrome
# Different browser with Maven
mvn test -Dbrowser=edge
mvn test -Dbrowser=safariThis project is for educational and testing purposes.