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

Comments

Projects
None yet
2 participants
@mjedracz
Copy link

mjedracz commented Sep 28, 2018

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

This comment has been minimized.

Copy link
Member

BorisOsipov commented Sep 28, 2018

I guess it is the same as #676

@BorisOsipov

This comment has been minimized.

Copy link
Member

BorisOsipov commented Sep 28, 2018

Not is is different.

@BorisOsipov BorisOsipov self-assigned this Sep 29, 2018

BorisOsipov added a commit that referenced this issue Sep 29, 2018

Fixed #817
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

Merge pull request #818 from codeborne/#817
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