Create Selenium WebDriver Maven Project in 10 Minutes

Having a hard time using Maven? Then read this express tutorial to create a Selenium Webdriver maven project using TestNG and Eclipse IDE.

In this article, you’ll find some quick visual instructions to set up a Selenium Webdriver maven project in Eclipse. And it won’t take more than five minutes of your precious time.

If you are already using Webdriver & TestNG with Eclipse, then you may skip to the next section. If you don’t, then check if you’ve TestNG plugin installed in your Eclipse. Just go to Window >> Preferences and search for TestNG. It’ll appear in the window pane if your Eclipse IDE have it.

Next, you should ensure whether you’ve Maven integration for Eclipse enabled. You can test it by opening the Eclipse marketplace window and searching for the maven keyword. In the search results, look for the text: Maven Integration for Eclipse. If it’s not already added, then click to install the maven support.

Also, if you want to read a detailed overview of Maven, then have a look at the below post.

So you are now ready with all the pre-requisites needed to create your first Selenium Webdriver maven project. Next, follow the visual aids and the description given in the below sections.

Create Selenium WebDriver Maven Project Using TestNG and Eclipse IDE.

While you are going through this maven tutorial, we recommend that you should start practicing the below steps. This way you can remember them much easily.

Create a Maven Project in Eclipse IDE.

1. Open Eclipse and right click on Package Explorer. Select New >> Maven project. And click the Next button.

WebDriver Maven Project - Create Maven Project


2. Tick the <Create a Simple Project (skip archetype selection)> check box and click Next.

WebDriver Maven Project - Skip Archetype Selection


3. Fill the group id, artifact id, and name. And click the Finish button to create the project.

WebDriver Maven Project - Configure Maven Project


4. The project structure would look something like the one shown in the below image.

WebDriver Maven Project - Project Structure


5. Also, you must make sure that the Installed JRE setting is correctly pointing to a JDK path on your system. You can change it from the Preferences window.

WebDriver Maven Project - Select JDK


6. Every maven project uses a POM file to add the required dependencies. So we’ll also be adding some libs required for our Webdriver maven project. Namely, these are the Selenium and TestNG JAR files. Please check from the below screen shot.

Note: Make sure you provide the correct version for each dependency you add in the POM.

WebDriver Maven Project - Update POM File

The above clip was just for the informational purpose. We’ll attach the full POM file in the below section.


Create a WebDriver TestNG Class in Your Project.

1. Go to your project and right click on the src/main/java folder. Then, click to select New >> TestNG class.

2. Assign a proper name to the class. And select required methods. Also, specify the name of the <testng.xml> file as shown below.

For example, we choose the Java class as LoadTest01.

WebDriver Maven Project - Create a New TestNG Class


3. Next, you should consider moving the TestNG file to the root of the project. See the below snapshot for reference.

WebDriver Maven Project - Move POM File to the root


Sample Code to Copy in Your WebDriver Maven Project.

In this part of the tutorial, we are attaching the Java source code and the POM file. You need to copy/paste them to your project files.


Java source code.

package com.techbeamers;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class LoadTest01 {

    private WebDriver driver;

    public void beforeClass() {
        driver = new FirefoxDriver();

    public void afterClass() {

    public void verifySearchButton() {

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


        String search_text = "Google Search";
        WebElement search_button = driver.findElement("btnK"));

        String text = search_button.getAttribute("value");

        Assert.assertEquals(text, search_text, "Text not found!");


POM File.

 <name>Load Testing</name>
 <description>Selenium Load Testing Example Using TestNG and Maven</description>

 <!-- Add Following Lines in Your POM File -->





For running the project, right click on the <testng.xml> file. And select Run As >> TestNG suite. That’s how you should be able to run your code using the TestNG.


Run WebDriver Maven Project with POM File.

Since we’ve used maven in our Webdriver project, so we can also utilize its POM file to run our tests. But we’ll need to add a few entries for the following plugins in the POM file.

1. <maven-compiler-plugin>,
2. <maven-surefire-plugin>.

To include these two plugins, you would need to append the following XML snippet to your project’s POM file.


Summary – Create a Selenium Webdriver Maven Project in Eclipse.

We are hopeful that this post will enable you to create a Webdriver maven project on your own. And you’ll recognize that using maven isn’t that hard.

It would be great if you let us know your feedback on this post.

Also, you can ask us to write on a topic of your choice. We’ll add it to our writing plan.

If you’d enjoyed the post, then please don’t leave without sharing it with friends and on social media.

Keep Learning,