Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Explore the seamless integration of Selenium Maven dependency in your test automation projects with this comprehensive tutorial.
Rahul Rana
December 22, 2025
While working on a project for test automation, you’d require all the Selenium dependencies associated with it like Selenium Maven dependencies. These dependencies are downloaded and upgraded manually throughout the project lifecycle, but managing dependencies can be quite challenging as the project gets bigger. This is why you need to build automation tools such as Maven to handle them automatically.
Maven can be defined as a software project management tool that uses the concept of project object model (POM). It enables the user to create an initial folder structure, perform compilation and testing, and then package and deploy the final product. It efficiently cuts down several steps followed in the build process and makes the build a one-step process.
In this Selenium Maven tutorial, I’ll explain what Maven is and why Maven is important as a build automation tool for managing Selenium Maven dependencies. Further, I’ll show you how to install Maven for your test automation projects and run your first project in this Selenium Maven tutorial.
The Selenium Maven dependency is a configuration entry in a project’s POM.xml file that automatically downloads and manages the Selenium libraries needed for browser automation.
What Is Maven?
Maven is a build automation and project management tool for Java-based projects. It simplifies compiling, packaging, dependency management, and project configuration using a central POM file.
How to Add in Selenium as Dependency in Maven Project?
To configure Selenium Maven dependency in your automation project, you need to create or edit the pom.xml file and define all required dependencies for Selenium and TestNG.
Maven plays a crucial role in managing a project lifecycle, which typically includes validation, code generation, compilation, testing, packaging, and more. It is a build automation tool that works in phases rather than tasks(as in the case of Apache Ant). It is used to manage the life cycle of a project. Maven makes the build management process much easier, as you only need to specify the dependencies in the pom.xml file, and Maven will take care of the rest!
Some key reasons Maven is used are:
By now, you already know that Maven is a build automation tool used to manage project dependency and the whole project lifecycle. Maven was built by the Apache Software Foundation and is used primarily for Java projects. It was initially developed to simplify the Jakarta Turbine Project’s building process and is now widely used to make building processes easy and uniform.
Maven can be defined as a software project management tool that uses the project object model (POM) concept. It enables the user to create an initial folder structure, perform compilation and testing, and then package and deploy the final product. It efficiently cuts down several steps followed in the build process by a single-step process.
Some key terms for this Selenium Maven tutorial:


Maven repository is the one step place to look for all the dependencies you might want to use in your projects. You can search for specific dependencies in the search bar and see for yourself which one you want to include in your project as shown below in the screenshot.

Maven can be installed either through Command-Line or with Eclipse IDE. We’ll first follow the steps to install it through Eclipse IDE.
Installing Maven in Eclipse is pretty straightforward; here are the steps:
Step 1: Click on Help from the top menu in Eclipse and select ‘Install New Software.’
Step 2: Click the Add button on the newly opened window.

Step 3: In the “Work with” text box, type “https://download.eclipse.org/technology/m2e/releases/latest/”. This URL is the location from where Maven can be downloaded.

Step 4: After this, Select all items to install.
Step 5: Wait a few minutes for the window to complete its process.
Step 6: Keep the default settings and click on the Next button.
Step 7: Accept the Terms & Conditions and click on Finish.
Step 8: Wait for the installation to finish.
Step 9: After the installation, restart your eclipse. Click on Yes to see the changes being reflected.
Boom! You’ve now installed Maven successfully to your Eclipse IDE.
If you want to go around the other way of installing Maven through the command line, please follow the below steps:
Step 1: Download & Install Java.
You need to install Java in your system if not already done. Click here to download the latest version of Java.
To check the Java version of your system, search and open run and type ‘cmd’ to launch the command prompt. Type ‘Java -version’ and press Enter to see which Java version is installed.
Step 2: Set Up Java Environment Variable
After installation of Java, set up the Java Environment Variable. Open the system settings to set the Java Environment Variable.

“C:\Users\prati\Downloads\jdk-21_windows-x64_bin\jdk-21.0.1” JDK path in the Variable value box and save the same.


Step 3: Download Maven and Set Up Maven Environment Variable


Step 4: Updating the Path Variable
To run Maven from the command line, we must necessarily update the Path Variable with Maven’s installation ‘bin’ directory.

