A Selenium WebDriver + Cucumber BDD + TestNG + Page Object Model framework for testing SauceDemo.
Designed for maintainability, readability, and parallel execution across multiple browsers.
Note: Built with the latest stable versions of all tools and libraries available at the time of publishing (Java 25 LTS, Selenium 4.45.0, Cucumber 7.34.3, etc.).
| Tool | Version |
|---|---|
| Java | 25 |
| Selenium WebDriver | 4.45.0 |
| Cucumber (Java, TestNG, PicoContainer) | 7.34.3 |
| TestNG | 7.12.0 |
| Log4j2 | 2.26.0 |
| Extent Reports (Cucumber 7 Adapter) | 1.14.0 |
| Apache Commons IO | 2.22.0 |
| Maven Surefire | 3.5.6 |
- BDD with Gherkin — Feature files written in plain English, easy for non-technical stakeholders
- Page Object Model — Reusable page classes with encapsulated locators and actions
- Multi-browser support — Chrome, Edge, and Firefox
- Parallel execution — Thread-safe WebDriver management via
ThreadLocal - Headless mode — Configurable via
config.properties - Selenium Grid — Run remotely against a Selenium Grid hub
- Rich reporting — Extent Spark HTML report with base64 screenshots, plus Cucumber HTML report
- Screenshot on failure — Automatically captures screenshots for failed scenarios
- Failed scenario rerun — Rerun only failed scenarios using the
FailedTestRunner - Logging — Log4j2 with SLF4J, output to
logs-report.log - Configurable waits — Centralized explicit wait strategies (visible, present, clickable)
src/
├── main/java/com/qa/automation/
│ ├── enums/
│ │ ├── ConfigProp.java # Property keys for config.properties
│ │ └── WaitStrategy.java # VISIBLE, PRESENT, CLICKABLE, NONE
│ ├── factories/
│ │ ├── BrowserFactory.java # Creates Chrome/Edge/Firefox drivers
│ │ ├── DriverFactory.java # Thread-safe WebDriver management
│ │ └── ExplicitWaitFactory.java # Centralized wait strategy application
│ ├── pageobjects/
│ │ ├── LoginPage.java # Login page locators & actions
│ │ └── HomePage.java # Home page locators & actions
│ └── utilities/
│ ├── ConfigUtil.java # Reads config.properties
│ ├── ConstantUtil.java # Project-wide constants
│ ├── ElementUtil.java # Base class with reusable element methods
│ └── ScreenshotUtil.java # Screenshot capture & attachment
├── main/resources/
│ └── log4j2.xml # Log4j2 configuration
└── test/
├── java/
│ ├── runners/
│ │ ├── DefaultTestRunner.java # Primary runner (all scenarios)
│ │ └── FailedTestRunner.java # Rerun failed scenarios
│ └── stepdefs/
│ ├── Hooks.java # Before/After scenario hooks
│ ├── LoginStepDef.java # Login scenario steps
│ └── HomeStepDef.java # Home page verification steps
└── resources/
├── features/
│ └── LoginTest.feature # Gherkin scenarios
├── config.properties # Framework configuration
├── extent.properties # Extent Report configuration
├── testng.xml # TestNG suite
└── testng-retry-failed.xml # Suite with failed rerun
The LoginTest.feature file covers 7 test cases across 5 scenario outlines:
| Scenario | Browser | Tags |
|---|---|---|
| Successful login — standard_user | Chrome | @smoke @core @tester1 |
| Locked out user — error message | Edge | @regression @core @extended @tester2 |
| Invalid username — error message | Firefox | @regression @core @extended @tester3 |
| Invalid password — error message | Chrome | @regression @core @extended @tester3 |
| Empty password — error message (deliberately fails) | Edge | @sanity @extended @tester4 |
| Empty username — error message | Firefox | @sanity @extended @tester4 |
| Verify list of accepted usernames | Chrome | @smoke @extend @tester5 |
- Java 25+
- Maven 3.9+
- Chrome, Edge, and/or Firefox browsers (with matching WebDriver binaries on PATH)
git clone <repo-url>
cd selenium-bdd-pomEdit src/test/resources/config.properties:
RUN_MODE=local # local | selenium_grid
BROWSER_HEADLESS=yes # yes | no
BROWSER_HEIGHT=1920
BROWSER_WIDTH=1080
PAGE_LOAD_TIMEOUT_TIMER=30
EXPLICIT_WAIT_TIMER=15Run all scenarios:
mvn clean testRun with a specific tag filter (uncomment the cucumber.filter.tags parameter in testng.xml):
mvn clean test -Dcucumber.filter.tags="@smoke"Rerun failed scenarios (after a prior run generated cucumber-failed-scenarios.txt):
mvn clean test -Dsurefire.suiteXmlFiles=src/test/resources/testng-retry-failed.xmlAfter execution, the following reports are generated:
| Report | File |
|---|---|
| Extent Spark Report | extent-spark-report.html |
| Cucumber HTML Report | cucumber-report.html |
| Rerun Failed HTML Report | cucumber-rerun-failed-report.html |
| Surefire HTML Report | target/surefire-reports/index.html |
| Surefire XML Results | target/surefire-reports/testng-results.xml |
Feature Files (Gherkin)
↓
Step Definitions (glue code)
↓
Page Objects (LoginPage, HomePage) ──extends── ElementUtil
↓
ExplicitWaitFactory ──uses── WaitStrategy
↓
DriverFactory (ThreadLocal<WebDriver>)
↓
BrowserFactory (local / selenium_grid)
↓
config.properties ──reads── ConfigUtil
ScreenshotUtil ──attaches── Cucumber Scenario
Log4j2 ──logs── logs-report.log
Extent Reports ──generates── extent-spark-report.html
TestNG ──parallel execution── testng.xml
Maven Surefire ──triggers── build lifecycle
- SauceDemo — the test application
- Selenium — browser automation
- Cucumber — BDD framework
- Extent Reports — test reporting