Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirefoxDriverFactory overwrites Firefox profile provided by Configuration #817

Closed
mjedracz opened this issue Sep 28, 2018 · 2 comments
Closed

Comments

@mjedracz
Copy link

The problem

FirefoxDriverFactory overwrites Firefox profile provided by Configuration.browserCapabilities

Details

I was trying to start Firefox with a custom profile with some certificates so the easiest approach was to set Configuration.browserCapabilities = capabilitiesWithFirefoxProfile; . However, when using default Firefox driver provider, profile capability is overwritten in com.codeborne.selenide.webdriver.FirefoxDriverFactory#transferFirefoxProfileFromSystemProperties.
It can be worked around by implementing provider on your own but it's something I'd rather avoid if that is the only reason to implement it :)

Tell us about your environment

  • Selenide Version: 4.14.2
  • Firefox version: 62.0

Code To Reproduce Issue

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("security.default_personal_cert", "Select Automatically");
FirefoxOptions firefoxOptions = new FirefoxOptions().setProfile(profile);

Configuration.browser = "firefox";
Configuration.browserCapabilities = new DesiredCapabilities(firefoxOptions);

Selenide.open("https://github.com/codeborne/selenide");

Then navigate to about:config and check security.default_personal_cert property, it should be set to "Select Automatically"

Possible fix

My suggestion would be to load FirefoxProfile from passed FirefoxOptions in com.codeborne.selenide.webdriver.FirefoxDriverFactory#transferFirefoxProfileFromSystemProperties, this would allow to set the profile in code and add another profile preferences from system properties.
The method would look like this:

private FirefoxOptions transferFirefoxProfileFromSystemProperties(FirefoxOptions currentFirefoxOptions) {
        String prefix = "firefoxprofile.";
        FirefoxProfile profile = Optional.ofNullable(currentFirefoxOptions.getProfile())
                                         .orElseGet(FirefoxProfile::new);
        for (String key : System.getProperties().stringPropertyNames()) {
            if (key.startsWith(prefix)) {
                String capability = key.substring(prefix.length());
                String value = System.getProperties().getProperty(key);
                log.config("Use " + key + "=" + value);
                if (value.equals("true") || value.equals("false")) {
                    profile.setPreference(capability, Boolean.valueOf(value));
                }
                else if (value.matches("^-?\\d+$")) { //if integer
                    profile.setPreference(capability, Integer.parseInt(value));
                }
                else {
                    profile.setPreference(capability, value);
                }
            }
        }
        return currentFirefoxOptions.setProfile(profile);
    }
@BorisOsipov
Copy link
Member

I guess it is the same as #676

@BorisOsipov
Copy link
Member

Not is is different.

@BorisOsipov BorisOsipov self-assigned this Sep 29, 2018
BorisOsipov added a commit that referenced this issue Sep 29, 2018
Change default value for Configuration.browserCapabilities to not null
Fix FirefoxDriverFactory overwrites Firefox profile provided by Configuration issue
BorisOsipov added a commit that referenced this issue Sep 30, 2018
Fix FirefoxDriverFactory overwrites Firefox profile provided by Configuration issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants