This project automates the login functionality tests for the OrangeHRM demo site using Selenium, TestNG, Java, and integrates video screen recording for each test execution. The tests cover valid and invalid login scenarios, verifying the behavior of the application under different conditions. The tests cover valid and invalid Admin scenarios, verifying the behavior of the application under different conditions. The tests cover valid Info scenarios, verifying the behavior of the application under different conditions. Additionally, the project features logging with Log4j and test reporting with Allure to track execution results Recently, a Directory Scrolling Functionality was added to dynamically load and extract all employee names from the directory using JavaScript scrolling techniques. The extracted data is then saved to an Excel file using the ExcelUtilis class.
Before you start running the automation tests, make sure you have the following software installed:
- Java (JDK 8 or higher) - Download here
- Maven - Download here
- Selenium WebDriver - Download here
- TestNG - Integrated via Maven dependency
- Allure Framework - Installation Guide
- Log4j - For logging, included as a Maven dependency
- JavaCV - For video recording during tests, included as a Maven dependency
- Browser Drivers (e.g., ChromeDriver, GeckoDriver) - ChromeDriver Download
- Selenium: For web automation, controlling the browser during tests.
- TestNG: For test management and execution.
- Java: Programming language used to write test scripts.
- Allure: For generating beautiful, interactive test reports.
- Log4j: For logging, helping track test execution and debugging.
- JavaCV: For recording videos of the tests in MP4 format (useful for debugging).
- Apache POI: For reading and writing Excel files.
- Apache Commons CSV: For handling CSV file operations.
- JavaScriptExecutor: For executing JavaScript commands to handle dynamic web elements.
- LoginTest.java: Contains test cases for logging in with both valid and invalid credentials.
- WebDriverFactory.java: Provides methods to initialize and configure WebDriver instances based on the browser and mode specified.
- ReuseTests folder: Includes reusable components like listeners, base classes, configuration loaders, and screen recording utilities.
- Configuration File (config.properties): Stores the configuration settings such as URL, browser preferences, and login credentials.
- OrangeHRMScript.xml: Defines the suite and test cases to be executed.
If any settings need to be handled by environment variables (e.g., for CI/CD), make sure to mention it explicitly.
## Environment Variables
For sensitive information such as credentials or specific configurations, you can override settings using environment variables.
Example:
- `LOGIN_USERNAME`: Override the valid login username.
- `LOGIN_PASSWORD`: Override the valid login password.
The config.properties
file contains settings for running the tests, such as the application URL, browser preferences, and login credentials.
-
URL Configuration
url
: The URL of the OrangeHRM demo site.
-
Browser Settings
browser
: Specifies the browser for running tests. Options available:- Chrome
- Firefox
- Edge
mode
: Specifies the browser's operational mode. Options include:- headless (No UI, useful for CI/CD environments)
- incognito (Runs the browser in incognito mode)
-
Credentials
- Valid Credentials: Used for successful login scenarios.
username
: The valid username.password
: The valid password.
- Invalid Credentials: Used to simulate unsuccessful login attempts.
Invalidusername
: Invalid username.Invalidpassword
: Invalid password.
- Valid Credentials: Used for successful login scenarios.
-
Login with Invalid Credentials:
- This test case simulates an invalid login attempt by using invalid credentials (username and password).
- It checks if the application correctly handles the failed login scenario.
-
Login with Valid Credentials:
- This test case checks the behavior when valid credentials are provided.
- It validates that after a successful login, the user is correctly redirected, and the company name and user information are displayed.
The WebDriverFactory.GetWebDriver
class is responsible for launching the browser and setting up the WebDriver based on the browser and operational mode specified in the configuration. It supports multiple browsers (Chrome, Firefox, Edge) and various modes such as headless and incognito.
Logging is managed using Log4j. The logs are stored in the ./logs/application.log
file. These logs help track test execution steps and assist in debugging failed tests.
The project integrates Allure for generating interactive, visually appealing reports. After each test, the AllureLog4jListener listens for log events and attaches the logs to the Allure report. This provides detailed insights into the execution results.
ScreenRecorderUtil captures the screen and records it during the execution of tests. The videos are saved in MP4 format and encoded with the H.264 codec using JavaCV. This feature is especially useful for debugging and reviewing test executions.
The testng.xml
file is used to define the suite and the individual test cases to be executed. The file includes the following:
- Listeners: Allure and Log4j listeners are included for reporting and logging.
- Test Classes: Contains test classes for login, directory, and admin functionalities.
The CSVDataDriven
class provides utility methods for reading data from a CSV file. This class is designed to facilitate data-driven testing by allowing tests to be executed with different sets of input data stored in a CSV file.
- Read CSV Data: Reads data from the provided CSV file and returns it as a list of arrays.
- Get Specific Line: Retrieves a specific line of data from the CSV based on the line number.
This class supports flexible handling of CSV files, allowing you to parameterize tests with various input data.
The ExcelUtilis
class offers methods to interact with Excel files. It provides functionality to both write and read data in Excel format, making it useful for managing test data and storing results.
- Write Data to Excel: Adds data from a map of column names and values into a newly created Excel file.
- Extract Data from Excel: Reads data from an existing Excel file and returns it in a structured format (map of sheet names and their respective data).
This class is beneficial for test scenarios that involve Excel as a source of test data or where results need to be stored in Excel format for later analysis.
This newly added functionality dynamically loads and extracts all employee names
from the Directory
page on the OrangeHRM
demo site.
Since the employee directory is contained within a scrollable container,
the function leverages JavaScriptExecutor to scroll and load all visible names dynamically.
-
Dynamic Scrolling: Uses JavaScriptExecutor to scroll through the employee directory. Continues scrolling until all employee names are fully loaded.
-
Employee Name Extraction: Extracts visible employee names from the scrollable container. Handles duplicates and ensures all names are uniquely collected.
-
Data Export to Excel: Saves all extracted employee names into an Excel file using the ExcelUtilis class. The file is generated in the specified directory for later analysis.
The RetryAnalyzer
class helps manage flaky tests by automatically retrying tests that fail. This is particularly useful in situations where tests may intermittently fail due to non-deterministic issues (e.g., network failures).
- Test Retry Logic: Configures the retry logic for failed tests, retrying them a specified number of times.
- Customizable Retry Count: Allows you to define the maximum number of retries for any test.
By using this class, tests can be more reliable, minimizing the impact of temporary failures and reducing the need for manual intervention when tests fail intermittently.
-
CSVDataDriven: Useful for implementing data-driven tests, where input data is managed in CSV files. This allows tests to be run with various datasets without altering the test code.
-
ExcelUtilis: Ideal for working with Excel files to read test data or save test results, making it easier to manage and analyze large volumes of test data.
-
RetryAnalyzer: Enhances test stability by ensuring that flaky tests are retried automatically, reducing false negatives and making your test suite more robust.
These classes work together to streamline test data management and improve the reliability and efficiency of your automated tests.
Once the setup is complete, you can run the tests using Maven and TestNG.
- Open a terminal/command prompt.
- Navigate to the root directory of the project.
- Run the following command to execute the tests:
mvn clean test
To run a specific test, execute:
Example
mvn -Dtest=LoginTest test
After running the tests, you can generate and view the Allure report by following these steps:
-
Install Allure Commandline:
brew install allure # macOS choco install allure # Windows
-
Generate the report using Maven:
mvn allure:serve
-
Open the generated report in your browser at the provided URL.
Issue: Browser not launching when running tests.
- Solution: Ensure that the correct browser driver (e.g., ChromeDriver or GeckoDriver) is installed and available in your PATH.
Issue: TestNG not executing tests.
- Solution: Verify that your
OrangeHRMScript.xml
file is configured correctly and contains the right test classes.
This automation testing project covers a variety of key functionalities such as:
- Validating login scenarios with both valid and invalid credentials.
- Configuring WebDriver for different browsers and operational modes.
- Capturing logs for test execution and generating interactive reports using Allure.
- Recording videos of test runs for detailed review and debugging.
- Have the ability to dynamically interact with scrollable containers, extract data, and save it.
The project also utilizes reusable components for test organization, making it scalable and easy to extend with additional functionalities.
It is an ideal template for web-based test automation, particularly for teams using Selenium
, TestNG
, and Java
.