Advance Selenium, Build Tool

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

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.

 

 

 

46 thoughts on “Basic guide in Webdriver -How integrate Selenium with Maven build tool

  1. Manikanth says:

    Could you please add me for mail updates

    1. Hi Manikanth,

      Please subscribe to my blog and youtube channel

  2. Muthukumar says:

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

    1. Hi Muthu,

      More videos about this topic are in pipeline…:)

  3. Muthu says:

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

  4. Shanu says:

    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

    1. Hi Shanu,

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

  5. Yokesh says:

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

    1. Hi Yokesh,

      Thanks for your positive comments…:)

  6. Soumyaranjan Sahu says:

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

    1. Hi,

      You can check proxy settings.

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

  8. Santhoshkumar Muralikrishnan says:

    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

    1. Hi Santhosh,

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

      1. Santhoshkumar Muralikrishnan says:

        Hi Mukesh,

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

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

  9. subhendu malu says:

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

    1. for MAC open terminal and run brew install maven

  10. Nikhil says:

    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.

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

  11. Muthubala says:

    Hi Mukesh ,

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

    1. HI Muthubala,

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

  12. Sumitra says:

    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.

    1. Hi you need only two dependency for Apache POI



      org.apache.poi
      poi
      3.14



      org.apache.poi
      poi-ooxml
      3.14

  13. Prabhakar says:

    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 ..??

    1. 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.

  14. Nikhil says:

    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

    1. Hi Nikhil,

      Send me zip file of project I will look into it

  15. Nikhil says:

    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

    1. Hi Nikhil,

      Restart will help in this.

  16. Pragyan says:

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

    1. just add in pom.xml file

  17. Amit Chaudhary says:

    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

    1. Hi Amit,

      is it fixec?

  18. suvankar says:

    hi,
    mukesh you are realy super star

    1. Hi Suvankar,

      Your comment made my day. Thank you 🙂

  19. Sooraj Hat says:

    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?

    1. Hi Sooraj,

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

  20. Manjunath says:

    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.

    1. 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 🙂

  21. Raja says:

    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.

    1. Hi Raja,

      Please update the Eclipse version to Eclipse Luna

      Thanks
      Mukesh

  22. hanumanthappa says:

    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

Leave a 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.