伙计们,我正在使用带有 selenium web 驱动程序 2.28 的 junit。问题是,如果我运行一个成功的测试用例,web 驱动器能够关闭 firefox 实例,但是当测试用例失败时,selenium web 驱动程序无法关闭 firefox。我正在使用带有 selenium-server-standalone-2.28.0.jar 的 FF 15.0.1。请回复谢谢萨希尔
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;
}