Selenium web driver cannot close firefox instance if test cases failed

i people, I am using junit with selenium 2.28 web driver. the problem is that if I run a successful test case, the web drives can close the firefox instance, but when the test case fails, the selenium web driver cannot close firefox. I am using FF 15.0.1 with selenium-server-standalone-2.28.0.jar. please respond thanks sahil

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; } 
+4
source share
1 answer

Add webdriver.quit() to @AfterClass method

Example When using selenide 4.5 I had to add (according to this version) do not close or place this dependency there

 import static com.codeborne.selenide.WebDriverRunner.getWebDriver; @AfterClass public static void cleanupBrowser(){ getWebDriver().close(); } 
+18
source

All Articles