Basic guide in Webdriver -How integrate Selenium with Maven build tool

Apache Maven is a software project management and comprehension tool. It is formally known as Build tool.  This article will help you to setup project and integrate selenium with maven.Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information that is called

Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information that is called Central repository. Maven has its own repository where it keeps all plugin, jars etc. in commonplace in .m2 repository.

Relation with Selenium-

We can create Maven project for writing script and create dependency-using POM.xml once dependency is set Maven will download all the dependent jar files automatically and in future if any update comes from Selenium or TestNG side it will simply update all the required changes.

Integrate selenium with maven

I have already published video on this which will cover integrate selenium with maven

 

Eclipse should be Juno(4.2) or Kepler(4.3) and If you are using Eclipse mars or neon then Maven comes by default so you can skip initial steps 🙂

Follow below steps for Eclipse Juno and Kepler

  1.  Step 1-  Open any browser and Copy below URL

http://download.eclipse.org/technology/m2e/releases

2.Step 2- Open Eclipse  and  Go to Help section then Click on install new software.

integrate selenium with maven

Eclipse Window

  3. Step 3– Now enter the url which we copied from Eclipse site and follow below steps.

integrate selenium with maven

Eclipse window 2

4. Step 4– Now select Maven check box and click next and accept agreement and finish.

 

Step 5– Installation will take some time and it may be asked for restart the eclipse.
After the restart, you can create Maven projects.

 

Integrate Selenium with maven

 

Step1- Open Eclipse then go to File then Click on New and select general project

integrate selenium with maven

 

Step 2– Now here you will get so many categories so from General Select Maven then Maven Project.

 

integrate selenium with maven

 

Step 3–   Now click on create a simple project checkbox and click on Next button

integrate selenium with maven

 

Step 4– Please enter Group id (depends on you I have taken selenium.maven) and Artifact ID > Next

 

integrate selenium with maven

 

Step 5- Click Finish and wait for some time for project creation. Once the project is created you can see the maven project in left project explorer.

 

Step 6– Click on pom.xml and click on Source tab you will get the source code of pom.xml

mavenineg8

 

 

 

 

integrate selenium with maven

Step 7- Now if want to integrate Maven with Selenium or any other tools then we need to add a dependency with Selenium.
So navigate to http://docs.seleniumhq.org/download/maven.jsp

how to integrate selenium with maven

 

 

 

 

 

 

 

 

 

 

Step 8– Selenium guys has  provided maven dependency so we need to copy the below dependency

 

how to integrate selenium with maven

Step 9– Open pom.xml file and create <dependencies> tag and paste the dependency code inside <dependencies> tag

 

Note – Each tag should be closed like <dependencies> —-</dependencies>

 

how to integrate selenium with maven

 

 

maven11in

Step 10- Let’s integrate the TestNG also in Maven project and Repeat the same steps as we did for Selenium
http://testng.org/doc/maven.html

 

mavnin19

 

After paste, your pom.xml will look like

Note- Once you will update pom.xml then inside your project you will get maven dependency.

 

Maven

 

Now we are done with Installation + project creation so let us create some sample scripts and will see how to execute the same

Selenium Scripts with Maven Project
Step 1- Click on project select src>test>java and right click then create a class

maven

 

Step 2– Give  package and class name and finish.

 

Maven

 

Maven Integration with Selenium

 

Step 3- Right your Java program and Run

Output- you will get the same output, which you will get if you run java project but now we have the central repository where all jars, is placed and if in future some new jars updated it will download automatically.

In next post, we will see how to create maven build and how to execute run the build via maven command prompt and from Eclipse also.

 

 

 

38 Comments

  1. Yokesh
  2. Soumyaranjan Sahu
  3. Santhoshkumar Muralikrishnan
      • Santhoshkumar Muralikrishnan
  4. subhendu malu
  5. Nikhil
  6. Muthubala
  7. Sumitra