mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.12k stars 1.52k forks source link

Unable to trust SSL certificates during local execution with Firefox 52.0.1 and geckodriver 0.15.0 #563

Closed KPKA closed 7 years ago

KPKA commented 7 years ago

It is possible to execute tests with RemoteWebDriver and to trust the certificates. I am doing it like this: var capabilities = DesiredCapabilities.Firefox(); capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile); capabilities.SetCapability("marionette", true); capabilities.SetCapability("acceptSslCerts", true); capabilities.SetCapability("acceptInsecureCerts", true); var timeSpan = TimeSpan.FromSeconds(120); var uri = new Uri(“www.anyuri.com”); var driver = new RemoteWebDriver(uri, capabilities, timeSpan);

If I try the same for executing the tests locally I am getting a certificate error in Firefox. Below in "Steps to reproduce" I added what I have already tried. Can anybody help me with my problem? I want to execute the tests locally and remotely and I am struggling to do this.

Firefox Version

52.0.1 (32 bit/64 bit)

Platform

Windows 7

Steps to reproduce -

I tried it in several ways for a local execution but I am always getting a certificate error in Firefox:

I have added the Firefox execution location and the geckodriver execution location to my PATH environment variable. I tried everything with Firefox 52.0.1 32 bit and Firefox 52.0.1 64 bit.

trace level log:

