Closed guru-23 closed 4 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.
@barancev Thanks a lot for the quick response, your suggested solution works.
Lots of existing docs lead to users expecting this to work.
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());
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);
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
)
System properties are local to the current process.
Hi @barancev The FirefoxOptions constructor reads this properties and sets the profile. Thanks
Hi @barancev, I've tried the following:
Pass a profile name:
FirefoxProfile firefoxProfile = new FirefoxProfile().setPreference("webdriver.firefox.profile","esaj")
FirefoxOptions firefoxOptions = new FirefoxOptions().setProfile(firefoxProfile)
Get the profile through the ProfilesIni
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("esaj")
FirefoxOptions firefoxOptions = new FirefoxOptions()
firefoxOptions.setProfile(firefoxProfile)
In both cases the result is: org.openqa.selenium.WebDriverException: Unexpected value for profile: null
Pass profile's path that is located at the same machine as Selenium Hub:
FirefoxProfile firefoxProfile = new FirefoxProfile( new File ("/home/seluser/.mozilla/firefox"))
FirefoxOptions firefoxOptions = new FirefoxOptions().setProfile(firefoxProfile)
This results in: org.openqa.selenium.firefox.UnableToCreateProfileException: Given model profile directory does not exist: \home\seluser.mozilla\firefox P.S: I don't really have this path on my local machine, I execute the tests from a Windows machine, that opens a browser window in the Selenium Hub that is hosted on an Ubuntu machine.
Pass the profile name before creating a FirefoxOptions object:
System.setProperty("webdriver.firefox.profile","esaj")
FirefoxOptions firefoxOptions = new FirefoxOptions()
This results in: org.openqa.selenium.WebDriverException: Firefox profile 'esaj' named in system property 'webdriver.firefox.profile' not found P.S: On my local Windows machine this user doesn't really exists, only in the Selenium Hub, on the Ubuntu machine.
If there is any additional information/help I can provide, please let me know.
What is the status here?
@pumba-lt I believe there is an issue. I've solved it by installing an extension.
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
Oh, yes. You are correct. Thanks!
you are welcome
Using FF-63 and Selenium-server-standalone-3.14.0 FirefoxOptions.toCapabilities() is not available anymore or am in missing any library reference ??
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.
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.
Create remote webdriver using the above capability object and continue with the test
new RemoteWebDriver(new URL(SELENIUM_REMOTE_URL), (capabilities));
Test case 2 :
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.