TestNG error:- Cannot find class in classpath using Selenium

SeleniumAutomation TestingTesting Tools

We may encounter Cannot find class in classpath exception while executing tests in Selenium with TestNG framework. This can be caused because of the following reasons −

  • In the TestNG XML, the class tag having the name attribute should not have the .java extension.

  • In the TestNG XML, the class file is incorrect and hence unable to determine the classpath of the class.

  • Errors within the project are present, and may require a clean project.

  • In the TestNG XML, the class file name is incorrect

The below image shows an example of this error −

Example

import org.testng.annotations.Test;
public class TestNGP {
   @Test
   public void tC1() {
      System.out.println("Test Case 1");
   }
}

Example

TestNG XML Implementation

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Test>
   <test name="Tutorialspoint" >
      <classes>
         <class name="TestNGP" />
      </classes>
   </test>
</suite>

Output

raja
Published on 07-Apr-2021 09:24:11
Advertisements