How to call testng.xml from the main java method?

I have a testng.xml file. Is there any way to run this file from the main java method?

Something like -

Class test { public static void main ( String [ ] args) { Run(testng.xml); } } 
+5
selenium-webdriver
source share
5 answers

You can run testng directly from the command line, perhaps make a bat file on it or use jenkins to run it. Contact here

or

If you want it mostly, then you can try

 TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = new TestNG(); List<String> suites = Lists.newArrayList(); suites.add("c:/tests/testng1.xml");//path to xml.. suites.add("c:/tests/testng2.xml"); testng.setTestSuites(suites); testng.run(); 
+12
source share

Please try the code below and make sure the testNG flag is added in the jar manifest file.

 public static void main(String[] args) { org.testng.TestNG.main(args); } 

Now you can transfer all the parameters to your bank, which are the same for the jar testNG file.

eg.

java -jar yourjar.jar testng.xml

or

java -jar yourjar.jar -testclass org.test.xyz.java

+4
source share

This work is for me. More details here .

 // Create object of TestNG Class TestNG runner=new TestNG(); // Create a list of String List<String> suitefiles=new ArrayList<String>(); // Add xml file which you have to execute suitefiles.add("C:\\Automation Test\\Git\\vne_automation\\testng.xml"); // now set xml file for execution runner.setTestSuites(suitefiles); // finally execute the runner using run method runner.run(); 

Hope this helps!

+2
source share

I did not get any errors and the correct XML path. But this will just end up with unsuccessful test cases. It does not open the Firefox browser. I use the testng annotation (i.e. @Before Suite, @Test, @group, etc.) inside the classes, while it successfully runs using Testng Suite in eclipse.

 <!-- suite name="Example" parallel="methods" thread-count="2" parallel="false" preserve-order="true"> --> <suite name="Example Donate System" verbose='1'> <test name="Agency" > <packages> <package name="com.Donatesystem.AgencyController" /> </packages> </test> </suite> 
0
source share

All of the above answers work like a talisman, but there is one limitation that will be met if and only until you remove the scope tag in pom.xml

In pom.xml there would be a maven dependency for testNg, and there would be one scope tag that would limit our jar only to the test

Just delete it

0
source share

All Articles