Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a particular TestNG suite from multiple suites using maven in Jenkins

I have a maven project with 3 TestNG suites and 4 test classes, I want to run a specific suite in jenkins, I searched a lot but found only one command to put in goal test -DsuiteXmlFile=Jquery.xml to specify the particular suite but when I do this it runs all the other suites as well. I am stuck here for a long time, Please guide me through the process. And also I want to know whether there is any setting I can do so that if I select one suite to run, any particular class of that suite I can run. I have attached image of my project structure here, Any input would be appreciated. Thanks :)

project structure

Guru99.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="WebGuru99">
  <test thread-count="5" name="TestGuru99">
    <classes>
      <class name="com.selenium.vivek.Example2.WebGuru99_1"/>
      <class name="com.selenium.vivek.Example2.WebGuru99_2"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Jquery.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="WebJquery">
  <test thread-count="5" name="TestJquery">
    <classes>
      <class name="com.selenium.vivek.Example2.WebJquery"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Rediff.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="WebRediff">
  <test thread-count="5" name="TestRediff">
    <classes>
      <class name="com.selenium.vivek.Example2.WebRediff"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Pom.xml

<plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>Suites/Guru99.xml</suiteXmlFile>
                        <suiteXmlFile>Suites/Rediff.xml</suiteXmlFile>
                        <suiteXmlFile>Suites/Jquery.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
like image 357
vivkv Avatar asked Mar 02 '18 18:03

vivkv


1 Answers

So, I didn't find any answers here, so continued my journey to explore what could be done to get around this issue and found out a solution. So for anyone who faces this kind of issue might as well get benefited.

Use <properties></properties> in pom file. Add a tag which can be then passed as an argument while running through maven goal.

I added 'suiteFile' as a tag in pom and then passed it in <suiteXmlFile> as a variable

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

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>${suiteFile}</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

And then in jenkins, I passed clean test -DsuiteFile=Suites\Jquery.xml as goal and it ran only that suite. Hope that helps someone :)

like image 163
vivkv Avatar answered Nov 06 '22 06:11

vivkv