Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QASmartTestLab

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.


📦 Project Structure (as in repo)


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).


🧰 Tech Stack

  • Java 17+
  • Maven 3.9+
  • Selenium 4.x (WebDriver + typed Options)
  • Cucumber 7.x (JUnit 5 platform)
  • Optional: Selenium Grid/Selenoid (remote runs)

⚙️ Configuration

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

▶️ How to Run

From Maven (default: Chrome, local)

mvn clean test

Choose browser / headless

mvn clean test -Dbrowser=firefox -Dheadless=true

Remote (Grid/Selenoid)

mvn clean test -Dselenium.remote=http://localhost:4444/wd/hub -Dbrowser=chrome -Dheadless=true

Filter by tags

Add 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 into junit-platform.properties.


🧪 Running in IntelliJ IDEA

  1. Open project (Maven imports pom.xml).

  2. Ensure Project SDK = 17+.

  3. Run com.qasmarttestlab.runners.RunCucumberTest (JUnit run config).

  4. (Optional) Add VM options for runtime flags:

    -Dbrowser=chrome -Dheadless=true -DpageLoadStrategy=eager
    

🧱 Pages & Step Definitions

  • Pages in com.qasmarttestlab.pages encapsulate locators & actions LoginPage, ResultsPage, etc.

  • UI StepDefs in com.qasmarttestlab.stepdefs.uiStepdefs call page methods.

  • Common Hooks in com.qasmarttestlab.stepdefs.common.Hooks handle lifecycle:

    • @Before → create driver, navigate to baseUrl
    • @After → screenshot on failure, quit driver

Make sure Hooks call:

DriverFactory.create();
WebDriver driver = DriverFactory.get();

and:

DriverFactory.tearDown();

🧩 Example Feature (UI)

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

🧼 Recommended Practices

  • 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) to RemoteWebDriver.

🧾 Reports

  • 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.)


🛠 Troubleshooting

  • 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.
  • MalformedURLException for remote URL: Validate -Dselenium.remote and wrap new URL(...) with a helpful message.
  • Driver leaks: Ensure Hooks call DriverFactory.destroy() in @After.

🤝 Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Add/adjust tests and docs
  4. Open a PR

📄 License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages