Skip to content

About

Java + Selenium WebDriver test automation framework (POM, TestNG, Maven) covering alerts, iFrames, dropdowns, waits, file upload, and window/tab handling — built via Test Automation University.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selenium Automation Testing

A Java-based UI test automation framework built while learning Selenium WebDriver through Test Automation University. The project covers a wide range of real browser interaction patterns using the Page Object Model, TestNG, and Maven.

Test site: The Internet (Herokuapp) — a purpose-built site for practicing browser automation across common UI patterns.


Tech Stack

Tool Purpose
Java Primary language
Selenium WebDriver 4.x Browser automation
TestNG Test framework — lifecycle hooks, assertions, reporting
Maven Build tool and dependency management
ChromeDriver Chrome browser driver (auto-managed via Selenium 4)

Project Structure

src/
├── main/java/
│   ├── Pages/          # Page Object classes — one class per page
│   └── utils/          # Shared utilities (WindowManager)
└── test/java/
    ├── base/           # BaseTests — driver setup, teardown, screenshot on failure
    ├── alerts/         # JS Alert, Confirm, Prompt tests
    ├── DropDown/       # Dropdown selection + multi-select via JS injection
    ├── frames/         # iFrame and nested frame interaction
    ├── hover/          # Mouse hover via Actions class
    ├── JavaScript/     # JavascriptExecutor — scroll, infinite scroll, DOM manipulation
    ├── Keys/           # Keyboard input — special keys and key combinations
    ├── login/          # Form authentication
    ├── Navigation/     # Tab switching, back/forward/refresh navigation
    ├── Slider/         # Horizontal slider via arrow keys
    └── Wait/           # Explicit and Fluent wait strategies

Architecture

BaseTests

All test classes extend BaseTests, which handles:

  • Driver initialization with @BeforeClass — one ChromeDriver instance per test class
  • Reset to home with @BeforeMethod — navigates back to the base URL before every test, preventing state bleed between tests
  • Teardown with @AfterClass — calls driver.quit() to close the browser and release ChromeDriver
  • Screenshot on failure with @AfterMethod — automatically captures a screenshot if a test fails and saves it to resource/Screenshots/

Page Object Model (POM)

Each page of the test site has a dedicated class in Pages/. Page classes:

  • Own all locators (By fields) for that page
  • Expose methods for actions (click, input, retrieve text)
  • Return the next page object when navigation occurs — enabling method chaining in tests
  • Receive the WebDriver instance via constructor — no static driver, clean dependency injection

Test classes stay thin — they call page methods and assert results. Locator changes only need to be updated in one place.

WindowManager

A utility class that wraps WebDriver.Navigation and window handle management, exposing cleaner methods (goBack(), switchTab(title)) instead of raw driver calls in test code.


What's Covered

Locating Elements

  • By.id, By.cssSelector, By.xpath, By.linkText, By.className, By.tagName
  • findElement() vs findElements() — single element vs list

User Interactions

  • click(), sendKeys(), getText(), getAttribute(), clear()
  • Keyboard keys via Keys class — Keys.BACK_SPACE, Keys.ARROW_RIGHT, Keys.chord() for combinations
  • File upload via sendKeys(absoluteFilePath) — bypasses OS file picker

Actions Class

  • moveToElement() — hover
  • contextClick() — right click
  • Method chaining with .perform()

Dropdowns

  • Select class — selectByVisibleText(), getAllSelectedOptions()
  • Multi-select enabled at runtime via JavascriptExecutor attribute injection

Alerts

  • switchTo().alert() — JS Alert, Confirm, and Prompt
  • accept(), dismiss(), getText(), sendKeys()

Frames & iFrames

  • switchTo().frame(name) — enter frame context
  • switchTo().parentFrame() — return to parent frame
  • Nested frame traversal — enter top frame, then child frame, return correctly

Windows & Navigation

  • getWindowHandles() — iterate open tabs
  • switchTo().window(handle) — switch by title match
  • navigate().back(), .forward(), .refresh(), .to(url)

JavaScript Executor

  • scrollIntoView() — scroll to element
  • window.scrollTo() — page-level scroll for infinite scroll trigger
  • DOM attribute manipulation — setAttribute('multiple', '') on dropdown

Wait Strategies

  • Explicit Wait (WebDriverWait) — wait for a specific ExpectedCondition
  • Fluent Wait — configurable polling interval and exception ignoring during wait period

Screenshots

  • TakesScreenshot cast — captures OutputType.FILE on test failure
  • Saved automatically to resource/Screenshots/{testName}.png

Running the Tests

Prerequisites: Java 17+, Maven, Chrome browser installed

# Clone the repo
git clone https://github.com/AnantNegi04/Selenium_automation_testing.git
cd Selenium_automation_testing

# Run all tests
mvn test

# Run a specific test class
mvn test -Dtest=LoginTests

# Run a specific test method
mvn test -Dtest=AlertsTests#testAcceptAlert

Key Patterns Demonstrated

Returning page objects from navigation methods

// Test reads like a user story
LoginPage loginPage = homePage.clickFormAuthenticationLink();
loginPage.setUserName("tomsmith");
loginPage.setPassword("SuperSecretPassword!");
SecureAreaPage secureArea = loginPage.clickLoginButton();
assertTrue(secureArea.getHeaderText().contains("You logged into a secure area!"));

Fluent Wait for dynamic content

FluentWait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(10))
    .pollingEvery(Duration.ofSeconds(1))
    .ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.presenceOfElementLocated(loadedText));

JavascriptExecutor for DOM manipulation

String script = "arguments[0].setAttribute('multiple', '')";
((JavascriptExecutor)driver).executeScript(script, findDropdownOption());

Notes

  • DropDown.java and DropDownPage.java are two separate implementations of the same page — DropDown.java is the earlier version, DropDownPage.java is the extended version with multi-select and JS injection support
  • Event listener implementation was skipped — EventFiringWebDriver was deprecated and removed in Selenium 4; the Selenium 4 equivalent uses WebDriverListener interface with EventFiringDecorator
  • DynamicLoadingExample1Page shows both WebDriverWait (commented out) and FluentWait implementations side by side for comparison

Built as part of a structured learning path toward SDET roles. Next phase: applying this framework to a real-world application.

About

Java + Selenium WebDriver test automation framework (POM, TestNG, Maven) covering alerts, iFrames, dropdowns, waits, file upload, and window/tab handling — built via Test Automation University.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages