Skip to content

dvackermandev/java-selenium-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-selenium-testing

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.


Requirements

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


Installation

  1. Clone the repository and navigate into it:

    git clone <repo-url>
    cd java-selenium-testing
  2. Copy the example env file and fill in your values:

    cp .env.example .env
  3. Edit .env with your target URL and credentials (see Configuration).

  4. Install dependencies (downloads all Maven dependencies):

    mvn dependency:resolve

Configuration

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

Building

Compile the project without running tests:

mvn compile test-compile

Running Tests

Run all tests (default: Chrome, headed)

mvn test

Run in headless mode

mvn test -Dheadless=true

Run with Firefox

mvn test -Dbrowser=firefox

Run with Firefox in headless mode

mvn test -Dbrowser=firefox -Dheadless=true

Run a specific test class

mvn test -Dtest=TestLogin

Run a specific test method

mvn test -Dtest=TestLogin#testLinkUnlinkUser

Test results are written to target/surefire-reports/.


Project Structure

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

Key components

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.

Dependencies

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages