Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestNGException: Cannot find class in classpath

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?

like image 252
Andy Williams Avatar asked Mar 22 '26 08:03

Andy Williams


1 Answers

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.

like image 69
econoMichael Avatar answered Mar 23 '26 23:03

econoMichael