options.LogLevel = FirefoxDriverLogLevel.Trace;
options.AddAdditionalCapability("acceptSslCerts", true);
options.AddAdditionalCapability("acceptInsecureCerts", true);
var driver = new FirefoxDriver(options);
1490182506271   geckodriver::marionette INFO    Starting browser C:\Program File
s\Mozilla Firefox\firefox.exe with args []
1490182506386   geckodriver::marionette INFO    Connecting to Marionette on loca
lhost:53760
1490182507385   geckodriver::marionette DEBUG   TCP connection established
1490182507407   geckodriver::marionette DEBUG   ← {"applicationType":"gecko","ma
rionetteProtocol":3}
1490182507407   geckodriver::marionette DEBUG   → 176:[0,1,"newSession",{"capabi
lities":{"desiredCapabilities":{"browserName":"firefox","marionette":true,"platf
orm":"ANY","version":""},"requiredCapabilities":{}},"sessionId":null}]
1490182508032   geckodriver::marionette DEBUG   ← [1,1,null,{"sessionId":"a760f6
62-6581-4e34-a954-1b5301000035","capabilities":{"browserName":"firefox","browser
Version":"52.0.1","platformName":"windows_nt","platformVersion":"6.1","pageLoadS
trategy":"normal","acceptInsecureCerts":false,"timeouts":{"implicit":0,"page loa
d":300000,"script":30000},"rotatable":false,"specificationLevel":0,"moz:processI
D":8408,"moz:profile":"C:\\Users\\test\\AppData\\Local\\Temp\\rust_mozprofile.To
jI21BK3zyq","moz:accessibilityChecks":false}}]
1490182508032   webdriver::server       DEBUG   Returning status Ok
1490182508033   webdriver::server       DEBUG   Returning body {"value": {"sessi
onId":"a760f662-6581-4e34-a954-1b5301000035","value":{"acceptInsecureCerts":fals
e,"browserName":"firefox","browserVersion":"52.0.1","moz:accessibilityChecks":fa
lse,"moz:processID":8408,"moz:profile":"C:\\Users\\test\\AppData\\Local\\Temp\\r
ust_mozprofile.TojI21BK3zyq","pageLoadStrategy":"normal","platformName":"windows
_nt","platformVersion":"6.1","rotatable":false,"specificationLevel":0,"timeouts"
:{"implicit":0,"page load":300000,"script":30000}}}}
1490182508033   hyper::header   TRACE   Headers.set( "Content-Type", ContentType
(Mime(Application, Json, [(Charset, Utf8)])) )
1490182508034   hyper::header   TRACE   Headers.set( "Cache-Control", CacheContr
ol([NoCache]) )
1490182508035   hyper::header   TRACE   Headers.set( "Content-Length", ContentLe
ngth(469) )
1490182508036   hyper::server::response DEBUG   writing head: Http11 Ok
1490182508037   hyper::header   TRACE   Headers.set( "Date", Date(HttpDate(Tm {
tm_sec: 8, tm_min: 35, tm_hour: 11, tm_mday: 22, tm_mon: 2, tm_year: 117, tm_wda
y: 3, tm_yday: 80, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 37079000 })) )
1490182508039   hyper::server::response DEBUG   headers [
Headers { Connection: close
, Content-Type: application/json; charset=utf-8
, Cache-Control: no-cache
, Content-Length: 469
, Date: Wed, 22 Mar 2017 11:35:08 GMT
, }]
andreastt commented 7 years ago

The acceptInsecureCerts capability is not being set. See the passed and returned capabilities in the log you attached.

KPKA commented 7 years ago

@andreastt : But I have set this capability in all of my code examples (what I've tried) to true. Can you tell me how I have to change my code to make this working?

andreastt commented 7 years ago

What language binding are you using?

The capabilities object your language binding passes, {"capabilities":{"desiredCapabilities":{"browserName":"firefox","marionette":true,"platform":"ANY","version":""},"requiredCapabilities":{}},"sessionId":null} doesn’t contain the necessary acceptInsecureCerts field needed to trigger invalid TLS certificates to be ignored. It would be good if you tried to debug why it isn’t being set when you call options.AddAdditionalCapability("acceptInsecureCerts", true).

Another thing I don’t get about log you pasted above is where the logs originating from Firefox has gone: they are supposed to be inherited by geckodriver and printed.

KPKA commented 7 years ago

@andreastt : I am using Selenium 3.3.0 and .Net 4.5.1

I debugged it and I used the following code:

var options = new FirefoxOptions();
options.LogLevel = FirefoxDriverLogLevel.Trace;
options.AddAdditionalCapability("acceptSslCerts", true);            options.AddAdditionalCapability("acceptInsecureCerts", true);
var driver = new FirefoxDriver(options);

Before starting the driver it is set correctly I think: If I expand the options in my watch, expand Non-Public members, additionalCapabilities are Count = 0 and additionalFirefoxOptions have Count = 2 which contain these two entries: {[acceptSslCerts, True]} and {[acceptInsecureCerts, True]}

When I debug via 'var driver = new FirefoxDriver(options);' he writes in the console output:

1490257672046   geckodriver     INFO    Listening on 127.0.0.1:49581
1490257673291   mozprofile::profile     INFO    Using profile path C:\Users\test
\AppData\Local\Temp\rust_mozprofile.i83MA6AW6RNv
1490257673293   geckodriver::marionette INFO    Starting browser C:\Program File
s\Mozilla Firefox\firefox.exe with args []
1490257673365   geckodriver::marionette INFO    Connecting to Marionette on loca
lhost:49585
1490257674358   geckodriver::marionette DEBUG   TCP connection established
1490257674363   geckodriver::marionette DEBUG   ← {"applicationType":"gecko","ma
rionetteProtocol":3}
1490257674363   geckodriver::marionette DEBUG   → 176:[0,1,"newSession",{"capabi
lities":{"desiredCapabilities":{"browserName":"firefox","marionette":true,"platf
orm":"ANY","version":""},"requiredCapabilities":{}},"sessionId":null}]
1490257674899   geckodriver::marionette DEBUG   ← [1,1,null,{"sessionId":"5a4d62
45-c7d8-4ca8-8649-84c4cb0e4c40","capabilities":{"browserName":"firefox","browser
Version":"52.0.1","platformName":"windows_nt","platformVersion":"6.1","pageLoadS
trategy":"normal","acceptInsecureCerts":false,"timeouts":{"implicit":0,"page loa
d":300000,"script":30000},"rotatable":false,"specificationLevel":0,"moz:processI
D":17528,"moz:profile":"C:\\Users\\test\\AppData\\Local\\Temp\\rust_mozprofile.i
83MA6AW6RNv","moz:accessibilityChecks":false}}]
1490257674901   webdriver::server       DEBUG   Returning status Ok
1490257674902   webdriver::server       DEBUG   Returning body {"value": {"sessi
onId":"5a4d6245-c7d8-4ca8-8649-84c4cb0e4c40","value":{"acceptInsecureCerts":fals
e,"browserName":"firefox","browserVersion":"52.0.1","moz:accessibilityChecks":fa
lse,"moz:processID":17528,"moz:profile":"C:\\Users\\test\\AppData\\Local\\Temp\\
rust_mozprofile.i83MA6AW6RNv","pageLoadStrategy":"normal","platformName":"window
s_nt","platformVersion":"6.1","rotatable":false,"specificationLevel":0,"timeouts
":{"implicit":0,"page load":300000,"script":30000}}}}
1490257674902   hyper::header   TRACE   Headers.set( "Content-Type", ContentType
(Mime(Application, Json, [(Charset, Utf8)])) )
1490257674903   hyper::header   TRACE   Headers.set( "Cache-Control", CacheContr
ol([NoCache]) )
1490257674906   hyper::header   TRACE   Headers.set( "Content-Length", ContentLe
ngth(470) )
1490257674907   hyper::server::response DEBUG   writing head: Http11 Ok
1490257674907   hyper::header   TRACE   Headers.set( "Date", Date(HttpDate(Tm {
tm_sec: 54, tm_min: 27, tm_hour: 8, tm_mday: 23, tm_mon: 2, tm_year: 117, tm_wda
y: 4, tm_yday: 81, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 907240000 })) )
1490257674908   hyper::server::response DEBUG   headers [
Headers { Connection: close
, Content-Type: application/json; charset=utf-8
, Cache-Control: no-cache
, Content-Length: 470
, Date: Thu, 23 Mar 2017 08:27:54 GMT
, }]
1490257674908   hyper::server::response DEBUG   write 470 bytes
1490257674908   hyper::server::response TRACE   ending
1490257674908   hyper::server   DEBUG   keep_alive = false for 127.0.0.1:49584
1490257674908   hyper::server   DEBUG   keep_alive loop ending for 127.0.0.1:495`

You can see that acceptInsecureCerts is false but in my watch it is still true.

I do not know how I can get the logs from Firefox. I had a look at other issues and there you write it is not supported. (eg.: https://github.com/mozilla/geckodriver/issues/330 ) Is it now supported?

prashantmothukuri commented 7 years ago

@andreastt I have found that when using FirefoxOptions, you have to use the AddAdditionalCapability method with isGlobalCapability set to true. This is the code that worked for me.

var options = new FirefoxOptions();
options.AddAdditionalCapability("acceptSslCerts", true, true);
options.AddAdditionalCapability("acceptInsecureCerts", true, true);

var  driver = new FirefoxDriver(options);
KPKA commented 7 years ago

@prashantmothukuri Thank you! It is now working for me, too :-)

andreastt commented 7 years ago

@prashantmothukuri Thanks for pointing that out. Not an issue in geckodriver, fortunately (-:

lock[bot] commented 5 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.