public class Second {
private WebDriver driver;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public void beforeClass() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@Test
public void testSecond() throws Exception {
driver.get("url");
System.out.println("test two");
Thread.sleep(5000);
}
@AfterClass
public void afterClass() throws Exception{
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个testNG测试用例,它会在driver.quit()中抛出Runtime Exception.测试成功通过但测试完成后浏览器未关闭
Stack Trace:
FAILED CONFIGURATION: @AfterTest afterClass
java.lang.RuntimeException: Process refused to die after 10 seconds, and couldn't taskkill …Run Code Online (Sandbox Code Playgroud)