• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Advance Selenium / Basic guide in Webdriver -How integrate Selenium with Maven build tool

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

March 22, 2015 by Ritika Gulati 46 Comments

Page Object Model in Selenium Webdriver

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

package MavenDemo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Testfacebook {

@Test
public void TestFireFox(){

WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("http://www.facebook.com");

driver.quit();

}

}

 

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.

 

 

 

Filed Under: Advance Selenium, Build Tool Tagged With: how to integrate selenium with maven, Maven

Reader Interactions

Comments

  1. Manikanth says

    November 8, 2019 at 5:31 PM

    Could you please add me for mail updates

    Reply
    • Mukesh Otwani says

      November 8, 2019 at 6:38 PM

      Hi Manikanth,

      Please subscribe to my blog and youtube channel

      Reply
  2. Muthukumar says

    June 23, 2019 at 9:45 AM

    Thanks ji, and one more help , can you Please Update the video for Hybrid Framework ?

    Reply
    • Mukesh Otwani says

      June 23, 2019 at 9:10 PM

      Hi Muthu,

      More videos about this topic are in pipeline…:)

      Reply
  3. Muthu says

    June 12, 2019 at 12:41 PM

    Could you please share the video for Windows Pop handles up using with 3rd party tool like autoIT?

    Reply
    • Mukesh Otwani says

      June 13, 2019 at 5:03 PM

      Hi Muthu,

      Please refer this link http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/

      Reply
  4. Shanu says

    April 5, 2019 at 3:30 PM

    Hi when i am creating maven project i am getting some error in pom.xml
    ” ” but when i changed this line , error got resolved but i am able to get Jre library file and maven dependency folder inside src folder

    Reply
    • Mukesh Otwani says

      April 5, 2019 at 8:08 PM

      Hi Shanu,

      I am not able to see line which you removed from pom.xml.

      Reply
  5. Yokesh says

    February 15, 2017 at 10:24 PM

    Mukesh, you are doing a great job! so organized & detailed steps and making it damn easy to follow. Pls continue 🙂

    Reply
    • Mukesh Otwani says

      February 16, 2017 at 11:37 AM

      Hi Yokesh,

      Thanks for your positive comments…:)

      Reply
  6. Soumyaranjan Sahu says

    December 16, 2016 at 4:06 PM

    Hi Mukesh,
    During creation of Maven project, I am getting “Could not calculate build plan: Plugin”

    Reply
    • Mukesh Otwani says

      December 17, 2016 at 11:56 AM

      Hi,

      You can check proxy settings.

      Reply
  7. Gaurav Khurana says

    December 5, 2016 at 11:30 PM

    It worked but as a TestNg.. How we know it ran as a maven project ?

    Reply
    • Mukesh Otwani says

      December 6, 2016 at 11:55 AM

      Hi Gaurav,

      Please follow below videos https://youtu.be/nasdb9QhFqg

      Reply
  8. Santhoshkumar Muralikrishnan says

    October 19, 2016 at 9:11 PM

    Hi mukesh,

    I am not able to create a maven project successfully. Followed the exact steps as in the video. Kindly help me to sort this.
    Getting the below error message.
    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6
    Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6

    Reply
    • Mukesh Otwani says

      October 20, 2016 at 1:54 PM

      Hi Santhosh,

      if you are running behind proxy then only this error comes. Kindly use without proxy.

      Reply
      • Santhoshkumar Muralikrishnan says

        October 20, 2016 at 6:26 PM

        Hi Mukesh,

        I dont used any proxy so far. Don’t know how to fix this. Kindly help me.

        Reply
        • Mukesh Otwani says

          October 20, 2016 at 8:14 PM

          Have you tried with Eclipse Neon. I guess some issue with your maven plugin then

          Reply
  9. subhendu malu says

    October 18, 2016 at 2:20 PM

    Hi Mukesh,
    i am not able install Maven in mac.Also after installation i am not able to find .m2 folder.plz guide me.

    Reply
    • Mukesh Otwani says

      October 18, 2016 at 4:32 PM

      for MAC open terminal and run brew install maven

      Reply
  10. Nikhil says

    September 30, 2016 at 1:09 PM

    Hi Mukesh,

    Tried freshly configuring the Maven project. Following steps were done.

    1. Downloaded 3.3.1 maven files.
    2. Path is set for MAVEN_HOME and in path variable.
    3. Maven Eclipse plugin is installed.
    4. When I click new->Project no option for Maven

    Just to add Im on company laptop where proxy is enabled. I tried with No proxy it didnt help at all.

    Reply
    • Mukesh Otwani says

      October 3, 2016 at 4:34 PM

      Then last option download Eclipse Neon it comes by default with Maven

      Reply
  11. Muthubala says

    September 29, 2016 at 4:49 PM

    Hi Mukesh ,

    May I know the steps for configure the more site in selenium web driver ?

    Reply
    • Mukesh Otwani says

      September 29, 2016 at 8:37 PM

      HI Muthubala,

      What do you mean by more site? Can you explain in brief?

      Reply
  12. Sumitra says

    September 26, 2016 at 3:02 PM

    Hi Mukesh,

    I went through ur videos for reading the excel.

    I am facing an issue and tried a lot. Could you please help me?

    my pom.xml looks like below:

    4.0.0
    EaasWebHybrid
    EaasWebHybrid
    0.0.1-SNAPSHOT
    EaasWebHybrid
    EaasWebHybrid

    org.seleniumhq.selenium
    selenium-java
    2.53.1

    org.testng
    testng
    6.9.10

    org.apache.poi
    poi
    3.9

    org.apache.poi
    poi-ooxml
    3.9

    org.apache.poi
    poi-ooxml-schemas
    3.9

    org.apache.poi
    poi-scratchpad
    3.9

    org.apache.poi
    ooxml-schemas
    1.1

    org.apache.poi
    openxml4j
    1.0-beta

    org.apache.poi
    poi-ooxml
    3.10-FINAL

    org.apache.maven.plugins
    maven-surefire-plugin
    2.19.1

    src\test\resources\RegressionSuite.xml

    Still in my code i get cannot instantiate XSSFWorkbook on the right side. (Highlighted part)

    XSSFWorkbook wb = new XSSFWorkbook(fis);

    Waiting for your reply.

    Reply
    • Mukesh Otwani says

      September 29, 2016 at 11:04 AM

      Hi you need only two dependency for Apache POI



      org.apache.poi
      poi
      3.14



      org.apache.poi
      poi-ooxml
      3.14

      Reply
  13. Prabhakar says

    September 22, 2016 at 12:16 AM

    Thanks Mukesh..Your videos and data is simply awesome for selenium learners..Have below queries after gone through maven tutorial…

    1.Do we need to add selenium jars,TestNG and other JARS after creating MAVEN Project in selenium to run test scripts in Maven Project..??
    2.How can Maven project knows there is latest version of TestNG/Selenium JARS/etc .. released recently ..??

    Reply
    • Mukesh Otwani says

      September 29, 2016 at 2:45 PM

      Hi Prabhakar,

      Maven will take care of adding jars you just have to specify the jars dependency.
      If latest version comes then you can change the version of the same and it will take care of updating the jars.

      Reply
  14. Nikhil says

    September 1, 2016 at 12:28 PM

    Mukesh Im getting on POM.xml, but what error it doesn’t show. I created testng class under test folder but when I execute testng.xml it gives error. Im pasting my POM.xml here. Its been 3 days and still struggling.

    4.0.0
    com.learnautomation
    com.learnautomation.selenium
    0.0.1-SNAPSHOT
    Demo Video Maven Build
    Demo Video Maven Build

    src/main/resources/testng.xml

    org.testng
    testng
    6.1.1

    org.apache.maven.plugins
    maven-compiler-plugin
    3.5.1

    1.8
    1.8
    1.8

    org.apache.maven.plugins
    maven-surefire-plugin
    2.17

    Reply
    • Mukesh Otwani says

      September 2, 2016 at 5:57 PM

      Hi Nikhil,

      Send me zip file of project I will look into it

      Reply
  15. Nikhil says

    August 31, 2016 at 11:33 PM

    In command prompt, when I type mvn -version. It says bad command. I have installed Maven, provided path in path variable. Also MAVEN_HOME variable is also set

    Reply
    • Mukesh Otwani says

      September 2, 2016 at 6:00 PM

      Hi Nikhil,

      Restart will help in this.

      Reply
  16. Pragyan says

    August 3, 2016 at 7:12 PM

    Hi mukesh, please let me know how to add the dependency. As I am getting an error on

    Reply
    • Mukesh Otwani says

      August 5, 2016 at 11:52 AM

      just add in pom.xml file

      Reply
  17. Amit Chaudhary says

    June 2, 2016 at 12:27 PM

    Hi Mukesh,

    I’m geting below error, when trying to create a maven project as per the steps provided by you –

    Error – Could not calculate build: Plugin org.apache.maven.plugins:maven-resource-plugin:2.6 or one of it’s dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resource-plugin:jar:2.6

    Reply
    • Mukesh Otwani says

      June 4, 2016 at 12:40 AM

      Hi Amit,

      is it fixec?

      Reply
  18. suvankar says

    February 25, 2016 at 12:50 AM

    hi,
    mukesh you are realy super star

    Reply
    • Mukesh Otwani says

      March 3, 2016 at 2:16 PM

      Hi Suvankar,

      Your comment made my day. Thank you 🙂

      Reply
  19. Sooraj Hat says

    December 29, 2015 at 4:43 PM

    Hi Mukesh, i keep getting “java.net.SocketException: Broken pipe” error message for a simple test case on Maven even though test case passes. do u know how to overcome this?

    Reply
    • Mukesh Otwani says

      December 29, 2015 at 10:06 PM

      Hi Sooraj,

      I did not get any kind of issue till now. Can you tell me the steps to reproduce it?

      Reply
  20. Manjunath says

    December 17, 2015 at 3:48 PM

    Hi,

    In the project structure four sections are there test/java, test/resources and main/java, main/resources. Can you please explain the four sections what to write in those sections.
    I guess in test/java section we are writing testcases and remaining can you please explain.

    Reply
    • Mukesh Otwani says

      December 17, 2015 at 8:42 PM

      main folder used by developer and test/resource folder can be used if you want to keep any file like chromedriver,iedriver etc.

      Hope its clear now 🙂

      Reply
  21. Raja says

    November 25, 2015 at 6:41 PM

    Hi dude,

    After installing the maven plug-in, I have created a java project. But here I am getting ony Src, target and pom.xml files only. I am not getting remain all folders (test,java..etc). Did I made any mistake while installing. Can you please help me dude.

    Reply
    • Mukesh Otwani says

      November 25, 2015 at 8:59 PM

      Hi Raja,

      Please update the Eclipse version to Eclipse Luna

      Thanks
      Mukesh

      Reply
  22. hanumanthappa says

    November 23, 2015 at 1:58 PM

    Hi Mukesh,

    I followed your pom.xml file in my project and mentioned xslt report dependecy also but unable to generate the reports.generating the normal report not giving the erro.
    Please find the my pom.xml file

    4.0.0
    com.learnautomation
    com.learnautomation.sel
    0.0.1-SNAPSHOT
    mavensample
    mavensaml

    jar

    org.testng
    testng
    6.3.1

    org.seleniumhq.selenium
    selenium-java
    2.47.1

    io.appium
    java-client
    3.2.0

    net.sf.saxon
    saxon
    8.7

    src

    org.apache.maven.plugins
    maven-surefire-plugin
    2.14.1

    testng.xml

    maven-compiler-plugin

    iso-8859-1
    1.7
    1.7

    org.reportyng
    reporty-ng
    1.2


    <!– /target/testng-xslt-report- –>
    true
    FAIL,SKIP,PASS,CONF,BY_CLASS
    true

    reporty-ng
    https://github.com/cosminaru/reporty-ng/raw/master/dist/maven

    Reply
    • Mukesh Otwani says

      November 23, 2015 at 9:31 PM

      Thanks try with Extent report https://www.youtube.com/watch?v=dBj7pxhZXhY

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?