0

When i write the script in bat file with following code for project location where actual testng file is placed:

set projectLocation=C:\Users\Automation-master

cd %projectLocation%

set classpath=%projectLocation%\bin;%projectLocation%\seleniumLibrary\*

java org.testng.TestNG %projectLocation%\testng.xml

With the above code Browser is invoked.

But in the same way i need to execute the Jar(of the above project) file comprising of class files, libs and testng xml with the actual tests in it through command line.

My query is how to specify classpath of libs and classes in the jar file and also point the testng xml file in the jar to execute the script?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vardhan
  • 41
  • 1

1 Answers1

0

Assuming you have built a jar which contains your test classes, you can specify this in TestNG via the below options

  • -testjar - Specifies a jar file that contains test classes. If a testng.xml file is found at the root of that jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test classes.
  • -xmlpathinjar - This attribute should contain the path to a valid XML file inside the test jar (e.g. resources/testng.xml). The default is testng.xml, which means a file called testng.xml at the root of the jar file. This option will be ignored unless -testjar is specified.

See here for more information.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • I have tried using following code: set projectLocation=C:\Users\Automation-master set classpath=%projectLocation%\seleniumLibrary\* java org.testng.TestNG -testjar asdf.jar -xmlpathinjar testng.xml . Here asdf is the jar having only class files.And the jar has testng.xml file with the classes to execute. I have set the jars required for the those test to run as classpath. – Vardhan Nov 09 '16 at 07:57
  • Getting the following error: [TestNG] [ERROR] Cannot find class in classpath: – Vardhan Nov 09 '16 at 08:04
  • Are you sure that your test jar named asdf.jar contains your test classes ? How are you creating a jar with your test classes ? Are you using maven ? Maven by default AFAIK, does not include test classes when build a jar using it. – Krishnan Mahadevan Nov 10 '16 at 03:25
  • No i am not using maven. I have created my jar using eclipse – Vardhan Nov 10 '16 at 06:33
  • Even in that case, i doubt if the jar you created would be having test classes. The easiest way to confirm this is to manually inspect the jar using some utility ( see here http://stackoverflow.com/questions/320510/viewing-contents-of-a-jar-file) and ensure that your test classes are present in it before trying this. – Krishnan Mahadevan Nov 10 '16 at 07:48