Running TestNG Suite programitically
We are working on an automation project and are using Selenium and TestNG.
At the moment we are using Jenkins to run our tests.
However as a personal project of mine I want to create a alternative way of running our tests.
I have created a seperate JavaFX project to create a GUI, with this GUI it enables you to chose the XML using Java File Chooser, when you choose the TestNG XML, it executes.
However when it executes it cannot find it test classes that are specified within it.
Can anyone shed some light on this? Or know of ways you can get a TestNG XML Suite to run from Java code, for example you give the code the path to the XML and then the code will run the XML.
Thanks in advance.
What you are looking for is the TestNG Class. This is the class which can be invoked to run the tests programatically.
TestNG runner = new TestNG();
List<String> tempSuite = new ArrayList<String>();
tempSuite is a list of paths to your suite.xml.
TestNG class also contains lot of other methods that can help you control your test run. One such important set of methods are
TestNG.addListener which will help you add your listners.
I can suggest: “Compatibility Testing Using BrowserStack & Selenium – TestNG” http://blog.testproject.io/2016/04/17/compatibility-testing-browserstack-and-selenium/