Step 5: Testing the Maven Installation
Maven is now successfully installed in your system. Now, let’s verify it from the Windows command line. Open the command prompt, type ‘mvn -version’ and hit Enter. Check to see the version of Maven installed in your system displayed in the results.

Now you’re all set with Maven Installation and can create projects using Maven.
Like the Maven installation we discussed earlier in the Selenium Maven tutorial, you can create a Maven project either through Eclipse IDE or the Command Line.
Below are the steps to create a Maven Project with Eclipse IDE:
Step 1: Create a new project from the Eclipse IDE.
Step 2: From the new project window, expand Maven and select Maven Project and then click on Next.
Step 3: You may create a simple project or let go of this option. For now, we’ll use a simple project that would create a simple Maven-enabled Java project.

Step 4: Now upon clicking Next you’ll need to type information about the Maven project created. You may refer below descriptions to fill in the values:
Note: The version can be chosen flexibly. If your project has no parent dependencies, you don’t need to fill in the project dependencies. Just fill in the appropriate information and click on ‘Finish’.

Step 5: Congrats! Your Maven project has now been created successfully!

Note: Java code is placed in /src/main/java, resources are kept in /src/main/resources, testing code is placed in /src/test/java, and the testing resources are placed in /src/test/resources.
Step 6: You may now open the pom.xml to view the structure set up by Maven. You’ll see all the information we entered in ‘step 4’ here. You can use the tabs at the bottom to change the view. The pom.xml tab has the pom XML code for the Maven project.


The Maven Project is now ready to be used.
Step 1: Open a Command Prompt and navigate to the folder to set up your project. Once navigated, type the below command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Here, DgroupId is the organization name, DartifactId is the project name, and DarchetypeArtifactId is the type of Maven project.
On clicking Enter, your Maven project will be created.

Step 2: You can go to the project location to see the newly created Maven project. You can open the pom.xml file, which is in the project folder, by default the POM is generated like this:

Step 3: You can view the default folder structure of your Maven project.

Now that we know how to create a Maven project, let’s try to integrate Selenium with Maven. But before we do that, we need to understand the various Dependencies that would help with this integration.
All the external libraries used in a project are called dependencies. Maven has an excellent feature that automatically downloads required libraries from its central repository, which makes it easy as you don’t have to store them locally. Below is an example of writing a Selenium Maven dependency in your pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version>
</dependency>
On adding the above Selenium Maven dependency, Maven will download the Selenium java library into our local Maven repository.
Another Selenium Maven dependency can be added to pom.xml based on the requirement. A few examples that you might have to use in our Selenium project are:
This would import the testing framework dependency for Java.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
This would download the libraries required to access Microsoft format files.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
You can add these Selenium Maven dependencies in your pom.xml as shown below:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>LambdaTest</groupId>
<artifactId>MyDemoProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo_Project</name>
<description>this is a demo maven project</description>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
In case you want to validate how these Selenium Maven dependency import the required libraries, you’ll have to go back to the demo project and see what libraries are present by default.
To do the same you need to:

Here you can see the default libraries in your project for this Selenium Maven tutorial.
For a clearer vision, I’ll create a sample class using Selenium components and some TestNG annotations. Please note that I’ll create the sample test class under our project structure’s src/test/java folder. Below, the error correction can be done after adding the libraries.


So, rather than manually adding libraries by configuring the project build path in this Selenium Maven tutorial, I’ll write the dependencies for the project in pom.xml, and Maven will directly download those from its repository. This saves the trouble of doing it manually and reduces the chance of missing out on adding some jars. So, here is how you add the dependencies:
The pom.xml before the Selenium Maven dependency is added:

pom.xml after the Selenium Maven dependency is added:

After you have saved and refreshed your project, check the build path and see the Selenium and TestNG libraries being added Selenium Maven dependency.

Also, you can now go to your test class and see the different options to correct the error thrown in this Selenium Maven tutorial:

You can simply Import the WebDriver, and you’d be good to go. Similarly, for Test annotation, just import testng.annotations.

