Selenium Test Automation: How to add plugins and dependencies to your Maven project?

Selenium

BriefTitle: 
Plugins and Dependencies

Adding plugins and dependencies to your Maven project

Environment:

  • Operating System: 64 bit Windows 8
  • Java Development Kit (JDK): 1.8
  • Integrated development environment(IDE): Eclipse Oxygen Release (4.7.0)

Step 1: Open pom.xml file

To open the pom.xml file:

  1. Open the maven project in Eclipse if not opened already.
  2. Double click on the pom.xml file from the root directory of your project:
  3. Click the pom.xml tab to open the file. By default, your project’s POM looks like this:
    <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>com.dic</groupId>
      <artifactId>automation</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>automation</name>
    </project>

Step 2: Add maven compiler plugin to pom.xml

To add the maven compiler plugin to your pom.xml file, just add the following plugin to your pom.xml:

Note: You can get the latest version of maven compiler plugin from Maven’s website.

<plugins>
     <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.1</version>
          <configuration>
          <source> 1.8</source>
          <target>1.8</target>
          </configuration>
     </plugin>
</plugins>

Step 3: Add the Surefire Plugin to pom.xml

To add the maven Surefire plugin to your pom.xml file, just add the following plugin to your pom.xml:

Note: You can get the latest version of maven Surefire plugin from Maven’s website.
<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>

Step 4: Add TestNG Dependency to pom.xml

To add the maven testNG dependency to your pom.xml file, just add the following dependency to your pom.xml:

Note: You can get the latest version of maven TestNG Dependency from Maven’s website.
<dependency>
     <groupId>org.testng</groupId>
     <artifactId>testng</artifactId>
     <version>6.11</version>
     <scope>test</scope>
</dependency>

Step 5: Add maven java dependency to pom.xml file

To add the maven java dependency to your pom.xml file, just add the following dependency to your pom.xml:

Note: You can get the latest version of maven java dependency from Selenium’s website.

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

Now you are done with adding all the plugins and dependencies to your Maven project.

Step 6: Review pom.xml

After adding all the plugins and dependencies to your pom.xml file, your project’s pom.xml looks like this:

<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>com.dic</groupId>
<artifactId>automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>automation</name>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<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> src/test/resources/testng.xml </suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

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

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.4.0</version>
</dependency>

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

<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
</dependency>  
  
</dependencies>

Step 7: Update maven project

Let’s update the maven project to reload the maven configuration file again. To update maven project:

  1. Right click on your project, and then choose Maven > Update Project to open the Update Maven Project window.
    Selenium-eclipse-select-update-maven-project
  2. Make sure your project is selected in Available Maven Codebases section..
  3. Select the checkbox next to Force Update of Snapshots/Release which will force to use the latest build of all the dependencies.
  4. Click the OK button.
    Selenium-eclipse-update-maven-project-click-ok
Sorting: 
6

Add new comment

Selenium