Michal
Michal

Reputation: 39

Unable to run xml test suite from command prompt

I have TestNG suite with 2 tests included into an XML file. Test Suite works just fine if launching via IDE ( Eclipse ). However, I do need to run via command prompt. I try launching it using the following command:

java -cp C:\eclipse\plugins\org.testng.eclipse_6.9.5.201505251947\lib\*;C:\myworkspace\myproject\bin org.testng.TestNG MyTestSuite.xml

The error that occurs is:

[TestNGClassFinder] Warning: Can't link and determine methods of class tests.Test1

[[TestNGClassFinder]] Unable to read methods on class tests.MyTest1 - unable to resolve class reference org/openqa/selenium/WebDriver

[TestNGClassFinder] Warning: Can't link and determine methods of class tests.Test2

[[TestNGClassFinder]] Unable to read methods on class tests.MyTest2 - unable to resolve class reference org/openqa/selenium/WebDriver

TestNG also reports 0 test runs with 0 failures and 0 skips if that's relevant.

Upvotes: 0

Views: 285

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193058

As the Test Suite works just fine if launching via IDE ( Eclipse ) you can follow the below mentioned steps to execute the Test Suite through command prompt:

Steps

  • Get the absolute Project Location from your IDE (i.e. Eclipse), browse to the sub-directory and create a directory lib
  • Copy all the relevant jars and libraries (Selenium and TestNG jars) in the lib directory.

    • selenium-server-standalone-3.13.0.jar
    • org.testng_6.14.2.r201802161450.jar
    • com.beust.jcommander_1.72.0.jar
    • org.apache-extras.beanshell.bsh_2.0.0.b6.jar
    • org.yaml.snakeyaml_1.17.0.jar
  • Through CLI browse to the Project Directory and provide the following classpath:

    >set classpath=<Project Directory>\bin;<Project Directory>\lib\*;
    
  • Through CLI execute testng.xml as follows:

    Project_Directory>java org.testng.TestNG testng.xml
    
  • On successful execution, within the Project Directory create a new text document and add the following code:

    java -cp bin;lib/* org.testng.TestNG testng.xml
    
  • Save the file as run.bat

  • Execute the Windows batch file run.bat and verify it executes the Test Suite as expected.

You can find a detailed relevant discussion in Need correct step for Bat file creation using (TestNG.xml + Maven)

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

Your command looks fine.

This should work for you :

  1. After adding TestNG to your project library create one folder in your Project names as lib ( name can be anything ).

  2. Go to "C:\Program Files\Eclipse\eclipse-java-mars-R-win32-x86_64\eclipse\plugins" location and copy com.beust.jcommander_1.72.0.jar and org.testng_6.14.2.r20180216145.jar file to created folder (lib).

Note : Files are testng.jar and jcommander.jar

Upvotes: 0

Related Questions