17
votes

Where does Selenium WebDriver (a.k.a Selenium 2) get the anonymous profile that it uses when it opens FirefoxDriver? If it used the default for Firefox, %appdata%/roaming/mozilla/firefox/profiles, then if I were to disable a firefox plugin, it should be disabled for Selenium WebDriver also, so why isn't it?

4
AFAIK it's always a brand new one. You should just create your own and modify it to your needs.devsnd
ok its a brand new one, but it is still basing it on some prototype stored on a computer, since it is remembering to start up an addon that was since disabled within firefox. Where is this prototype?Michael Roller
I guess it's the one firefox provides, if you specify the -CreateProfile option on the command line. e.g. firefox -CreateProfile test. So what you are asking for is rather a firefox question, than a selenium one. I still recommend just to create a new Profile using the Profile Manager, e.g. firefox.exe -ProfileManagerdevsnd
In the headless case install / start something like xvfb (framebuffer server) and you will be able to use DISPLAY=:11.0 firefox -CreateProfile test.daniel.kahlenberg

4 Answers

21
votes

I will answer it, supporting comment from @twall: When starting firefox in Selenium 2 WebDriver, it starts new, anonymous profile.

However, if you want to change it, you can create new Firefox profile and name it somehow, you know what it is - e.g. SELENIUM

Then in your code do this:

 ProfilesIni profile = new ProfilesIni();
 FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
 WebDriver driver = new FirefoxDriver(ffprofile);

That way, Firefox will always start that profile. In the profile you do all the settings you need

5
votes

You can assign to each Selenium grid 2 node a specific firefox profile:

java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile=my-profile -role node -hub http://example-server.org:4444/grid/register

Notice that the value of the webdriver.firefox.profile has to be the firefox profile name, not the location or the folder name

2
votes

When running webdriver on a test server with no options to create profiles on the machine you can create your profile programmatically:

private FirefoxProfile GetFirefoxProfile()
{
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
    return firefoxProfile;
}
1
votes

Fetching a profile is not useful as it is internally creating another copy of the fetched named profile. Accessing the original profile is required if for eg: test coverage data should be written to a data store across multiple invocations.

Here is a possible solution by Overriding the ProfilesIni class of Selenium

Start by creating a Custom profile using firefox -p, say "CustomSeleniumProfile"

ProfilesIni profileini = new ProfilesIni() {
    @Override
    public FirefoxProfile getProfile(String profileName) {
            File appData = locateAppDataDirectory(Platform.getCurrent());
            Map<String, File> profiles = readProfiles(appData);
            File profileDir = profiles.get(profileName);
            if (profileDir == null)
              return null;
            return new FirefoxProfile(profileDir);
     }
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);

driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");