Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error Could not find or load main class org.testng.TestNG

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.

like image 492
user2624997 Avatar asked Jul 27 '13 06:07

user2624997


People also ask

Can't find or load main class in Testng?

There are several ways the "Could not find or load main class" error can occur while executing Java programs. Most of the time, it occurs because of specifying an incorrect class name, class file extension, file path or classpath.

How do you resolve Testng no tests found nothing was run?

Solution. The easiest solution would be to change the @BeforeTest annotation with @Test and execute you Test case / Test Suite. Save this answer.


2 Answers

  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

like image 64
Prashanth Sams Avatar answered Sep 22 '22 03:09

Prashanth Sams


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

like image 35
Nguyen Thi Huong Avatar answered Sep 18 '22 03:09

Nguyen Thi Huong