我各位,
我正在使用 junit 和 selenium web 驱动程序 2.28。
问题是,如果我运行成功的测试用例,Web 驱动器能够关闭 Firefox 实例,但是当测试用例失败时,Selenium Web 驱动器无法关闭 Firefox。
我正在使用 FF 15.0.1 和 selenium-server-standalone-2.28.0.jar。
请回复
谢谢
萨希尔
private void startWebdriver() throws UIException{
//2) Prevent re-use.
if(UIHandlerWD.this.profile == null)
throw new
UIException(
UIException.Code.UI,
"Webdriver instance cannot be instantiated."
);
//3) Configure Selenium Webdriver.
if (this.profile.browserType.equalsIgnoreCase("*firefox")){
FirefoxProfile fProfile = new FirefoxProfile();
// profile.SetPreference("network.http.phishy-userpass-length", 255);
fProfile.setAcceptUntrustedCertificates(true);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setJavascriptEnabled(true);
dc.setCapability(FirefoxDriver.PROFILE, fProfile);
//this.webdriver = new FirefoxDriver(dc);
this.webdriver = new FirefoxDriver(dc);
}
else if (this.profile.browserType=="INTERNETEXPLORER")
this.webdriver = new InternetExplorerDriver();
else
throw new
UIException(
UIException.Code.UI,
"Unknown browser type '" + this.profile.browserType +"'."
);
//4) Start Webdriver.
this.webdriver.get(this.profile.getURL().toString());
this.webdriver.manage().timeouts().
implicitlyWait(5, TimeUnit.SECONDS);
this.webdriver.manage().timeouts().
pageLoadTimeout(this.profile.timeout, TimeUnit.SECONDS);
}
void stopWebdriver() {
if(this.webdriver != null){
try{
Thread.sleep(5000);
}
catch (Exception e) {
// TODO: handle exception
}
this.webdriver.close();
}
this.webdriver = null;
this.profile = null;
}
Add webdriver.quit()
to an @AfterClass
method.
close() 将关闭当前活动窗口。如果当前活动窗口是最后一个窗口,则其功能相当于执行 quit()。
然而,它确实需要有一个有效的活动会话才能执行此操作。如果您的测试失败,则该会话可能已死亡,因此当您调用 close() 时,它不知道向何处发送命令并引发异常。
quit() 将结束所有会话并关闭所有客户端,它基本上是一个清理所有内容的命令。如果所有客户端/会话已经关闭/结束,它也不会抛出任何异常。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)