2

I am trying to execute a TestNG Suite file via the command line in order to initiate a regression run. Currently I am doing this through my Eclipse IDE successfully by right-click on the "testng.xml" file then selecting Run As > TestNG Suite.

However, when I try to run it via the command line, I get an error message. Steps below:

  • I navigate to the directory where my "testng.xml" file is saved. e.g. C:\Users\xxx\Documents\eclipse projects\Automated Testing\config
  • Run the command:

    java org.testng.TestNG testng.xml

The above command generates the below response:

Error: Could not find or load main class org.testng.TestNG 
  • I tried setting the classpath to include all of the selenium and testNG Jar files as per below:

    set classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium-2.25.0/libs/*

However, this generates the below error message:

Environment variable classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium- 2.25.0/libs/* not defined 

I have looked on the testNG Documentation (http://testng.org/doc/documentation-main.html) and this just says that testNG has to be in your classpath, so now I am a bit stuck. Any help would be greatly appreciated.

2 Answers 2

3

Either methods work :)

Method #1

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

Method #2

cd C:\Workspace\projectname set ProjectPath=C:\Workspace\projectname echo %ProjectPath% set classpath=%ProjectPath%\bin;%ProjectPath%\lib\* echo %classpath% java org.testng.TestNG %ProjectPath%\testng.xml 
Sign up to request clarification or add additional context in comments.

Comments

1

Thanks @siemic, I have finally got it working now. Basically you just need to run the two commands below:

  1. set classpath=..\bin;C:\libs\selenium-java-2.25.0.jar;C:\libs\testng-6.0.1-nobsh
    noguice.jar;C:\libs*

  2. java org.testng.TestNG

It was the first command that I was having trouble with, so just to elaborate I needed to set the following three items on the classpath:

  • The BIN Directory of my project. This is because the java files that I have developed are located here.
  • The Selenium.jar file, this is because I am using the selenium framework
  • The testng.jar file, needed because this is my unit testing framework

Then finally I used a wildcard to include all other JAR files within my libraries folder. The weird thing is I needed to fully specificy the name of the selenium and testng jar files, or else the tests don't work. Not too sure why.

Anyway it is working fine now and I am able to execute the tests via the command line.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.