A practical test automation lab using Java 17+, Selenium 4, Cucumber (JVM), and Maven.
Built for UI, API, and DB examples with clean packages and runtime configuration.
QASmartTestLab/
├─ src
│ └─ test
│ ├─ java
│ │ └─ com.qasmarttestlab
│ │ ├─ config/
│ │ ├─ pages/
│ │ │ ├─ LoginPage.java
│ │ │ └─ ResultsPage.java
│ │ ├─ runners/
│ │ │ └─ RunCucumberTest.java
│ │ ├─ stepdefs/
│ │ │ ├─ apiStepdefs/
│ │ │ ├─ common/
│ │ │ │ └─ Hooks.java
│ │ │ ├─ dbStepdefs/
│ │ │ └─ uiStepdefs/
│ │ │ ├─ LoginSteps.java
│ │ │ └─ UiStepDefs.java
│ │ └─ support/
│ │ └─ DriverFactory.java
│ └─ resources
│ ├─ features/
│ │ ├─ apiFeatures/
│ │ ├─ dbFeatures/
│ │ └─ uiFeatures/
│ │ └─ login.feature
│ ├─ testdata/
│ ├─ config.properties
│ └─ junit-platform.properties
├─ pom.xml
└─ README.md
Names matter: Packages in code are
com.qasmarttestlab.*(match this in new classes).
- Java 17+
- Maven 3.9+
- Selenium 4.x (WebDriver + typed Options)
- Cucumber 7.x (JUnit 5 platform)
- Optional: Selenium Grid/Selenoid (remote runs)
src/test/resources/config.properties — put environment-specific values here (baseUrl, creds used for demo/test, etc.).
Runtime -D properties (picked up by DriverFactory):
| Property | Default | Notes |
|---|---|---|
browser |
chrome | chrome | firefox | edge |
headless |
false | true/false |
selenium.remote |
— | e.g. http://localhost:4444/wd/hub |
timeout.pageLoad.sec |
60 | numeric |
timeout.script.sec |
30 | numeric |
timeout.implicit.sec |
0 | keep at 0; use explicit waits |
pageLoadStrategy |
normal | normal | eager | none |
src/test/resources/junit-platform.properties should include your Cucumber glue & plugin defaults, for example:
junit.jupiter.execution.parallel.enabled=false
cucumber.execution.parallel.enabled=true
cucumber.execution.parallel.config.strategy=dynamic
cucumber.glue=com.qasmarttestlab
cucumber.plugin=pretty, html:target/cucumber-report.html, json:target/cucumber-report.json, junit:target/cucumber-junit.xml, summary
cucumber.publish.quiet=true
cucumber.filter.tags=not @ignore
cucumber.snippet-type=camelcase
mvn clean testmvn clean test -Dbrowser=firefox -Dheadless=truemvn clean test -Dselenium.remote=http://localhost:4444/wd/hub -Dbrowser=chrome -Dheadless=trueAdd tags in feature files (e.g., @ui @smoke) and pass:
mvn clean test -Dcucumber.filter.tags="@ui and @smoke"Cucumber picks these via
cucumber.filter.tags(JUnit Platform property). You can also move that intojunit-platform.properties.
-
Open project (Maven imports
pom.xml). -
Ensure Project SDK = 17+.
-
Run
com.qasmarttestlab.runners.RunCucumberTest(JUnit run config). -
(Optional) Add VM options for runtime flags:
-Dbrowser=chrome -Dheadless=true -DpageLoadStrategy=eager
-
Pages in
com.qasmarttestlab.pagesencapsulate locators & actionsLoginPage,ResultsPage, etc. -
UI StepDefs in
com.qasmarttestlab.stepdefs.uiStepdefscall page methods. -
Common Hooks in
com.qasmarttestlab.stepdefs.common.Hookshandle lifecycle:@Before→ create driver, navigate tobaseUrl@After→ screenshot on failure, quit driver
Make sure Hooks call:
DriverFactory.create();
WebDriver driver = DriverFactory.get();and:
DriverFactory.tearDown();src/test/resources/features/uiFeatures/login.feature
Feature: Login
As a user
I want to sign in
So that I can see my account
@happy
Scenario: Valid login
Given I am on the login page
When I sign in with credentials: "tomsmith" and password: "SuperSecretPassword!"
Then I should see a "You logged into a secure area!" message- Keep implicit wait = 0 and use explicit waits in page methods.
- Put test data under
src/test/resources/testdata/. - Use tags (
@ui,@api,@db,@smoke,@regression) to slice suites. - For remote runs, pass the same
*Options(headless, acceptInsecureCerts) toRemoteWebDriver.
- Surefire/JUnit output:
target/surefire-reports/ - Cucumber HTML:
target/cucumber-report.html - Cucumber JSON:
target/cucumber-report.json
(You can add Allure or net.masterthought:cucumber-reporting if you want richer reporting.)
- CDP version warnings (Chrome x not matched): Harmless unless using DevTools APIs. Pin to a supported Chrome (Chrome for Testing) or update Selenium when the matching
selenium-devtools-v<major>is released. MalformedURLExceptionfor remote URL: Validate-Dselenium.remoteand wrapnew URL(...)with a helpful message.- Driver leaks: Ensure
HookscallDriverFactory.destroy()in@After.
- Fork the repo
- Create a feature branch
- Add/adjust tests and docs
- Open a PR
MIT