Enable Javascript

Please enable Javascript to view website properly

Toll Free 1800 889 7020

Looking for an Expert Development Team? Take 2 weeks Free Trial! Try Now

Integrating Maven & Jenkins with Selenium

Maven Jenkin Selenium

Selenium used for web automation testing, but when we talk about delivering a product to a client, we need constant integration with the production environment, so that live deployment can be checked and only if it satisfies a pass percentage, then only they are pushed to the production environment. A continuous integration pipeline has to be set using Jenkins, which checks the latest build and can then be deployed to the production environment.

Maven is used as a build management tool, which can simplify the build process and make jars more easily available.

Maven and Jenkins: At a Glance

Jenkins is an open-source continuous integration tool. It can be used on Windows, Linux, MAC and Solaris environments. This means that it supports different systems. Jenkins will monitor a job when we are building a continuous integration pipeline and this job can be SVN checkout, corn, or any applicable state. It then performs an action when a particular job triggered./p>

Maven is a build management tool, which use to make the build process easy. You can easily define all the dependencies with the help of Maven, and it will provide you with all the jars in one go. You don’t need to worry about getting it from the internet and then importing it. With the help of pom.xml, you can define all the dependencies using artifact and version id. Maven will download the specified jar files from the maven repository and place them in. /m2 repository. Also, when you want to share the project with other team members, you can’t manually send the jars.

People scattered over the team can use different versions of jars which can bring inconsistency to the project. It is better to have a common structure of the project, which shared throughout the team.

Why use Maven and Jenkins?

  • Whenever a new deployment made, Jenkins will keep an eye on it and run a smoke test against the latest build. If the build is passed, it will be deployed in the build production environment.
  • It is not easy to run all the test cases by the time you reach the office. If you know that your test or regression suite will take almost 10 hours to execute then you can have a nightly build run on Jenkins, which will run the test cases during night time so that by the time you reach the office, you can get the latest test result without wasting any more time.
  • Jenkins will serve as a common server on which results published. The client and all stakeholders can log in to the server and see the test results.
  • Using Maven in your project removes the hard coding of jars.
  • The Build process will become very easy with Maven build management tool.
  • Updating hard coding jars is a hectic process. It’s better to update the version number in pom.xml so that jars can be updated on the go. You don’t need to worry about deleting the old jar and getting the latest jar.
  • When the team is big then you need a common structure to share the project structure. It’s easy to share the artifact id and version id so that people in the team can clone the project.

Steps to install Maven with TestNg in Selenium

A prerequisite is Eclipse. You have to download m2eclispe plugins which you can find in the Eclipse marketplace. You can go to the Eclipse marketplace and then search Maven in it. The first plug-in which will come in the search results is the one that you have to download.

Steps of creating a Maven project

  • Follow File -> New Project-> Other to create a project in Eclipse and then you have to select Maven -> Maven project. It will help in creating a Maven project.
  • Press the Next button, and you have to then specify the Artifact Id and Group Id. It will be unique for your project as when pushed to the git hub repository anybody can clone the project using these. Group Id is your Project Name, and Artifact Id is your Project folder name.
  • Select a template for the project.
  • Then select “Maven quickstart template”.
  • You will then get a Project with a structure of two folders. There will be two folders – src/main/java and src/main/test. You can main your tests in src/main/test folder and other things in the src/main/java.
  • You can then see pom.xml in your project structure. POM is the heart of the maven. Now, open the pom.xml and add the below code in it so that it can download all the dependencies and place them in the project structure. <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.45.0</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope> </dependency> </dependencies>
  • For every jar file, go to the maven repository official site and search for that particular jar. You can then copy the dependency tag and then add it to the pom.xml file.
  • You can integrate the testng framework with this by making a NewTest.xml file in the project structure.
  • For running the test through maven, you need one plugin which is known as maven sure-fire plugins. For running the test through testng you need the testng.xml plug-in. Maven compiler plugins also required for compiling the code. This plug-in will ensure that tests are running without any hiccups <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <suiteXmlFiles> <suiteXmlFile>TestNG.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build>
  • Now, you can go to the project path where pom.xml placed. Open cmd there. You can then fire the below commands to clean, compile and test the code.
  • mvn clean
  • mvn compile
  • mvn test // for all tests to be executed.

Steps to install Jenkins Server

Now, you have built the project using Maven and you need a continuous integration pipeline setup using Jenkins. You can then follow the below steps to install the Jenkins server on which tests will be running.

  • Click here and download Jenkins for your machine. You can then unzip the Jenkins folder and then you will get its .exe file which you can run to install the Jenkins server.
  • After the first step, you done with the installation of the Jenkins. You have to then follow the below command to run the server on the localhost. The command is:

    java -jar jenkins.war

  • The Jenkins server will continue to run on port number 8080. However, you can change the port number if you want to run it on another port.
  • You can go to https://localhost:8080 You will see the Jenkins server running on this port and then you can do the installation of the necessary plugins.
  • Click on New Item and then select the Maven project
  • Click on the OK button and a new job create with the name specified by you in Jenkins Server
  • Go to Manage Jenkins and select Configure Systems. You have to then configure Maven and JDK with the version number and go to Build Section and enter the full path of your pom.xml.
  • Click on Apply button. Click on the “Build Now” button.
  • In the left section, you can see the test execution history which will show you how many tests got passed and how many got failed.
  • You can schedule the regression test cases using Jenkins for nightly builds. You have to go to modify the configuration and select “Build Periodically” and then, enter the time in the manner like “0 22 * * *”. It will trigger every day at 10 pm. You can specify any time according to your convenience.


After retaining the structure locally, you can add Maven and Jenkins to your project to simplify the build process and add continuous integration with the production environment. As a proficient Software Testing Company, I guarantee you will find it useful. All the best!!

Software Development Team
Need Software Development Team?

Thank you!
We will contact soon.

Oops! Something went wrong.

Recent Blogs


NSS Note
Trusted by Global Clients