【发布时间】:2016-06-02 08:27:48
【问题描述】:
我正在使用 WebDriver 运行测试,当测试失败时,浏览器不会关闭。在 Windows 机器上,这是一个大问题,因为我有几个 Firefox 实例仍在后台运行。请指教
代码如下:
public static WebDriver driver;
private String sTestCaseName;
@BeforeMethod
public void beforeMethod() throws Exception {
DOMConfigurator.configure("log4j.xml");
sTestCaseName = Constant.Login_Name;
Log.startTestCase(sTestCaseName);
new BaseClass(driver);
}
@Test(description = "Login", enabled = true)
public void TestLogin_Success() throws Exception {
try {
driver = new FirefoxDriver();
LoginBuilder.Execute(driver);
Log.info("Successfully Login!");
} catch (Exception e) {
Log.error(e.getMessage());
throw (e);
}
}
@Test(description = "Login_Failed", enabled = true)
public void TestLogin_Failed() throws Exception {
try {
driver = new FirefoxDriver();
LoginBuilder.Execute_Failed(driver);
Log.info("Unsuccessfully Login!");
} catch (Exception e) {
Log.error(e.getMessage());
throw (e);
}
}
@AfterMethod
public void afterMethod() {
Log.endTestCase(sTestCaseName);
driver.close();
}
【问题讨论】:
标签: java selenium automation