An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

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

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.

![Jenkins build](https://github.com/user-attachments/assets/b8b689ec-7845-4a04-9bf9-bc15e65e1fab)

![Jenkins Blue Ocean](https://github.com/user-attachments/assets/5e5cfff0-d6a1-4a5f-af2b-af5c84bc445d)

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

---
[![GitHub stars](https://img.shields.io/github/stars/Ritik-Saxena/selenium-pom-junit?style=social)](https://github.com/Ritik-Saxena/selenium-pom-junit)
[![GitHub followers](https://img.shields.io/github/followers/Ritik-Saxena?style=social)](https://github.com/Ritik-Saxena?tab=followers)
[![GitHub forks](https://img.shields.io/github/forks/Ritik-Saxena/selenium-pom-junit?style=social)](https://github.com/Ritik-Saxena/selenium-pom-junit)
[![GitHub watchers](https://img.shields.io/github/watchers/Ritik-Saxena/selenium-pom-junit?style=social)](https://github.com/Ritik-Saxena/selenium-pom-junit)