3

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?

1
  • 1
    Using the pageobject design pattern, I believe people usually pass around the instance of WebDriver from page to page and therefore don't need to reuse the browser. For a while I was extending FirefoxDriver and overriding methods to force the re-use of a browser, which worked for a while but then it broke again around build 2.17 or so and I haven't got it to work since then. Commented Oct 4, 2012 at 20:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how can i create a firefoxprofile and attach to every webdriver?
Get any profile. Even a clean one. They are stored at %APPDATA%/Mozilla/Mozilla Firefox/profiles or %TEMP% (there are temp profiles from WebDriver). Store the folder anywhere. Instantiate FirefoxDriver with that Profile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.