🔧Maven- Project & Build Management Tool — Article #6

🔁Switching Testng.xml files With Maven Profiling

Control TestNG XML files Execution📄

Fareena Imran
CodixLab

--

In this article, we’re going t learn about ‘how to switch XML files with maven profiling’. Let’s get started 👇

Scenario💭: Let’s consider you have one testng1.xml file where you have all tests for smoke testing and there is another testng2.xml file where you have all the tests for regression testing or etc.

Now, if you want to trigger among testng.xml files then would you like to make changes to the testng file name every time in the pom.xml file (as we did in the previous article) đŸ„±â” obviously Nooo❌!

So, you can make profiles in the pom.xml file to trigger among testng.xml files. Now, Let’s see how to do this 👇

How to create profiles in pom.xml ❔

  1. Use <profile> tag in pom.xml.
  2. Give any name to id that you will use to give a command using cmd to execute testng.xml with this id.
  3. Go to <build> tag in pom.xml → copy → cut, then paste this <build> tag after <id> tag like👇

4. Use the command in cmd to execute a specific testng.xml file.

Syntax:

mvn test -PId_Name    //id_Name is that you will give to <id> tag.

Don't use gap in id_Name otherwise it will show you error.

5. Give the name of the testng.xml file that you want to execute by using the specific id name like this 👇

....
<profiles>
<profile>
<id>Regression</id>
<build>
....
<plugin>
<artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
...
</build>
</profile>
<profile>
<id>Smoke</id>
<build>
....
<plugin>
<artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
...
</build>
</profile>
</profiles>
...

6. Go to cmd and run ‘mvn test -PSmoke’ (Smoke is the id name that we have given to the testng2.xml file. Now, this command will execute the testng2.xml file but if you want to execute testng1.xml the use ‘mvn test -PRegression’ command on cmd.

Follow my all articles to learn more about SQA tools and frameworks.

If you find this post useful, please tap 👏 button below 😊

Best of Luck 👍

--

--

Fareena Imran
CodixLab
Writer for

SQA Engineer| Tech Writer | Write stories about SQA