[java] Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass

When i'm trying to run the test suite, am getting this exception. We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then also am getting the same exception. Please suggest any ways that am missing here.

Error console:

org.testng.TestNGException: 
Cannot find class in classpath: EmpClass

at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
at org.testng.xml.XmlClass.init(XmlClass.java:73)
at org.testng.xml.XmlClass.<init>(XmlClass.java:59)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:543)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1350)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

This question is related to java selenium selenium-webdriver testng

The answer is


I came across the same issue stated above today. **setting the class-path again in eclipse ** solved the issue .


In testng.xml file, remove "." from tag "" class name if you are not using packages.


I also got the same exception:

I tried the following steps:

  1. In Eclipse> Project > Clean. (The Exception remained)

  2. I ran another project(The testng.xml ran successfully)

After running another project, I ran the project in which I was getting the Exception, and fortunately it worked for me, with no errors.


I had similar issue and the project had some build errors. I did sudo -R 777 to the project and then I cleaned my project. After that it worked fine.

Hope it helps.


Make sure that your class is under src.


It happens when MAVEN is not installed locally on the system.

I faced the same issue when i cloned a Maven based Project from GIT and then as soon as I executed I got exception "Cannot Find Class In ClassPath : Class Name"

So i did a mvn clean test and found that maven is not installed locally.

After doing sudo apt install maven Maven got installed and i was able to Run the code


You have to edit your tests Runner xml file. See this example:

 <test name="Employees Test">
               <classes>
                      <class name="packagename.classname">
                       </class>
               </classes>
 </test>

In <class name="packagename.classname"> row you must enter your tests package name then name of class that you want to run.

Thanks and wish you all the best.


include the package name with class. It will remove your name. I also got the same issue but adding the package name with class fixed this issue.


I had the same error when tried to run my tests in a JSF project.

I´m using Eclipse IDE (kepler). So, I did "project > clean" and then ran the tests again of the same project.

It worked!


Project>>Clean and Maven>>Update Project worked for me


I had the same error. I cleaned the maven project then the problem was solved.


In my case I imported maven project as Default existing project in eclipse.After that I imported as maven project.That worked for me.


For me, the issue was because I excluded the test from compilation in the POM. My pom.xml looked like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <testExcludes>
            <exclude>com/mycompany/app/AppTest.java</exclude>
        </testExcludes>
    </configuration>
</plugin>

After removing the <exclude>, I was able to run the tests in AppTest.java again.


If you use IntelliJ IDEA, try the following:

  1. From 'File', select "Invalidate Caches/ Restart" option.
  2. Confirm this action by clicking the "Invalidate and Restart" button.
  3. Then the IDEA will be restarted.
  4. You will then find a fresh copy of your project.
  5. You then need to import/ change project format to the Maven project. IDEA will show you options at the bottom right corner.
  6. After this, you should be able to run your project.

This issue can be resolved by adding TestNG.class package to OnlineStore package as below

  1. Step 1: Build Path > Configure Build Path > Java Build Path > Select "Project" tab
  2. Step 2: Click "add" button and select the project with contains the TestNG source.
  3. Step 3 select TestNG.xml run as "TestNG Suite"

In my opinion if src has test/java/ folders then in build path out location should be like target/test-classes.

If src has main/java/ folders then in build path out location should be like target/classes.


After done trying everything that I found on this issue, in eclipse,

I selected my project --> right click --> Run as --> Maven generate-sources

enter image description here

Then I re-ran my TestNG project and it ran perfectly fine without any issues.Hope that helps :)


I faced the similar issue on importing maven with testng project. This was solved by converting again into TestNg project by

right click on eclipse project > TestNG > Convert to TestNG

and replacing the existing testng.xml file with the newly created. Clean and update the maven project with mvn install

Note: take backup of your testng.xml


I also had this issue. I'm using IntelliJ IDEA. I was using src/main/java for configuration files and src/test/java for test files.
Because of this testNG couldn't find the class path. To prevent getting that error need to move all the files from src/main/java to src/test/java or vice versa.


Note: You have to specify class name along with packages as given below.

<suite name="testNGLearning">
    <test name="simpleTest">
        <classes>
            <class name="testngTests.TestNGSimpleTest" />
            <class name="testngTests.TestMessageUtil" />
        </classes>
    </test>
</suite>

Go to Project>Build Path>Configure Build Path>Libraries>Remove Error libraries

After Refresh project and run again program.


I had this same problem when I imported my project from one PC to another on IntelliJ IDEA.

Below Solution worked for me:

  1. Import project using Git.
  2. After Importing IDE would prompt you a dialog on the bottom right corner saying "Import as Gradle", you need to select that but make Sure you have set JAVA_HOME and GRADLE(Gradle Home or Gradle wrapper both should work) properly.
  3. Run the build.gradle and make sure all the dependencies are downloaded correctly without any error.
  4. Now move to your Test Case and try to run with TestNG or JUnit and if you have followed above 3 steps properly you should able to run the test case.

I also ran into the same problem with TestNG version 6.14.2

However, this was due to a foolish mistake on my end and there is no issue whatsoever with maven, testng or eclipse. What I was doing was -

  1. Run project as "mvn clean"
  2. Select "testng.xml" file and right click on it to run as TestNG suite
  3. This was giving me the same error as reported in the original question
  4. I soon realized that I have not compiled the project and the required class files have not been generated that the TestNG would utilize subsequently
  5. The "target" folder will be generated only after the project is compiled (Run as "mvn build")
  6. If your project is compiled, this issue should not be there.

For me the problem was very strange.
I have a testng.xml file at the root of my Eclipse project. When I changed the file through Eclipse, it wasn't changing the testng.xml file in my directory.

Turns out it made a copy of the folder into the eclipse workspace..

Hope this helps someone out


I had no problems with this until recently.

Now I had to move the suite's xml test file into the root of the project I was testing.

It may be that there is a setting to point at the classes I am testing, but I have not found it.


Got the IDE working again. The solution is quite funny - and even a re-install, and deleting the IDE does not fix it on windows. What you need to do in that case, is to go to the testNG run configurations - and delete them all. This is for the TestNG XML classpath error on windows OS. I am using spring tools suite 3.6.4.

Make certain that you delete all the configurations, make sure the project can build, and if there are no problems, the test should run now.

Regards -Anthony Toorie


You should create package first and then create new TestNG class under that package.


My 2 cents on the problem: I was experiencing the same problem, while some part of my path was in Cyrillic. So check the path to your project for special characters. Once I removed this, the problem was fixed


Let me share what worked for me:

  1. When we do "mvn clean" - we are cleaning old compiled classes please lgo to ocation "your project directroy -> target " you will find this folder is getting cleaned because that's where MVN places it's compiled artifacts

  2. Since it's already a MAVEN project then go to your project folder and open in command prompt. And issue "mvn clean" and then "mvn test" -> "mvn test" command will place all the compiled files under proper folders and then you can run your tests through TestNG or MAVEN itself.

  3. Make sure you set up "M2_HOME" or "MAVEN_HOME" to your env path , sometime "MAVEN_HOME" doesn't work so add "M2_HOME" as well (google it for this set up)

Above suggestions worked for me so I wanted to share, good luck


For me it was that I added Skip Tests checkbox/flag in the Maven Build of the Project

Therefore the test classes weren't compiled and then weren't found by TestNG


I had the same issue when i was using selenium 3.11.xx dependency however my problem was resolved when i used selenium 3.4.x dependency.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to selenium

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser Class has been compiled by a more recent version of the Java Environment How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? How to make Firefox headless programmatically in Selenium with Python? element not interactable exception in selenium web automation Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click How do you fix the "element not interactable" exception?

Examples related to selenium-webdriver

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? How to make Firefox headless programmatically in Selenium with Python? Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click How do you fix the "element not interactable" exception? Scrolling to element using webdriver? Only local connections are allowed Chrome and Selenium webdriver Check if element is clickable in Selenium Java

Examples related to testng

element not interactable exception in selenium web automation how to use List<WebElement> webdriver Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass How to run TestNG from command line How do I setup the InternetExplorerDriver so it works TestNG ERROR Cannot find class in classpath Order of execution of tests in TestNG