Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What profile does Selenium WebDriver use by default?

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?

like image 536
Michael Roller Avatar asked Aug 20 '12 01:08

Michael Roller


People also ask

Which is default browser of Selenium Webdriver?

Selenium comes with default Mozilla Firefox driver which is bundled in Selenium WebDriver jar file. That's why for calling Firefox driver, no setup is required. If we want to use other browsers, we need to set up its system property.

How do I make Chrome my default profile in Selenium?

We can open Chrome default profile with Selenium. To get the Chrome profile path, we need to input chrome://version/ in the Chrome browser and then press enter. We need to use the ChromeOptions class to open the default Chrome profile. We need to use the add_argument method to specify the path of the Chrome profile.

What is the name of default profile created by Firefox driver?

Profiles profile = new Profiles(); FirefoxProfile fprofile = profile.

What is browser profile in Selenium?

Firefox profile is the collection of settings, customization, add-ons and other personalization settings that can be done on the Firefox Browser. You can customize Firefox profile to suit your Selenium automation requirement. Also, Firefox or any other browser handles the SSL certificates settings.


4 Answers

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

like image 58
Pavel Janicek Avatar answered Sep 27 '22 23:09

Pavel Janicek


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

like image 35
Andreas Panagiotidis Avatar answered Sep 27 '22 23:09

Andreas Panagiotidis


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;
}
like image 43
FrankyHollywood Avatar answered Sep 28 '22 01:09

FrankyHollywood


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");
like image 33
santon Avatar answered Sep 27 '22 23:09

santon