Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse the same WebDriver in different application using selenium

i'm writing here to ask if is possible to init WebDriver

WebDriver driver = new FirefoxDriver();

and use the same browser for many jar application, so doing, in other jar file, something like:

int port = ...;
String host = ...;
WebDriver driver = getDriver(host,port);

i ask this question because FirefoxDriver is very slow to load and happear, and i need to call many jar that load that driver. i think that in this way, loading just one time my driver, my total application will be fastly than open N-times N-instances of that driver. i hope that my question is clear and well-formed :) thanks to all!

EDIT: i see that there is the possibility to use RemoteWebDriver.

DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

How can i use it? when i have to instantiate the webdriver in localhost:4444?

like image 303
Jayyrus Avatar asked Apr 28 '26 01:04

Jayyrus


1 Answers

This is the most demanded feature request in Selenium. However, it's still not possible to attach a WebDriver to running browser window. What you discovered in RemoteWebDriver is the posibility to run tests remotely on another computer. But that computer still has to start a new browser window.

You could, I guess, write your application as something as a HUB that would enqueue all jars (classes) to run, would start a single instance of Firefox and pass the driver reference around. It's not a nice solution and as far as I know, nobody has done it yet.

BUT! The majority of time spent on startup in Firefox is creating a new FirefoxProfile. If you created one profile dedicated to testing and started your Firefox always with this profile, it would be significantly faster.

like image 110
Petr Janeček Avatar answered May 01 '26 11:05

Petr Janeček