Reputation: 5131
I am having trouble getting RemoteWebDriver to close sessions. The problem occurs when running tests in parallel and one of the instances of RemoteWebDriver calls the close method.
For example:
If I comment out the call to close() then both tests run to completion successfully however both browser windows stay open after.
I am currently running the latest version of Firefox and 2.29.0 of seleium-server. Selenium is being used to scrape customer invoices off sites and is running on a JBoss server.
The code that creates the connection is the following:
public WebDriver getRemoteWebDriver() {
DesiredCapabilities capabilities = new DesiredCapabilities();
WebDriver driver = null;
URL url = null;
// Connect to the selenium server
try {
url = new URL("http://127.0.0.1:4441/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
capabilities.setBrowserName("firefox");
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new RemoteWebDriver(url, capabilities);
driver = new Augmenter().augment(driver); // Used to take screens
driver.manage().timeouts().implicitlyWait(SELENIUM_IMPLICIT_WAIT_SECONDS, TimeUnit.SECONDS); // Set implicit wait time
driver.manage().deleteAllCookies(); // Make sure we have clean session
return driver;
}
My question is: How do I properly create and close instances of RemoteWebDriver in parallel on one machine? Any help is much appreciated. Thank you.
Upvotes: 0
Views: 1317
Reputation: 7655
If you're running this test from a unit test, you can define a beforeclass and afterclass-hook. This way your selenium driver can start up before running all tests and shut down afterwards.
Upvotes: 1