Execute Multiple XML files in TestNG
Execute Multiple Xml files in TestNG will discuss about how to execute multiple xml files in TestNG at a time. For ex. You have more than one xml suite files to execute different types of test scripts in your project. Now you can execute the individual xml files simply that right click on xml file and run as testng suite. But if you have multiple files then you need to put those xml files in a separate xml file and need to execute the same way as right click on xml and run as testng suite. This way you can manage the test cases execution how we want.
Sometimes we need to maintain separate test suite for smoke test and separate suite for sanity test and another for Regression testing. For ex, once you receive the new build then you can perform smoke test using its own xml file, same way you can perform sanity test also using its own xml file. But if you want to execute full regression then you need to include regression tests, smoke tests and sanity tests. In these kind of situation we will put all these three suite files into another xml file and then we can execute that single xml file to run all the test scripts available under these 3 suite files.
We will see this functionality with an example:
Let’s assume we have 3 packages called com.multiplesuite.regression, com.multiplesuite.smoke and com.multiplesuite.sanity and each package contains 2 class files and then each class will contain 1 test method.
Now we will write sample xml files for each and every package which we have discussed above:
1. Xml file for com.multiplesuite.regression (ex: regression.xml)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="Test"> <classes> <class name="com.multiplesuite.regression.regressionClassOne"/> <class name="com.multiplesuite.regression.regressionClassTwo"/> </classes> </test> </suite>
In the above xml file it contains two classes called regressionClassOne and regressionClassTwo and each class contains its own methods.
2. Xml file for com.multiplesuite.smoke (ex: smoke.xml)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="Test"> <classes> <class name="com.multiplesuite.smoke.smokeClassOne"/> <class name="com.multiplesuite.smoke.smokeClassTwo"/> </classes> </test> </suite>
In the above xml file it contains two classes called smokeClassOne and smokeClassTwo and each class contains its own methods.
3. Xml file for com.multiplesuite.sanity (ex: sanity.xml)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="Test"> <classes> <class name="com.multiplesuite.sanity.sanityClassTwo"/> <class name="com.multiplesuite.sanity.sanityClassOne"/> </classes> </test> </suite>
In the above xml file it contains two classes called sanityClassOne and sanityClassTwo and each class contains its own methods.
If you want to execute only regression test then you can use regression.xml file to execute its specific tests and the same way we can do it for smoke test and sanity test also.
But now we want to execute all the above three xml files at a time. Then you need to put these three xml file into another xml and then run the same to achieve our requirement.
Below is the sample xml file to execute above 3 suite files: (ex: testng.xml)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="MultipleSuite"> <suite-files> <suite-file path="regression.xml"></suite-file> <suite-file path="smoke.xml"></suite-file> <suite-file path="sanity.xml"></suite-file> </suite-files> </suite>
In the above file we can observe new tags called suite-files and suite-file-path. By using suite-file-path we can mention the individual suite files and can execute the same like run as testng suite.
This way we can execute multiple suite files from other xml file.
Please watch the you tube video for better understanding.