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

前端 未结 3 1344
温柔的废话
温柔的废话 2021-01-14 03:28

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 (HT

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 03:30

    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);
    

提交回复
热议问题