ui5-uiveri5 icon indicating copy to clipboard operation
ui5-uiveri5 copied to clipboard

capabilities for firefox not working

Open davidhennemann opened this issue 5 years ago • 7 comments

Hi there,

Is there a possibility to pass capabilities to firefox? I would like to pass the acceptInsecureCerts: true option to selenium. I tried with the following config:

browsers: [
    {
      browserName: 'firefox',
      capabilities: {
        acceptInsecureCerts: true,
      },
    },
  ],

Unfortunately the firefox instance seems to ignore this flag. In the -v log it tells:

D/runner - WebDriver session successfully started with capabilities Capabilities {
  map_: Map {
    'acceptInsecureCerts' => false,
    'browserName' => 'firefox',
    'browserVersion' => '70.0',
    'moz:accessibilityChecks' => false,
    'moz:buildID' => '20191016161957',
    'moz:geckodriverVersion' => '0.26.0',
    'moz:headless' => false,
    'moz:processID' => 87228,
    'moz:profile' => '/var/folders/5r/41x85gd54ygbp93pg7fsrx3r0000gn/T/rust_mozprofilePW2VHI',
    'moz:shutdownTimeout' => 60000,
    'moz:useNonSpecCompliantPointerOrigin' => false,
    'moz:webdriverClick' => true,
    'pageLoadStrategy' => 'normal',
    'platformName' => 'mac',
    'platformVersion' => '18.7.0',
    'rotatable' => false,
    'setWindowRect' => true,
    'strictFileInteractability' => false,
    'timeouts' => { implicit: 0, pageLoad: 300000, script: 30000 },
    'unhandledPromptBehavior' => 'dismiss and notify'
  }
}

Reference to the capability in the webdriver documentation: https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/acceptInsecureCerts

davidhennemann avatar Oct 29 '19 20:10 davidhennemann

Hi, in the version of selenium-webdriver (3.6) that we use, this is a setting of the Firefox profile but currently, we do not support building and using custom firefox profile. Not that it is a big problem but we never had the request to do so. Unfortunately, I do not see a workaround right now. Maybe we will be able to push this feature in the next takt e.g. in 4 weeks.

maximnaidenov avatar Oct 30 '19 11:10 maximnaidenov

Hi, thank you for the fast answer! We would need this ability because we are trying to make REST-calls to a localhost https-server, which at the moment only works from chrome, because of certificate issues with firefox. I would also be more than happy to support with a PR for this feature. Maybe you could point me into a direction for this? Otherwise we are not really in a rush, so a few weeks shouldn't be a problem.

davidhennemann avatar Oct 30 '19 17:10 davidhennemann

Hi David, thanks for the offer, actually it would be no more than 10 lines of code. In directDriverProvider.js we build the firefox driver, see lines 522 till 551. We process geckdriverOptions and build the FirefoxServicebuilder, then we build FirefoxOptions from firefoxOptions. The profile is a more complex "option". So we could use firefoxProfile and parse it to Profile object and add to options. Just the way we build the options object on lines 539-545

maximnaidenov avatar Oct 31 '19 06:10 maximnaidenov

Hi David, thanks for the offer, actually it would be no more than 10 lines of code.

@davidhennemann PR! PR! PR! :) :) :)

vobu avatar Oct 31 '19 08:10 vobu

Okay, i will look into it!

davidhennemann avatar Nov 01 '19 16:11 davidhennemann

So i looked into it today and tried to follow @maximnaidenov instruction (very helpful, thanks for that!). For testing purpose i hard-wired the config changes into the code and did not passed them dynamically. I ended up with:

// ...
//
// no firefox.Options.fromCapabilities() so need to build firefoxOptions manually
var firefoxOptions = new that.deps.firefox.Options();

var capabilitiesFirefoxOptions = this.protConfig.capabilities.firefoxOptions;
if (capabilitiesFirefoxOptions) {
    _.forIn(capabilitiesFirefoxOptions, function(value, key) {
    firefoxOptions[key].apply(firefoxOptions, value);
    });
}

// CHANGES start

// create firefox profile and append it to options
let firefoxProfile = new that.deps.firefox.Profile();
firefoxProfile.setAcceptUntrustedCerts(true);
firefoxProfile.setAssumeUntrustedCertIssuer(false);
firefoxProfile.setPreference('browser.newtabpage.enabled', true);
firefoxOptions.setProfile(firefoxProfile);

// CHANGES end

It seems like the new profile indeed is used by firefox. I noticed this because browser.newtabpage.enabled lead to a new-tab being opened with the default firefox new-tab page (without this flag its just a white page). Unfortunately firefox still did not accept my self signed certificate and produced errors and warnings about this.

And in the starting log it still logs:

D/runner - WebDriver session successfully started with capabilities Capabilities {
  map_: Map {
    'acceptInsecureCerts' => false,
    ...
  }
}

I think i maybe need to alter the capabilities. But i am not sure how to access those. Do you have any ideas? Thank you!

davidhennemann avatar Nov 04 '19 23:11 davidhennemann

It could be a problem due to the changes around WebDriver protocol that goes to a W3C standart REST protocol. Some of the properties are now prefixed with moz: but I am not sure how this really works with our version of webdriverjs

maximnaidenov avatar Nov 13 '19 13:11 maximnaidenov