3

Team,

I know this is a popular question but I have been researching this 2 days with no luck. When I execute my Test Suite via testng.xml I am getting the following error:

TestNGException: Cannot find class in classpath: (packageName.className)

I am using Eclipse IDE for Java Developers

Version: Mars.1 Release (4.5.1)

Build id: 20150924-1200

As well as Maven.

Here is my pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ASWRegression</groupId>
<artifactId>ASWRegression</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ASWRegression</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>


    <dependency>

        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.48.2</version>

    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
        <scope>test</scope>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

         <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.18.1</version>
    </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

</build>

I have cleaned the project via eclipse,updated maven ran maven cleans and builds but am not having any success. I even made sure my system library was pulling the correct java jdk 1.8. Please advise if there is anything else i need to be doing?

3
  • Why do you provide your pom file if you try to run your tests via testng.xml (I suppose via the TestNG plugin)? BTW, it is working as expected via maven only (mvn test)? You should provide the testng.xml file to surefire too (see the doc) Commented Oct 14, 2015 at 15:08
  • @juherr yes it works as maven, what doc are you referring to? Commented Oct 16, 2015 at 11:46
  • Surefire's one: maven.apache.org/surefire/maven-surefire-plugin/…. You should provide your test.xml file too. Commented Oct 19, 2015 at 11:39

2 Answers 2

2

You need to include the .class of packageName.className in your classpath (as the error says). So when you run the .xml file via a command line it should look something like java -cp %CLASSPATH%;path/to/packageName.className.class org.testng.TestNG path/to/testng.xml.

Depending on what is or isn't already in your class path, you'll also need to include the paths to the libraries. Because this can be a chore to type in, I highly suggest saving this as a shell script or batch file depending on your OS.

Sign up to request clarification or add additional context in comments.

Comments

0

I was getting same error. I just resolved by doing this steps.

Convert TestNG again

Right click on project --> TestNG --> convert to TestNG.

Refresh your project(right click on project --> refresh)

Now run your test from testng.xml again(right click on testng.xml --> run as --> TestNgSuite).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.