Search code examples
seleniumselenium-webdriverselenium-gridselenium-firefoxdriverremotewebdriver

Selenium 2 Firefox Profile Change Location


For many weeks now, I have been looking around and I have not seen anything regards to changing the location the Firefox Profile saves to.

I am using a specific Firefox profile, however, when the tests run the session is created in /tmp/. I would like the session to start up in a different location and save the files it uses in a location like: /var/tmp/. Is there any way to do this?

Note: This is not a question as to where I get the RemoteWebDriver to use a specific Firefox profile.

Edit: I am using Selenium 2.28 and Firefox 15.0.1


Solution

  • Look at FirefoxProfile:442

    File profileDir = TemporaryFilesystem.getDefaultTmpFS()
              .createTempDir("anonymous", "webdriver-profile");
    copyModel(model, profileDir);
    

    The TemporaryFilesystem takes it's location from "java.io.tmpdir":, which usually points to system's temp directory. Santoshsarma's solution will work because of this line (but it will also move your OS temp directory).

    private static File sysTemp = new File(System.getProperty("java.io.tmpdir"));
    

    We can do more! Look at the public method setTemporaryDirectory!

    You can invoke this method just before instantiating your FirefoxDriver and it should create it's profile copy at the location you specified.