I have say N number of test classes and I have one test suite say testing.xml which can run all those N tests , how to run testing.xml that is test suite multiple times ? Please help me out how to programatically run it multiple times
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1">
<test name="exampletest1">
<classes>
<class name="tester.NewTest1" />
</classes>
</test>
<test name="exampletest2">
<classes>
<class name="tester.NewTest2" />
</classes>
</test>
</suite>
You cannot do it from the xml, but in the @Test annotation - you can add a invocationCount attribute with the number of times you want to run it. It would come out as those many tests run in the report.
To run a single test case numerous times and that too in parallel, we can use an additional attribute of @Test annotation, threadPoolSize. Below is the sample code where we used both invocationCount and the threadPoolSize attribute. Now, after running the same XML file, five test case instances will run in parallel.
Yes, use a @Factory and create two instances of your test class, each with a different parameter.
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.
Here try this, you can modify this for whatever n times you want
for(int i=0;i<3;i++)
{
List<String> suites = new ArrayList<String>();
suites.add("testng.xml"); //path of .xml file to be run-provide complete path
TestNG tng = new TestNG();
tng.setTestSuites(suites);
tng.run(); //run test suite
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With