Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Your connection is not secure - using Selenium.WebDriver v.3.6.0 + Firefox v.56

I'm writing tests with Selenium + C# and I face an important issue because I didn't found solution when I test my site with secure connection (HTTPS). All solutions I found on stackoverflow are out of date or doesn't work. I tried to exercise all solutions from below question: Selenium Why setting acceptuntrustedcertificates to true for firefox driver doesn't work?

But they did not help me solve the problem Nor is it the solution of using Nightly FireFox. Still, when the selenium loading Firfox browser, I see the page: "Your connection is not secure".

Configuration:

  • Firefox v56.0
  • Selenium.Firefox.WebDriver v0.19.0
  • Selenium.WebDriver v3.6.0

my code is:

                    FirefoxOptions options = new FirefoxOptions();
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.AcceptUntrustedCertificates = true;
                    profile.AssumeUntrustedCertificateIssuer = false;
                    options.Profile = profile;
                    driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService() , options , TimeSpan.FromSeconds(5));
                    Drivers.Add(Browsers.Firefox.ToString() , driver);

Thank for your help!

Updates to my question here:

Note 1: To anyone who has marked my question as a duplicate of this question:

Firefox selenium webdriver gives “Insecure Connection” I thought that it is same issue, but I need solution for C#, I try match your JAVA code to my above code

First, I changed to TRUE the below statment:

     profile.AssumeUntrustedCertificateIssuer = true;

second, I create new FF profile ("AutomationTestsProfile") and try to use it:

Try 1:

       FirefoxProfile profile = new FirefoxProfileManager().GetProfile("AutomationTestsProfile");

try 2:

       FirefoxProfile profile = new FirefoxProfile("AutomationTestsProfile");

I Run 2 options, but still the issue exists.

Note 2: I attached screenshot of my problem, it appears when the driver try to enter text to user-name on login page.

I noticed that when I open my site with FF, Firefox displays a lock icon with red strike-through red strikethrough icon in the address bar,

but near the username textbox not appears the msg:

"This connection is not secure. Logins entered here could be compromised. Learn More" (as you writed on the duplicate question),

So maybe there is a different problem?

screenshot: "insecure Connection" tab

like image 475
C. Mar Avatar asked Nov 06 '17 09:11

C. Mar


2 Answers

You are setting the properties on the profile. The FirefoxOptions has a property AcceptInsecureCertificates, set that to true.

Forget the profile, this is what you want:

var op = new FirefoxOptions
{
    AcceptInsecureCertificates = true
};

Instance = new FirefoxDriver(op);
like image 161
Jota Alava Avatar answered Nov 10 '22 01:11

Jota Alava


For me, the profile setting AcceptUntrustedCertificates was not enough, I also had to set option security.cert_pinning.enforcement_level. My startup looks like

// no idea why FirefoxWebDriver needs this, but it will throw without
// https://stackoverflow.com/questions/56802715/firefoxwebdriver-no-data-is-available-for-encoding-437
CodePagesEncodingProvider.Instance.GetEncoding(437);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

var service = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);
service.FirefoxBinaryPath = Config.GetConfigurationString("FirefoxBinaryPath"); // path in appsettings

var options = new FirefoxOptions();
options.SetPreference("security.cert_pinning.enforcement_level", 0);
options.SetPreference("security.enterprise_roots.enabled", true);

var profile = new FirefoxProfile()
{
    AcceptUntrustedCertificates = true,
    AssumeUntrustedCertificateIssuer = false,
};
options.Profile = profile;

var driver = new FirefoxDriver(service, options);
like image 3
BurnsBA Avatar answered Nov 10 '22 03:11

BurnsBA