TestNG – Cannot find class in classpath Error

TestNG – Cannot find class in classpath Error

TestNG – Cannot find class in classpath Error/exception in Java displaying while running your java program using TestNG framework. TestNG framework provides facility to execute multiple classes and multiple methods.

TestNG – Cannot find class in classpath Error

TestNG – Cannot find class in classpath Error/exception mat occurs in Selenium ,May be three below reasons

1.Not able to identify the classpath of class – Specified Class in TestNG xml file
2.Some errors in the projects – Try to clean your projects in Eclipse IDE from menu.
3.Provided package name is wrong in testng.xml file

Also Read TestNG Tutorials

ALSO READ  Java Lang NullPointerException in Selenium

Resolution: simply check all your class names and packages names in testng.xml file as below examples.

Session ID is null using webdriver after calling quit
How to send extent reports in email with screenshots

TestNG XML:

As per above reasons i have given below testng XML file with spell mistake in package name in <class name=”packageone.TestCase001″ /> because my package name is packagesone but i have given packageone ,so while trying to execute the testng XML file in the console i am getting error message as Cannot find class in classpath.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="SuiteName" parallel="methods">
 <test name="TestName" allow-return-values="true">
 <classes>
 <class name="packageone.TestCase001" />
 <class name="simpleFactoryUsage.TestCase003" />
 <class name="parallelWithBaseTest.TestCase004"/>
 </classes>
 </test>
</suite>

Also Read Selenium WebDriver Session not created exception

ALSO READ  Cross Browser Testing using Selenium WebDriver

When i run above testng xml file i have received this error message in console as Cannot find class in classpath,now i have corrected the testng xml file as below with minor error that is corrected the packages names as well as Class Names in testng xml file as below.Now when i run testng xml file it is executed the scripts successfully.

ALSO READ  How to Add Screenshots to TestNG Report

Modified TestNG XML

<?xml version="1.0" encoding="UTF-8"?>
<suite name="SuiteName" parallel="methods">
 <test name="TestName" allow-return-values="true">
 <classes>
 <class name="packagesone.TestCase001" />
 <class name="simpleFactoryUsage.TestCase003" />
 <class name="parallelWithBaseTest.TestCase004"/>
 </classes>
 </test>
</suite>

Now it has ran successfully with out any error and details displayed in Console with output messages.I hope this is helpful in resolving TestNG – Cannot find class in Classpath Error in your test scripts.

Rajesh K

Leave a Reply

Your email address will not be published. Required fields are marked *