Trigger Specific TestNG.xml through Jenkins for Maven Project - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Tuesday, 6 February 2018

Trigger Specific TestNG.xml through Jenkins for Maven Project

When we are testing our project.
It usually consists of multiple TestNG.xml files

To Run a specific Xml File

We have to add specific parameters in Pom.xml

Following is example of entry we make in Pom.xml


              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>  
                         <suiteXMLFile>${suitexml}</suiteXMLFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>


Here suitexml is a parameter

For whole Pom.xml refer following

<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.gurpreet</groupId>
  <artifactId>project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>project</name>
  <url>http://maven.apache.org</url>

  <build>
      <pluginManagement>
          <plugins>
             <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <debug>true</debug>
                        <encoding>utf-8</encoding>
                        <optimize>true</optimize>
                        </configuration>
                </plugin>
             
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>
                         <suiteXMLFile>${suitexml}</suiteXMLFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
                </plugins>
      </pluginManagement>
  </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
 
    <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.6</version>
</dependency>
 
    <dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</dependency>
 
    <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.2</version>
</dependency>
 
  </dependencies>
</project>


Make a bat file where we will specify the value of suitexml that will point to the specific TestNG.xml file
Following is a bat file

cd E:
cd E:\MortalGlobe


mvn test -Dsuitexml=E:\MortalGlobe\src\test\java\com\gurpreet\pages\firsttestng.xml

Place this bat file in Jenkins Job Folder in your machine





Entry of Bat file  in Jenkins Job

2 comments: