I have started TestNG and wrote the first program in it but I cannot be able to run because of an error "Cannot find class in classpath: FirstTestNGFile" (here FirstTestNGFile is a class name). Here is my code.
package firsttestngpackage;
import org.openqa.selenium.*;
import org.testng.annotations.*;
import org.testng.Assert;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstTestNGFile {
public String baseURL = "https://www.google.com/";
String driverpath = "D:\\Ashish\\Setup\\chrome\\chromedriver.exe";
public WebDriver driver;
@Test
public void verifyHomepageTitle() {
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseURL);
String expectedtitle = "Google";
String Actualtitle = driver.getTitle();
Assert.assertEquals(expectedtitle, Actualtitle);
driver.close();
}
}
Here is the Exception:
Cannot find class in classpath: FirstTestNGFile
at org.testng.xml.XmlClass.loadClass(XmlClass.java:77)
at org.testng.xml.XmlClass.init(XmlClass.java:69)
at org.testng.xml.XmlClass.<init>(XmlClass.java:55)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:575)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
Note: I already cleaned my project and that did not resolve my problem.
please write program here with xml file code which you are asking about. You haven't told us how you are running your tests. You need to be adding more information around: 1. How are you running tests (feel free to update your question with detailed information) 2. Include the TestNG suite xml file that you are using. Your stacktrace seems to indicate you are using one.