Reputation: 83
I wanted to trigger the execution from a java main method instead of testng.xml file.
My doubt is how to add the parameters to Java main method for the execution. I have found .addListener and .setGroups to add listener and groups respectively, but couldn't able to find a way to add parameters.
Please help me out to start the exection through java main method.
Sample:
public class Execution {
public static void main(String[] args) throws IOException {
TestNG test = new TestNG();
test.setTestClasses(new Class[] {AETVTests.class});
test.addListener(new MyTestListenerAdapter());
test.setGroups("");
test.run();
}
}
Upvotes: 1
Views: 375
Reputation: 395
If you would reconsider using xml - you can also trigger execution through the main method with the xml file. Add the testng.xml file to your project path (in eclipse you can right click project - new - file - testng.xml), and this will work:
public static void main(String[] args) throws IOException
{
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("C:\\eclipse-2018\\Tests\\testng.xml"); //path to xml
testng.setTestSuites(suites);
testng.run(); //run TestNG
}
Upvotes: 1
Reputation: 614
You can access args by arg[0],arg[1] likewise. in cmd run your jar file> java -jar classname.jar param1 param2
Upvotes: 0