SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.5k stars 8.15k forks source link

Selenium hub 3.5.3 ignoring Firefox profile set on DesiredCapabilities #4664

Closed guru-23 closed 4 years ago

guru-23 commented 7 years ago

System

Testcase

Test case 1 :

Setting network.proxy.type on FirefoxProfile object to 0, so that the automation test's which run on FF skip's the proxy and doesnt ask for user authentication.

FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("network.proxy.type", 0);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(FirefoxDriver.PROFILE, fp);

Create remote webdriver using the above capability object and continue with the test new RemoteWebDriver(new URL(SELENIUM_REMOTE_URL), (capabilities));

Test case 2 :

ProfilesIni profileIni = new ProfilesIni();
FirefoxProfile fp = profileIni.getProfile("AUTO_PRO");
capabilities.setCapability(FirefoxDriver.PROFILE, fp);

Expected Behaviour:

Opened Browser profile should have network.proxy.type set to 0 and should skip proxy and connect directly instead.

Actual behaviour:

Firefox Profile object ignored by Remote node, the firefox browser opened by node creates its own default profile which has network.proxy.type set to 5 instead of 0.

This scenario works fine if i run the test locally instead of running on a remote selenium hub. Have also tried with different versions, the last one which correctly picks up the set Firefox profile object is 3.4.0. All the selenium-server-standalone jar's from 3.5.0 ignore's the Firefox profile object's set on capabilities.

I have also tried setting "webdriver.firefox.profile" to the new profile name on the config json and pass the same on the node start up, but even then the profile is ignored.

barancev commented 7 years ago

To pass options to Firefox driver you'd better use FirefoxOptions class:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 0);
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
driver = new RemoteWebDriver(options.toCapabilities());

or even better, without passing profile over the wire:

FirefoxOptions options = new FirefoxOptions();
options.addPreference("network.proxy.type", 0);
driver = new RemoteWebDriver(options.toCapabilities());

FirefoxOptions.toCapabilities() method generates proper payload to start new geckodriver-based FirefoxDriver as well as legacy xpi-based FirefoxDriver. The way you attempted to pass profile is suitable for the legacy driver only.

guru-23 commented 7 years ago

@barancev Thanks a lot for the quick response, your suggested solution works.

shs96c commented 7 years ago

Lots of existing docs lead to users expecting this to work.

avineshks commented 7 years ago

Use FirefoxOptions to work with Custom Firefox profiles. Below code works like charm for custom profile.

FirefoxProfile` profile = new FirefoxProfile(new File(path_to_ptofile));
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
WebDriver driver = new RemoteWebDriver( new URL(sel_host_url), options.toCapabilities());
barancev commented 6 years ago

FirefoxOptions implements Capabilities now, and the code from my comment above can be simplified:

FirefoxOptions options = new FirefoxOptions();
options.addPreference("network.proxy.type", 0);
driver = new RemoteWebDriver(options);
WarleyGabriel commented 6 years ago

I tried with the following code and did not succeed when loading the user into the remote Web Driver: Same problem reported in issue: #5026

System.setProperty("webdriver.firefox.profile","profile_name")
FirefoxOptions firefoxOptions = new FirefoxOptions()
def d = new RemoteWebDriver (
new URL(gridUri), firefoxOptions
    )
barancev commented 6 years ago

System properties are local to the current process.

hm1rafael commented 6 years ago

Hi @barancev The FirefoxOptions constructor reads this properties and sets the profile. Thanks

WarleyGabriel commented 6 years ago

Hi @barancev, I've tried the following:

If there is any additional information/help I can provide, please let me know.

namedgraph commented 6 years ago

What is the status here?

WarleyGabriel commented 6 years ago

@pumba-lt I believe there is an issue. I've solved it by installing an extension.

AlexeyDP commented 6 years ago

P.S: On my local Windows machine this user doesn't really exists, only in the Selenium Hub, on the Ubuntu machine.

In your case, you create Profile object before passing it to RemoteWebDriver constructor, so obviously, Profile would be null because profile file is absent on your local machine where you create Profile object. Please let me know if I am mistaken

WarleyGabriel commented 6 years ago

Oh, yes. You are correct. Thanks!

AlexeyDP commented 6 years ago

you are welcome

akshattambe commented 5 years ago

Using FF-63 and Selenium-server-standalone-3.14.0 FirefoxOptions.toCapabilities() is not available anymore or am in missing any library reference ??

diemol commented 4 years ago

The docs have been revamped some months ago and we do not have so much information about profiles. Nevertheless, this issue seems that it should not belong in this repo but rather in the docs one. We would appreciate help over there creating docs related to this topic. As we are doing an issue cleanup, I will close this one since no actions from the team are needed.