https://github.com/ritik-saxena/selenium-pom-junit
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.
https://github.com/ritik-saxena/selenium-pom-junit
apachepoi automation automation-framework cicd java jenkins junit4 maven maven-pom selenium selenium-java selenium-webdriver testing
Last synced: 3 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/ritik-saxena/selenium-pom-junit
- Owner: Ritik-Saxena
- Created: 2025-03-05T23:56:22.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-21T00:49:41.000Z (3 months ago)
- Last Synced: 2025-03-21T01:32:22.273Z (3 months ago)
- Topics: apachepoi, automation, automation-framework, cicd, java, jenkins, junit4, maven, maven-pom, selenium, selenium-java, selenium-webdriver, testing
- Language: Java
- Homepage:
- Size: 94.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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**.https://github.com/user-attachments/assets/7bb2c04e-a689-4e82-b700-4e29f1dce158
### β οΈ 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.https://github.com/user-attachments/assets/aa887aa5-ef99-4948-a4d8-d63923d4e7b0
### π± 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.https://github.com/user-attachments/assets/b8e6cf5a-0ab1-4961-a354-29c7352a77e8
### π 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.https://github.com/user-attachments/assets/28531409-6134-440c-8056-0c38c2e1e5b2
### πΌ Frames Test
* Automated **frame handling and switching** using Seleniumβs ```switchTo().frame()``` methods.
* Ensured **proper frame navigation** and interactions with embedded elements inside frames..https://github.com/user-attachments/assets/530b4f11-46e3-4fe3-ba24-669649d9cbbd
### πͺ 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**.https://github.com/user-attachments/assets/5cb11e22-5312-44eb-b84c-25591116ae7b
### π 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.https://github.com/user-attachments/assets/09f8a8f6-96f4-48c8-aa2f-dc5c44ca49dd
## 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.
5. **Reporting and Archiving the artifact:**
* JUnit Test Reporting: Collects test execution results from `surefire-reports`.
* Artifact Archiving: Stores test reports for future reference.

---
If you like this repository, doand
the repo for more amazing stuff coming soon.
---
[](https://github.com/Ritik-Saxena/selenium-pom-junit)
[](https://github.com/Ritik-Saxena?tab=followers)
[](https://github.com/Ritik-Saxena/selenium-pom-junit)
[](https://github.com/Ritik-Saxena/selenium-pom-junit)