Open In App

Maven Dependency Management with Selenium

Last Updated : 06 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Maven is an open-source build automation tool primarily used for Java projects. It provides a uniform build system, project dependency management, and documentation. Maven uses the Project Object Model (POM) file to manage project configurations and dependencies, simplifying the build process and ensuring consistency across different environments.

Use Cases:

  • Version Management: It can easily upgrade or downgrade the library versions.
  • Transitive Dependencies: It can automatically manage the dependencies of the dependencies.
  • Exclusion: It can exclude unnecessary transitive dependencies.

Here, we can process the setup of a Maven project in Eclipse, integrate Selenium WebDriver, and run automated browser tests.

Step 1: Create the Maven Project

To create a Maven project, go to File > New > Project, select Maven Project, and click Next. Choose Create a simple project (skip archetype selection), then provide a unique Group ID (e.g., com.geeks), a project name as the Artifact ID (e.g., maven-selenium-demo), and set the Version to 1.0-SNAPSHOT. Finally, click Finish.

mvn archetype:generate -DgroupId=com.geeks -DartifactId=maven-selenium-demo-Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Project-Structure
Project Structure

Step 2: Add the Selenium and TestNG Dependencies

pom.xml

XML
<dependencies>
    <!-- Selenium WebDriver Dependency -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.6.0</version> <!-- Replace with the latest version -->
    </dependency>

    <!-- TestNG Dependency for testing framework -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.4.0</version> <!-- Replace with the latest version -->
        <scope>test</scope>
    </dependency>
</dependencies>

Step 3: Install maven dependencies.

Save the pom.xml file, or run the bellow command to automatically download the required Selenium and TestNG dependencies. Once we can add the plugins then you will find the selenium dependencies into the library files of the project.

mvn clean test
Maven-clean-test-output
Maven clean test output

Maven Can Simplifies the dependency management and builds the automation for the Selenium projects. By the leveraging Maven's capabilities. We can ensure consistent builds, easily manage the dependencies, and streamline the testing workflow.


Maven Dependencies
Visit Course explore course icon

Explore