Skip to content

This Selenium test automation framework follows the Page Object Model (POM) for clean, maintainable tests. It includes handy utilities for waits, elements, logging, screenshots, and data-driven testing. Dynamic waits boost stability, and a regression suite keeps functionality in check. With Jenkins CI/CD, it ensures smooth, efficient automation.

Notifications You must be signed in to change notification settings

Ritik-Saxena/selenium-pom-junit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

selenium logo

Selenium POM using JUnit: Element Interactions

Connect with me on LinkedIn


📝 About the Project

This project is a Selenium-based test automation framework implemented using the Page Object Model (POM) to ensure modularity, reusability, and maintainability of test scripts. It covers UI automation for various web interactions, including login functionality, alerts, drag-and-drop, dropdowns, frames, multiple windows, and web tables.

🔹 Key Features:

  • 🚀 Page Object Model (POM): Ensures a structured and scalable test design.
  • 🛠 Utility-Driven Approach: Uses ElementUtils.java, WaitUtils.java, ExcelUtils.java, LogUtils.java, ScreenshotUtils.java, BrowserUtils.java, and ConfigReader.java for efficient automation.
  • 📊 Data-Driven Testing: Implements ExcelUtils.java to parameterize test data dynamically.
  • 📸 Automated Screenshots: Captures screenshots on test failures using ScreenshotUtils.java.
  • 📝 Logging & Reporting: Uses LogUtils.java to track test execution status.
  • Asynchronous Waits: Implemented dynamic waits in WaitUtils.java to handle element visibility and clickability efficiently.
  • 🔄 Regression Testing: Implemented regression suite to validate existing functionalities after updates.
  • 🏗 CI/CD Integration: Configured Jenkins Pipeline to automate regression test execution.

This framework ensures robust test automation, reduces manual efforts, and integrates seamlessly into CI/CD pipelines for continuous testing. 🚀✅


Folder Structure

selenium-pom/
│── logs/
│   ├── test.log
│── src/
│   ├── main/
│   │   ├── java/
│   │   │   ├── pages/
│   │   │   │   ├── AlertPage.java
│   │   │   │   ├── DragAndDropPage.java
│   │   │   │   ├── DropdownPage.java
│   │   │   │   ├── FramesPage.java
│   │   │   │   ├── LoginPage.java
│   │   │   │   ├── MulipleWindowsPage.java
│   │   │   │   ├── WebTablePage.java
│   │   │   ├── utils/
│   │   │   │   ├── BrowserUtils.java
│   │   │   │   ├── ConfigReader.java
│   │   │   │   ├── ElementUtils.java
│   │   │   │   ├── ExcelUtils.java
│   │   │   │   ├── LogUtils.java
│   │   │   │   ├── ScreenshotUtils.java
│   │   │   │   ├── WaitUtils.java
│   │   ├── resources/
│   │   │   ├── LoginTestData.xlsx
│   │   │   ├── config.properties
│   │   │   ├── log4j2.xml
│   ├── test/
│   │   ├── java/
│   │   │   ├── base/
│   │   │   │   ├── BaseTest.java
│   │   │   ├── tests/
│   │   │   │   ├── RegressionsTestSuite.java
│   │   │   │   ├── AlertTest.java
│   │   │   │   ├── DragAndDropTest.java
│   │   │   │   ├── DropdownTest.java
│   │   │   │   ├── FramesTest.java
│   │   │   │   ├── LoginTest.java
│   │   │   │   ├── MulipleWindowsTest.java
│   │   │   │   ├── WebTableTest.java
│── target/
│   ├── screenshots/
│   │   ├── loginSuccess.png
│── Jenkinsfile
│── pom.xml

Common Automation Test Implementation Points 🚀

These are the common best practices followed across all test cases:

  • Implemented Page Object Model (POM) to maintain modularity and separation of concerns.
  • Utilized explicit waits (WaitUtils) and ElementUtils to ensure elements are properly loaded before interaction.
  • Performed data-driven testing (where applicable) to enhance test coverage and reusability.
  • Implemented assertions to validate expected behaviors for UI elements and actions.
  • Used logging (LogUtils) to track test execution status for better debugging and reporting.
  • Captured screenshots (ScreenshotUtils) for key test scenarios like successful actions or failures.
  • Ensured structured test execution flow by using proper setup methods before each test.
  • Utilized essential utilities (ElementUtils, WaitUtils, ExcelUtils, LogUtils, ScreenshotUtils, BrowserUtils, ConfigReader) to enhance test automation efficiency, ensuring reliable element interactions, explicit waits, data-driven testing, logging, screenshot capturing, and configuration management.

Test Preview

🔑 Login Test

  • Worked with text field interaction using enterUsername() and enterPassword() methods.
  • Performed data parameterization for login credentials using Apache POI via ExcelUtils.
  • Ensured secure credential retrieval via ConfigReader utility for application properties.
  • Validated login functionality for both valid and invalid credentials.
  • Implemented a dynamic test execution flow using data-driven testing via Excel.
  • Ensured proper test reporting using logs and status messages.
LoginTest.mp4

