public class Test{
private WebDriver driver;
private String baseUrl;
@BeforeTest
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().window().maximize();
baseUrl = "https:gmail.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void gmalLogin() throws Exception {
driver.get(baseUrl");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("sunil.wali");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("Trelleborg@123");
driver.findElement(By.id("log_in")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(10000);
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
}
}
结果: 在执行之前,在系统中成功安装TestNG时,setup()方法在setup方法中未定义。
执行后,结果 - org.testng.TestNGException:
无法实例化类Test
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:387)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:299)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:110)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:186)
答案 0 :(得分:0)
只有当您提供有关如何运行测试类的更多信息时,才能回答您的问题。以编程方式,通过eclips或从命令行?
仅当testNG无法访问测试类路径时,testNG才会发生此异常。