Role of the POM File and Dependencies in Selenium Automation Project
Updated: Jan 11
Introduction
The Page Object Model (POM) file plays a crucial role in a Selenium automation project. It serves as a blueprint for organizing and managing the automation code efficiently.
Purpose of POM File
The main function of the POM file is to encapsulate the elements and actions of a web page within a single object. This approach enhances the maintainability and readability of test scripts.
Sample Pom xml for Selenium Project
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.qa.abc</groupId>
<artifactId>com.qa.abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sample project</name>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.33.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.26.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>7.14.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.11.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<suiteXmlFiles>
<suiteXMLFile>testng.xml</suiteXMLFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>clean-allure-results</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>target/allure-results</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Components of POM xml
Project Coordinates: The groupId, artifactId, and version elements, often referred to as "GAV" coordinates, uniquely identify a project.
Dependencies: External libraries are declared in the <dependencies> section, enabling Maven to manage them automatically.
Build Plugins: The <build> section can include <plugins> for specific tasks like compilation and packaging.
Main dependencies and their use in Selenium automation project
We can download the dependencies from maven repository website - https://mvnrepository.com
1.Selenium java
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.33.0</version>
</dependency>
This dependency helps maven to download Selenium java library and manage it for the project.
2. WebDriver
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
</dependency>
This dependency is for managing WebDriver Manager library in the project. It is helpful in managing WebDriver binaries such as ChromeDriver, Firefox and others.
3. Testng
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
</dependency>
Testng dependency allows Maven to download and manage TestNG library for the project. TestNG is a framework used to organize the testcases , run them parallelly and generate detailed reports in selenium project.
4. Cucumber related dependencies
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.26.0</version>
</dependency>
Cucumber is a tool for running automated tests in a behavior driven development style. It provides the necessary classes and methods to execute feature files which describe the behavior in plane language. Including dependencies in the pom allows Maven to download the Cucumber Java library for the project.
5. Cucumber TestNG
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.16.0</version>
</dependency>
This dependency enables the user to run Cucumber tests using TestNG framework which helps in writing in behavior driven development and use TestNG framework for reporting and reporting capabilities.
6. Apache POI Dependency
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.4.0</version>
</dependency>
Apache POI library is a powerful Java library for reading and writing Microsoft Office documents, such as Excel, Word or Excel etc. In the context of Selenium automation project, it is often used for data-driven testing by reading data from Excel files and writing results back to them.
7. Apache Commons-io
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.19.0</version>
</dependency>
This dependency helps in working with files, streams and other input and output operations making it easier to do common tasks such as reading and writing files and managing directories etc.
8. Allure-Cucumber
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>2.29.1</version>
</dependency>
Allure is a lightweight test reporting tool that provides insights into test execution process and makes it easier to analyze and understand the results. Including this dependency in POM file helps in creating visually appealing test reports for Cucumber tests.
9. Log4j core and API
<!--
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.25.1</version>
</dependency>
This dependency helps in managing Log4j Core library for the project. Log4j is a popular logging framework for Java applications and Core library provides essential classes and methods for logging various messages such as Debug, Info, Warn and ERROR.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.25.1</version>
</dependency>
This dependency is useful in managing Log4j API library, it provides essential classes and methods for logging messages. Difference between Log4jcore and API is that API library provides essential classes and methods to log messages and core library includes the actual implementation of the logging framework.
10. PicoContainer
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>7.14.0</version>
<scope>test</scope>
</dependency>
Pico Container is a lightweight dependency injection container for java that uses constructor based injection to automatically create and share objects to manage step definitions , page objects and WebDriver per scenario in Cucumber framework.
Conclusion
Pom xml file is a the one of the main component of the Selenium automation project it provides a organized way to the project to minimize redundancy and streamline future changes. Tip for adding dependencies from Maven repository is that always download stable version not the latest one.


