Wednesday, May 13, 2015

How to Run TestNG xml Programmatically

public static void main(String[] args) {
  TestNG testng = null;
  List suites = null;
  try {
   testing = new TestNG();
   suites = Lists.newArrayList();
         suites.add("D:/Projects/SeleniumTests/testng1.xml");//path to xml..
         suites.add("D:/Projects/SeleniumTests/testng2.xml");//If need to execute more xml files
   testng.setTestSuites(suites);
   testing.run();
  } catch (Exception e) {
   e.printStackTrace();
  }
}


Using Bat File:
D:
cd Projects\SeleniumTests
set MyProjectPath=D:\Projects\SeleniumTests
echo %MyProjectPath%
set classpath=%MyProjectPath%\bin;%MyProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG %MyProjectPath%\testng.xml