What profile does Selenium WebDriver use by default?
Asked Answered
C

4

17

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?

Cognizant answered 20/8, 2012 at 1:9 Comment(4)
AFAIK it's always a brand new one. You should just create your own and modify it to your needs.Manzanares
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?Cognizant
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 -ProfileManagerManzanares
In the headless case install / start something like xvfb (framebuffer server) and you will be able to use DISPLAY=:11.0 firefox -CreateProfile test.Antidromic
O
21

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

Orchardman answered 20/8, 2012 at 7:33 Comment(2)
What kind of code is this? I.e., I'm using selenium in Rails via the capybara and selenium-webdriver gems.Dynasty
can i use this profile the way i used several user logins by using single browsers? @PavelJanicekDebauchery
A
5

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

Adjective answered 21/11, 2013 at 13:31 Comment(0)
P
2

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;
}
Pineapple answered 30/7, 2014 at 7:51 Comment(0)
B
1

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");
Brittney answered 4/3, 2015 at 3:9 Comment(1)
Wow, thanks. The existing ProfilesIni() quit working for some reason, and always returned an anonymous profile directory below /tmp.Confucian

© 2022 - 2024 — McMap. All rights reserved.