Selenium WebDriver is a tool that allows you to automate web browsers using code, making it easier to test web applications and perform repetitive tasks. It supports multiple programming languages like Java, Python, and JavaScript, and works across various browsers such as Chrome, Firefox, and Edge. You can learn more and get started at selenium.dev.
Selenium WebDriver is a programming interface developed by Simon Stewart in 2006.
-
Cross-Platform Support: Works on Windows, Mac, and Linux.
-
Cross-Browser Support: Compatible with major browsers like Chrome, Microsoft Edge, Firefox, and Safari.
-
Multi-Language Support: Works with top programming languages including Java, JavaScript, Python, C#, and Ruby.
-
Use Eclipse IDE to develop and manage test cases.
-
Integrates with Jenkins for CI/CD pipeline automation.
-
Supports Maven for build and dependency management.
-
Use Git (version control) and GitHub (cloud-based repository hosting) for collaboration.
-
Supports TestNG as a testing framework.
-
Huge ecosystem of plugins β offering flexibility and enhanced capabilities.
-
Generates HTML test reports using Maven, TestNG, Extent Reports, and Allure Reports.
- Help >> Eclipse Market place >> search >> testng >> Install.
- Download the x64 Installer (.exe) from Oracle JDK Downloads.
- Run the installer and complete the setup.
- Set environment variables:
- Open This PC > Properties > Advanced system settings > Environment Variables.
- Under System variables, create a new variable:
JAVA_HOME = C:\Program Files\Java\jdk-21 - Edit the Path variable and add:
C:\Program Files\Java\jdk-21\bin
- Verify installation by running in Command Prompt:
java --version
- Download the Binary zip archive (
apache-maven-3.9.9-bin.zip) from Apache Maven Downloads. - Extract the zip file to a desired location, e.g.,
C:\Program Files\apache-maven-3.9.9. - Set environment variables:
- Right-click This PC β Properties β Advanced system settings β Environment Variables.
- Under User variables, create a new variable:
MAVEN_HOME = C:\Program Files\apache-maven-3.9.9 - Edit the Path variable under System variables and add:
C:\Program Files\apache-maven-3.9.9\bin
- Verify installation by running in Command Prompt:
| Category | UI/Control type | Prefix | Example |
|---|---|---|---|
| Basic | Button | btn | btnExit |
| Basic | Text box | txt | txtLastName |
| Basic | Check box | chk | chkReadOnly |
| Basic | Radio button / group | rad | radGender |
| Basic | Label | lbl | lblHelpMessage |
| Basic | Date picker | dtp | dtpPublished |
| Basic | Links/Anchor Tags | lnk | lnkForgotPwd |
| Basic | Combo box | cbo | cboEnglish |
| Basic | Menu | mnu | mnuFileOpen |
| Basic | Sub Menu | sbmnu | mnuFileOpen |
| Basic | Dropdown List / Select tag | ddl | ddlCountry |
| Basic | Table | tbl | tblCustomer |
| Basic | Form | frm | frmEntry |
| Basic | Frame | fra | fraLanguage |
| Basic | Image | img | imgIcon |
| Basic | Common dialog | dlg | dlgFileOpen |
| Basic | List box | lst | lstPolicyCodes |
| Basic | RichTextBox | rtf | rtfReport |
| Basic | TabStrip | tab | tabOptions |
| Basic | Text Area | txa | txaDescription |
| Complex | Spinner | spn | spnPages |
| Complex | Chevron | chv | chvProtocol |
| Complex | Data grid | dgd | dgdTitles |
| Complex | Data list | dbl | dblPublisher |
| Complex | Directory list box | dir | dirSource |
| Complex | Drive list box | drv | drvTarget |
| Complex | File list box | fil | filSource |
| Complex | Panel/Fieldset | pnl | pnlGroup |
| Complex | ProgressBar | prg | prgLoadFile |
| Complex | Slider | sld | sldScale |
| Complex | StatusBar | sta | staDateTime |
| Complex | Timer | tmr | tmrAlarm |
| Complex | Toolbar | tlb | tlbActions |
| Complex | TreeView | tre | treOrganization |
src/main/java
βββ com.qa.utils
βββ Base.java
βββ CommonUtils.java
βββ ExcelUtils.java
βββ ExtendReportManager.java
βββ SeleniumUtils.java
βββ PdfReader.java
βββ log4j2.xml
src/test/java
βββ tests
βββ LoginTest.java
βββ pages
βββ LoginPage.java
Configurations
βββ Config.properties
Data
βββ TestData.json
Include
βββ UploadFile.pdf, UploadFile.png, UploadFile.csv...
βββ SelectorHub.crx (browser extension)
Logs
βββ execution.logs
reports
βββ extendReport.html
Screenshots
βββ assertDemo0313_Failed_183355.png
target (Maven Report)
βββ surefire-reports
βββindex.html
test-output(Testng Report)
βββ index.html
Test Suites
βββts-smoke.xml
βββts-sanity.xml
βββts-regression.xml
README.md
This project is a structured Maven-based Selenium Java framework following a layered architecture for better modularity, scalability, and maintainability.
| Directory/File | Description |
|---|---|
| com.qa.utils | Stores utility and helper classes |
Base.java |
Base class for initializing WebDriver, managing browser setup, and teardown |
CommonUtils.java |
Reusable methods like wait handling, data formatting, etc. |
ExcelUtils.java |
Handles reading/writing data from Excel files |
ExtendReportManager.java |
Manages Extent Report generation for test execution |
SeleniumUtils.java |
Utility methods for handling Selenium operations (e.g., handling alerts, frames, windows) |
PdfReader.java |
Handles PDF file reading and verification |
log4j2.xml |
Log configuration file for logging using Log4j |
| File | Description |
|---|---|
Config.properties |
Stores global configuration (e.g., browser type, URL, timeout) |
| File | Description |
|---|---|
TestData.json |
Stores structured test data in JSON format |
| File | Description |
|---|---|
UploadFile.pdf, UploadFile.png, UploadFile.csv |
Test files for file upload scenarios |
SelectorHub.crx |
Browser extension for element inspection |
AutoIt |
Scripts for handling Windows-based popups |
| File | Description |
|---|---|
execution.logs |
Logs generated during test execution |
| File | Description |
|---|---|
extendReport.html |
Extent Report file with test summary and results |
| File | Description |
|---|---|
assertDemo0313_Failed_183355.png |
Screenshot of failed test for debugging |
| Directory/File | Description |
|---|---|
surefire-reports/index.html |
Test execution report generated by Maven Surefire Plugin |
| File | Description |
|---|---|
index.html |
TestNG report with execution summary |
| File | Description |
|---|---|
TS_app_smoke.xml |
TestNG suite file for smoke tests |
TS_app_Regression.xml |
TestNG suite file for regression tests |
-
Test Execution
- TestNG reads the test suite file (
TS_app_smoke.xmlorTS_app_Regression.xml). - Initializes WebDriver using
Base.java.
- TestNG reads the test suite file (
-
Page Object Handling
LoginTest.javacallsLoginPage.javamethods.LoginPage.javauses locators and actions to interact with web elements.
-
Utilities and Configuration
Config.propertiesprovides browser type, URL, and other environment settings.CommonUtils,SeleniumUtils, andExcelUtilsprovide helper methods.
-
Data Handling
- Test data is fetched from
TestData.jsonorExcelUtils.java.
- Test data is fetched from
-
Assertions and Reporting
- Assert statements validate expected vs actual results.
ExtendReportManager.javagenerates Extent Reports.- Screenshots are captured for failed cases.
-
Logging
- Logs are generated using
log4j2.xml.
- Logs are generated using
-
Teardown
- Browser session is closed using
Base.javacleanup methods.
- Browser session is closed using
| Pattern | Description | Recommendation & Notes |
|---|---|---|
| βοΈ Page Object Model (POM) | Separates UI element locators and actions from test cases | π Best practice: Keeps tests clean, maintainable, and reusable. Highly recommended for all Selenium projects. |
| Singleton Pattern | Ensures a single instance of WebDriver | Recommended: Helps manage WebDriver lifecycle consistently and avoids resource conflicts. |
| Data-Driven Testing | Fetches test data from JSON, Excel, or CSV files | Best practice: Enables running tests with multiple data sets, improves test coverage and flexibility. |
| β Page Factory Pattern (@FindBy) | Uses annotations to initialize WebElement objects for locators | Not recommended / Deprecated: Still works but deprecated in Selenium 4+. Can cause proxy/stale element issues. Explicit locators with WebDriver are preferred. |
| Decorator Pattern | Enhances Selenium functions (like waits, screenshots) | Recommended: Useful for extending WebDriver capabilities and adding reusable features like logging or screenshots. |
- Proxy issues: Uses lazy proxies that can cause
StaleElementReferenceExceptionand are hard to debug. - No built-in waits: Leads to flaky tests due to
timing problems. - Maintenance: Adds
complexityand hides element lookup details. - Better alternatives:
Explicit By locators with WebDriverWait are clearerand more reliable. - Limited modern support:
Doesnβt support Selenium 4features well. - Performance: Proxy creation can
slow down large test suites.
β
Follows layered architecture for better maintainability
β
Implements Page Object Model for clean separation of concerns
β
Supports data-driven testing using JSON and Excel
β
Provides logging and reporting with Log4j and Extent Reports
β
Enables parallel and cross-browser testing using TestNG and Maven
This project demonstrates Selenium WebDriver features from version 3 up to 4.29, including:
- Basic Selenium WebDriver actions
- PDF file reading using Apache PDFBox
- Comprehensive TestNG framework test cases
- Core Java fundamentals
- ChromeOptions and Chrome DevTools usage
- Mobile emulator testing on Chrome browser
- Data-driven testing with JSON, Excel, Properties files, and MySQL database
- File upload automation with Robot class and AutoIT
- Headless browser testing using HtmlUnit, ChromeDriver, FirefoxDriver, and PhantomJS
- Logging with Log4j framework
- Page Object Model design pattern demos: traditional POM and Page Factory with
@FindByannotation - Singleton design pattern example
- Shadow DOM handling
- Broken links detection
- Use of relative/friendly locators
- Apache PDFBox for PDF handling
- Log4j for logging
- Automation library for friendly locators
- Clone the repository.
- Configure
Config.propertieswith browser, URL, and timeout. - Run tests using:
mvn clean test- View reports at:
target/surefire-reports/index.htmlreports/extendReport.html- Allure report via:
allure serve allure-resultsRun a suite with:
mvn clean test -DtestngFile=YourTestSuite.xmlExamples:
mvn clean test -DtestngFile=smoke-test-suite.xml
mvn clean test -DtestngFile=sanity-test-suite.xml
mvn clean test -DtestngFile=regression-test-suite.xml- Adjust
<suiteXmlFile>path if suite files are not inTest Suites. - Change dependency scope from
<scope>test</scope>to<scope>compile</scope>to run from command line.
- Parallel suite located in
Test Suites/Parallel...
-
Maven surefire report target/surefire-reports/
index.html -
TestNG Report test-output/
index.html -
Allure Report install
scoopwindow powershell : iwr -useb get.scoop.sh | iex installallurecommand: scoop install allure cmd command :allure serve allure-results
Bijaya Chhetri | Automation Engineer | π github.com/bija510
This project is licensed under the MIT License.