⚠️ Alert Test

  • Automated JavaScript alert handling, including simple, confirmation, and prompt alerts.
  • Used Selenium's alert interface to accept, dismiss, and send text to alerts.
  • Validated alert responses using assertions to ensure expected results.
  • Tested multiple alert behaviors, such as OK and Cancel actions for confirmation alerts.
  • Performed text input automation for JavaScript prompt alerts.
AlertTest.mp4

🖱 Drag And Drop Test

  • Automated drag-and-drop functionality using Selenium’s Actions class.
  • Performed element interactions using Actions class for smooth drag-and-drop execution.
  • Validated UI behavior by simulating user actions programmatically.
DragAndDropTest.mp4

📌 Dropdown Test

  • Automated dropdown selection testing using Selenium’s Select class.
  • Performed dropdown selection using multiple methods:
    • By value
    • By visible text
    • By index
  • Validated selected dropdown options using assertions to ensure correct selection.
  • Created structured and reusable methods for dropdown interactions to improve maintainability.
  • Logged dropdown selection actions using LogUtils for better test tracking.
DropdownTest.mp4

🖼 Frames Test

  • Automated frame handling and switching using Selenium’s switchTo().frame() methods.
  • Ensured proper frame navigation and interactions with embedded elements inside frames..
FramesTest.mp4

🪟 Muliple Windows Test

  • Automated multiple window handling using Selenium’s switchTo().window() methods.
  • Performed dynamic window switching by both tab number and window title.
  • Validated UI behavior by asserting window titles after switching.
  • Implemented efficient window management by allowing selective and bulk window closures.
MultipleWindowsTest.mp4

📊 WebTable Test

  • Automated web table validation by retrieving and verifying column headers dynamically.
  • Extracted table data dynamically for structured and efficient data retrieval.
  • Validated column headers against expected values to ensure correct table structure.
  • Implemented a reusable method to fetch all rows for scalable test cases.
WebTableTest.mp4

Detailed Logs

Implemented custom logging to track test execution, including INFO, ERROR, and WARNING logs. These logs provide visibility into test execution flow, failures, and key actions performed during test runs.

📄 Sample Logs (logs/test.log)

2025-03-05 07:41:48 [main] INFO  utils.LogUtils - [tests.LoginTest.testValidLogin:37] - Login successful: You logged into a secure area!
2025-03-05 07:41:52 [main] INFO  utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:80] - Starting login test with Excel data...
2025-03-05 07:41:54 [main] INFO  utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:94] - Attempting login for user: demo
2025-03-05 07:41:55 [main] ERROR utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:106] - Failed to login!
2025-03-05 07:41:55 [main] INFO  utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:94] - Attempting login for user: tomsmith
2025-03-05 07:41:56 [main] INFO  utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:104] - Login Successful!
2025-03-05 07:41:56 [main] INFO  utils.LogUtils - [tests.LoginTest.testLoginWithExcelData:113] - Excel test completed. Data saved.
2025-03-05 07:42:03 [main] INFO  utils.LogUtils - [tests.LoginTest.testValidLoginAndTakeScreenshot:67] - You logged into a secure area!
2025-03-05 07:42:03 [main] INFO  utils.LogUtils - [tests.LoginTest.testValidLoginAndTakeScreenshot:71] - Login successful: You logged into a secure area!
2025-03-05 07:42:03 [main] INFO  utils.LogUtils - [utils.ScreenshotUtils.takeScreenshot:21] - Screenshot taken successfully!
2025-03-05 07:42:10 [main] INFO  utils.LogUtils - [tests.LoginTest.testInvalidLogin:53] - Login failed as expected: Your username is invalid!
2025-03-05 07:43:10 [main] INFO  utils.LogUtils - [tests.DropdownTest.validateDropdown:31] - Selected dropdown option: Option 1
2025-03-05 07:43:11 [main] INFO  utils.LogUtils - [tests.DropdownTest.validateDropdown:36] - Selected dropdown option: Option 2
2025-03-05 07:43:11 [main] INFO  utils.LogUtils - [tests.DropdownTest.validateDropdown:41] - Selected dropdown option: Option 1

CI/CD Integration using Jenkins

Below are the pipeline stages performed for the project.

  1. Checkout Code: Pulls the latest test scripts from GitHub.
  2. Set Up Dependencies: Runs mvn clean install -DskipTests to set up project dependencies.
  3. Regression Test Execution:
    • Executes mvn test -Dtest=RegressionTestSuite.
    • Runs all test classes listed under RegressionTestSuite.
  4. Reporting and Archiving the artifact:
    • JUnit Test Reporting: Collects test execution results from surefire-reports.
    • Artifact Archiving: Stores test reports for future reference.

Jenkins build

Jenkins Blue Ocean


If you like this repository, do and the repo for more amazing stuff coming soon.


GitHub stars GitHub followers GitHub forks GitHub watchers

About

This Selenium test automation framework follows the Page Object Model (POM) for clean, maintainable tests. It includes handy utilities for waits, elements, logging, screenshots, and data-driven testing. Dynamic waits boost stability, and a regression suite keeps functionality in check. With Jenkins CI/CD, it ensures smooth, efficient automation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages