Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Sunday, February 4, 2018

Adding dependencies to maven for selenium

To add dependencies in maven project for running selenium tests, we can add dependencies under dependencies section as shown below:





1. Go to https://mvnrepository.com

2. Add Below dependencies:

a. TestNG
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.13.1</version>
    <scope>test</scope>
</dependency>

b. Selenium-java
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.8.1</version>
</dependency>

c. Selenium chrome driver
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.8.1</version>
</dependency>

3. All the other dependencies related to selenium can be found at:
http://www.mvnrepository.com/artifact/org.seleniumhq.selenium

4. The dependencies are associated with the tests and downloaded at m2 folder in users folder

Sunday, February 21, 2016

Maven POM.xml: Dependencies for Selenium, TestNG and junit

While working with Selenium, TestNG and junit with maven, we need to add in the Project Object Model (POM.xml), dependencies for Selenium, TestNG and junit. In this article, we have explained how to add the required dependency in the dependencies section in pom.xmlfile.

Add the dependency in the dependencies section for the required artifacts. Also please update the version as per latest version of the artifact.


Selenium Dependency:

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.52.0</version>
</dependency>

junit Dependency:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>

TestNG Dependency:

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8</version>
  <scope>test</scope>
</dependency>

Saturday, February 20, 2016

How to use maven to create selenium project

In this article, we will understand the basics of maven and how to create maven project for Selenium WebDriver in eclipse.

Problem Statement of this article:

  • Understanding the use of maven for creating a selenium Project.
  • Installing maven plug-in for eclipse
  • Creating a maven Project in eclipse
  • Adding dependencies for Selenium


Understanding the use of maven for creating a selenium Project.


  • Maven provides a uniform build system.
  • A Project Object Model or POM is an XML file in maven that contains project and configuration information used by Maven to build the project.
  • We can add and configure dependencies for selenium, TestNG and other resources in the maven Project using POM.xml file
  • Maven helps to define Project structure for better management of resources.
  • Maven automatically downloads the necessary files added in dependencies for WebDriver and other resources while building the project.


maven plugin download from eclipse

Installing maven plug-in for eclipse



Below are the steps to install maven plug-in for eclipse

  • Open eclipse and click on Help>Eclipse Marketplace
  • Search for Maven integration for Eclipse in eclipse marketplace. Install Maven integration for Eclipse
  • Restart eclipse.
  • Maven plug-in has been added in eclipse.


Creating a maven Project in eclipse:


  Pre-Condition: Maven Plug-in is added in eclipse.Below are the steps to create a maven project in eclipse.

creating maven project in selenium
  • Navigate to File>New>Project.
  • It will ask to select a wizard. Select Maven>Maven Project and click on Next
creating maven project in selenium
  • To start with, select create a simple project in the window and click on Next.
  • Provide the details for the artifact including Group Id, Artifact Id, Version, packaging to start with.
  • Click on Finish.
creating maven project in selenium

Once we click on finish,maven project is created in Java. As mentioned earlier, All the configurations of the Project are saved in a POM.xml file as shown below:

creating maven project in selenium


POM stands for "Project Object Model". It is XML representation of the Maven project. POM.xml file inherits from base superPOM.xml

How to use selenium libraries in the maven Project.


We can use selenium libraries by adding dependencies for selenium in the Project Object model as shown in the code snippet below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>qaautomation</groupId>
  <artifactId>Selenium_eclipse_maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>My first maven</name>
  <description>testing</description>  
  <dependencies>
      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.48.2</version>
    </dependency>
    <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.8.1</version>
</dependency>    
  </dependencies>
</project>

References: