8
votes

I'm trying to run TestNG from command line, but it's giving me error. Can someone tell me where am I going wrong?

java -cp C:/TestNG directory/testng-6.2.jar;C:\project directory\src\com\suites\suite\shop org.testng.TestNG testng.xml

Error: Could not find or load main class org.testng.TestNG

My scripts runs fine when I ran them from eclipse testng plugin.

6

6 Answers

10
votes
  1. Copy the below commands in a text file.

  2. Edit the location.

  3. Save it as yourtext.bat

  4. Now, double click on the batch file created.

cd C:\Workspace\projectname

java -cp C:\Workspace\projectname\lib*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml

4
votes

Path of TestNG.jar file was not set up. Follow instructions of following site to set up. It worked for me: http://qtp-automate.blogspot.com/2011/10/running-selenium-testng-test-from.html

2
votes
  1. Try above answers.
  2. If still not work, then you might have downloaded the wrong version of testng.jar. From link testng.org, please click "here for ant users" to download a full testng.jar(11 mega bytes), not a "Maven Central" version(no more than 100k).

I have tested those two versions on centos following testng tutorial point

2
votes

Possibly your testng.jar file is not in the lib folder that C:\Workspace\projectname\lib.

You should find testng.jar first in your computer and move it manually to C:\Workspace\projectname\lib. Then it will work

0
votes

Check that the lib folder contains testng-6.8.jar(or any other version) file because testng.xml even executes successfully without testng-6.8.jar (or any other version) with the jars that gets added when we add TestNG library.

0
votes

My Assumptions:

  1. You are trying to run test file from command prompt

  2. libs folder generated under Project/tagret upon using "mvn clean package -DskipTests"

  3. class file generated under Project/target/test-classes/package-name

With above assumptions in mind, you can follow below process.

Setting class path in command prompt:

1. Open project location in command prompt


2. set classpath=C:\User\SeleniumTestProject\target\test-classes;C:\User\SeleniumTestProject\target\libs\*

3. java org.testng.TestNG C:\User\SeleniumTestProject\testng.xml