Automated UI test suite using Selenium WebDriver and JUnit 5. Built with the Page Object Model (POM) pattern. Java/Maven port of python-selenium-testing.
- Java 17+
- Maven 3.8+
No browser or driver pre-installation required. Selenium Manager (bundled with selenium-java 4.6+) automatically downloads Chrome for Testing (or Firefox) and the matching WebDriver binary on first run.
-
Clone the repository and navigate into it:
git clone <repo-url> cd java-selenium-testing
-
Copy the example env file and fill in your values:
cp .env.example .env
-
Edit
.envwith your target URL and credentials (see Configuration). -
Install dependencies (downloads all Maven dependencies):
mvn dependency:resolve
Copy .env.example to .env and set the following values:
| Variable | Description |
|---|---|
BASE_URL |
Base URL of the application under test |
BROWSER |
chrome (default) or firefox |
IMPLICIT_WAIT |
Element wait timeout in seconds (default: 10) |
PAGE_LOAD_TIMEOUT |
Page load timeout in seconds (default: 30) |
LOGIN_USERNAME |
Username for standard user login |
LOGIN_PASSWORD |
Password for standard user login |
SSN |
SSN used during account linking |
PIN_1 |
First PIN field value |
PIN_2 |
Second PIN field value |
ADMIN_LOGIN_USERNAME |
Username for admin login |
ADMIN_LOGIN_PASSWORD |
Password for admin login |
Compile the project without running tests:
mvn compile test-compilemvn testmvn test -Dheadless=truemvn test -Dbrowser=firefoxmvn test -Dbrowser=firefox -Dheadless=truemvn test -Dtest=TestLoginmvn test -Dtest=TestLogin#testLinkUnlinkUserTest results are written to target/surefire-reports/.
java-selenium-testing/
├── .env.example # Template for environment variables
├── .gitignore
├── README.md
├── pom.xml # Maven build file and dependencies
└── src/
└── test/
└── java/
└── com/example/selenium/
├── config/
│ └── Config.java # Loads .env and exposes config constants
├── pages/
│ ├── BasePage.java # Shared Selenium helpers (find, click, type, etc.)
│ └── LoginPage.java # Page Object for the login/admin flows
└── tests/
├── BaseTest.java # JUnit lifecycle: creates/destroys WebDriver
└── TestLogin.java # Test: link account, logout, admin unlink, logout
| File | Purpose |
|---|---|
Config.java |
Single source of truth for all config values. Reads .env via dotenv-java; -Dbrowser and -Dheadless system properties override the .env values. |
BasePage.java |
Abstract base class providing reusable wrappers around WebDriverWait and ExpectedConditions (presence, visibility, clickability). |
LoginPage.java |
Concrete Page Object containing all locators and action methods for the login, linking, and admin flows. |
BaseTest.java |
JUnit 5 base class. @BeforeEach creates the WebDriver instance (Chrome or Firefox, optionally headless); @AfterEach calls driver.quit(). Equivalent to pytest's conftest.py. |
TestLogin.java |
JUnit 5 test class with a single test: logs in as a user, links an account, logs out, logs in as admin, unlinks the account, and logs out again. |
| Library | Version | Purpose |
|---|---|---|
selenium-java |
4.18.0 | WebDriver browser automation; bundles Selenium Manager for automatic browser + driver downloads |
junit-jupiter |
5.10.2 | Test framework |
dotenv-java |
3.0.0 | Load .env configuration file |