protected void closeWebDriver(Thread thread) { ALL_WEB_DRIVERS_THREADS.remove(thread); WebDriver webdriver = THREAD_WEB_DRIVER.remove(thread.getId()); if (webdriver != null && !holdBrowserOpen) { log.info("Close webdriver: " + thread.getId() + " -> " + webdriver); long start = System.currentTimeMillis(); Thread t = new Thread(new CloseBrowser(webdriver)); t.setDaemon(true); t.start(); try { t.join(closeBrowserTimeoutMs); } catch (InterruptedException e) { log.log(FINE, "Failed to close webdriver in " + closeBrowserTimeoutMs + " milliseconds", e); } long duration = System.currentTimeMillis() - start; if (duration >= closeBrowserTimeoutMs) { log.severe("Failed to close webdriver in " + closeBrowserTimeoutMs + " milliseconds"); } else if (duration > 200) { log.info("Closed webdriver in " + duration + " ms"); } else { log.fine("Closed webdriver in " + duration + " ms"); } } }
protected void closeUnusedWebdrivers() { for (Thread thread : ALL_WEB_DRIVERS_THREADS) { if (!thread.isAlive()) { log.info( "Thread " + thread.getId() + " is dead. Let's close webdriver " + THREAD_WEB_DRIVER.get(thread.getId())); closeWebDriver(thread); } } }