You can add more dependencies like Apache POI, extent reporting, commons email, or anything that might be specific to your project in a similar fashion to your pom.xml.
Note: TestNG Selenium maven dependency seamlessly integrates with TestNG automation scripts, providing a practical and effective approach to streamline your testing processes.
Now we are done configuring the project, let us run the project to see if the tests work fine.
There is a maven lifecycle in Selenium that every Maven build follows. The different methods are simply goals. Before going ahead, I’ll explain what these goals are.
Open a command line in your system, type mvn, and then Enter.

You can see a “Build Failure” message with an error saying that no goal has been defined in this Selenium Maven tutorial. As you parse through this message, you can see the different goals that can be defined for our Maven project. I’ll quickly go through these default goals before going into detail about the goals required for the Selenium project.
Of the above-said default goals, three are crucial for Selenium test automation. These three are clean, install, and tests.
You can use these goals alone or with a clean-install for this Selenium Maven tutorial.
Note: When using Eclipse IDE, you can directly use any of these three goals by right-clicking on your pom.xml, then Run As and selecting any of the options.
I’ll start with selecting Maven clean in this Selenium Maven tutorial, you can see the output below:

So here, the task of clean, which is to delete the target folder, has been completed, and hence, our Build is successful.
Before going to the second task of install, you need to add a plugin called the Maven Compiler plugin. Without it, the test automation build will fail. This plugin is used to identify the specific location of the compiler. You can add the plugin below in your pom.xml and refresh the project before executing the Maven install.
<build>
<!-- To define the plugin version in your parent POM -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Note: To read more about different types of Plugins for Maven, click here.
Upon adding this piece, your pom.xml would look like below:

Now, go to Maven Install just like you did for Maven Clean in this Selenium Maven tutorial and observe the console output for the build installation:


You can see in the console output that the Maven installer also executed the tests. To see the installed directories in your local system, refresh your project and see the generated directories. In the below snapshot, you can see all the files generated(a jar file as well since this is a simple JAVA program) as a result of the Maven install. You can share this jar file directly for others to execute.

Similarly, we can do Maven Test in this Selenium Maven tutorial and see the build results in the console:


The above steps show how execution can be done through Eclipse IDE, but in real-time project execution is done mostly through the command line So now we would use these goals from the command line. Before proceeding with these tasks, ensure that your current working directory in cmd points to your local workspace location. If we do not do this, our Maven command will not be able to find the desired pom.xml, and hence, our Selenium test automation build will fail.
Let us first do the Maven Clean using the command prompt in this Selenium Maven tutorial. We simply need to write ‘mvn clean’:

You can see the target folder getting deleted. The next step in this Selenium Maven tutorial is to do a Maven install by typing ‘mvn install’ in the command prompt.


The console output is almost similar to what was there through Eclipse execution. Let us now perform a Maven test by typing ‘mvn test,’ which would execute the test without building jar files.

Now that you know the basic goals for executing our automated testing, you can run your Selenium automation scripts through Maven!
By now you have read this term in this Selenium Maven tutorial quite some time in your console output logs, so I’ll shed some light on it. The surefire plugin helps Maven to identify the tests and is used with whichever framework your project is built on. To add the Surefire plugin to your pom.xml use the below code snippet:
<plugin>
<groupId>org.apache.Maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Your pom.xml should look like below:

Now I’ll run Maven test from eclipse in this Selenium Maven tutorial and see the results:

You can now check the reports that have been generated by default and in a similar way by typing ‘mvn test’ can execute this suite from the command prompt.
The report generally gets generated at the following location
“your_project_name/target/surefire-reports”

If in case, the report is not generated by default, we can find it from this location:
“${basedir}/target/site/surefire-report.html”

In this Selenium Maven tutorial, I explored how Maven as a build automation tool can better manage Selenium Maven dependency for your project. With Maven, you wouldn’t have to worry about installing and upgrading your project libraries as they are done automatically with the tool. Now you know how to install Maven in your systems with both Eclipse IDE and with the command line. I also explained how to create a Maven project in Eclipse IDE Also, I went through the Maven lifecycle, and the goals used, and then I ran the Maven project.
This pretty much sums up everything you need to know to get started with Maven in this Selenium Maven tutorial. Do reach out to us in case of any questions or doubts. Also, I’d appreciate it if you could help us share this article and retweet it. That’s all for now. Happy Testing!!!
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance