0

I'm trying to run testng.xml from command line. My project is maven project and mapped to git repository. I'm using below command to run from command line but facing [TestNG] [ERROR] Cannot find class in classpath:"filename" error java -cp C:\Softwares\TestngJars\testng-6.9.6.jar;C:\Users\praveen.ps\git\qawebautomationwoohoo\QCMainWoohoo\target\classes;C:\Softwares\TestngJars\jcommander-1.7.jar;C:\Softwares\TestngJars\bsh-1.3.0.jar org.testng.TestNG testing-prav.xml

Please help me to resolve this issue.

Note: I'm able to run the same from my eclipse without any issue and able to invoke the same from jenkins

Praveen PS
  • 127
  • 2
  • 5
  • 17
  • Please refer [here](http://stackoverflow.com/questions/7600898/testng-error-cannot-find-class-in-classpath) and [here](http://stackoverflow.com/questions/25543910/error-org-testng-testngexception-cannot-find-class-in-classpath-empclass). Might help – Sudeepthi Jan 03 '17 at 11:14
  • Thank you @Sudeepthi. I verified both links. They addressed more on eclipse related issue – Praveen PS Jan 03 '17 at 12:29

3 Answers3

0

Issue is resolved.i'm able to run the testng.xml via command line.Below are the steps followed to resolve the issue

  1. Enclosed all jar paths and classpath in Double-Quotes(" "). ex: java -cp "path-to-jars;path-to-classfiles" org.testng.TestNG testng.xml
  2. Added selenium jar file path as command line needs jar file to execute the script.
  3. Need to add bsh-1.3.0 and jcommander-1.7 jar files.
Praveen PS
  • 127
  • 2
  • 5
  • 17
0

For me issue got resolved by fixing the project setup in eclipse.
I clicked on the fix project setup suggestion given by eclipse, and then it started working.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
0

For Mavenised project, TestNG xml runner doesn't generate class files. Its the surefire plugin that does the creation of class files from .java files. You need to add/configure this plugin in your project pom.xml

 </build>
     <plugins>
         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>surefire-it</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>

                    </execution>

                </executions>
                <configuration>
                 <argLine>-Dfile.encoding=UTF-8</argLine>
                     <properties>
                        <property>
                            <name>delegateCommandSystemProperties</name>
                            <value>true</value>
                        </property>
                    </properties>
                    <skip>false</skip>
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <suiteXmlFile>./src/test/resources/testSuites/${testsuite}.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>

            </plugin>
          </plugins>
        </build>

Then, run the testNG.xml using this command.

mvn clean integration-test -Dtestsuite=<YourXMLfilename>
Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29