Saritha Athmakur
Saritha Athmakur

Reputation: 1

How to run testng.xml from Command Prompt using org.testng.TestNG

I am trying to run testng.xml from command prompt. This is the command I'm running:

C:\Users\sathmakur>java -cp C:\Users\sathmakur\.m2\repository\org\testng\testng\
6.3.1\testng-6.3.1.jar org.testng.TestNG test.xml

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ ParameterException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterExcep tion
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more

I'm new at using TestNG and Command Prompt. It would be a great help if someone could shed some light.

Upvotes: 0

Views: 8545

Answers (3)

Phoenix Sri
Phoenix Sri

Reputation: 1

From the stack it is clear that the essential jar file named jcommander-x.xx.jar is missing from the class path. Add this jar file to class path and your command line execution should work.

Upvotes: 0

Vijay Hadimani
Vijay Hadimani

Reputation: 11

Steps to run TestNG class in command prompt

  1. Open Eclipse
  2. Create New Project in specified Workspace
  3. Create a folder with name jars in the same workspace and paste selenium jars,apache jars etc
  4. Add TestNG library to the Project
  5. Create a TestNG class and using @Test annotation write a method
  6. Right click on project---->TestNG---->Convert to TestNG---->You will get one testng.xml
  7. open command prompt and type the below command

    java -cp bin;jars/* org.testng.TestNG testng.xml

or

open notepad and type the above command and save as .bat file,double click on bat file.

Upvotes: 1

Amit Chaudhari
Amit Chaudhari

Reputation: 124

Saritha,

The easier way is to include that testng.xml in your pom.xml. Maven Surefire plugin can be configured for the same. Refer to this link http://docs.codehaus.org/display/MAVENUSER/Maven2+And+TestNG.Example+pom.xml (Observe the suitexmlfile tag). Once you include your testng.xml. All you have to do is call "mvn test" from the command prompt.

Upvotes: 0

Related Questions