đ§Maven- Project & Build Management Tool â Article #6
đSwitching Testng.xml files With Maven Profiling
Control TestNG XML files Executionđ
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 â
- Use <profile> tag in pom.xml.
- Give any name to id that you will use to give a command using cmd to execute testng.xml with this id.
- 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 đ