How to execute testng.xml files using Java Program

In this post, we are going to discuss how to execute testng.xml files using Java Program.

As we all know in Selenium webdriver can execute multiple test cases using testng.xml file and we can handle all test case execution via testng.xml file.

If you are new in testng and not sure about testng.xml file then please check the below youtube video.

How to create testng.xml file in Eclipse 


What is need of this in Selenium?

Let me explain this with a help of an example.

Consider you have 10 test cases in Selenium and  you have created a testng.xml to execute all test cases.

Now you create another 20 test cases which belong to the same project but they belong to different module so again we created testng1.xml for the same.

If the same process goes on then at last you must be having couple of xml files which will  be having all the testcases.

Now the real problem is if you want to execute all xml in one shot then you can not do because Eclipse will allow to execute only one xml.

In this case we can take help of an TestNG class which allow us to execute multiple xml in one shot.

In below example I am having one testng.xml file which I will execute using Java Program.


How to implement in Selenium Webdriver

I have covered the therory part in program itself.Lets have a look.

I above program I have taken one xml file only but if you have mutiple files then repeat the same procedure and add files.

Hope you will implement the same in your project.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group


  1. Svitlana
  2. Ram Narayan
  3. laksha
  4. manohar kamarushi
  5. Nikhil
  6. Azgar khan Abdul
  7. Jananga