【问题标题】:Chrome browser certificate is not trusted issue using browsermob-proxyChrome 浏览器证书不是使用 browsermob-proxy 的受信任问题
【发布时间】:2019-11-20 12:09:30
【问题描述】:

是否有办法让 chrome 忽略使用 browsermob-proxy 导致的无效证书

我使用 google.com 只是出于示例原因,在实际情况下,我需要提供凭据和登录名,而无效的证书会阻止我继续。

please note here that the proxy is working perfectly and after i used all args to ignore the certificate issue https://i.stack.imgur.com/dG4Vl.png

    import java.io.File;
    import org.openqa.selenium.Proxy;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.CapabilityType;
    import org.testng.annotations.Test;
    import net.lightbody.bmp.BrowserMobProxy;
    import net.lightbody.bmp.BrowserMobProxyServer;
    import net.lightbody.bmp.client.ClientUtil;
    import net.lightbody.bmp.core.har.Har;

    public class Proxytest4 {
    WebDriver driver = null;
    BrowserMobProxy proxy = null;

    @Test
    public void actionLaunchRegistrationPage() throws Exception {

        System.setProperty("webdriver.chrome.driver", "/Users/path/chromedriver");
        System.setProperty("webdriver.chrome.logfile", "/Users/path/hromedriver_issue.log");

        proxy = new BrowserMobProxyServer();
        proxy.setTrustAllServers(true);
        proxy.start(0);

        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

        ChromeOptions options = new ChromeOptions();

        options.addArguments("--proxy-server=" + seleniumProxy.getHttpProxy());
        options.addArguments("--no-sandbox");
        options.addArguments("--start-maximized");
        options.addArguments("--disable-extensions");
        options.addArguments("disable-gpu");
        options.addArguments("window-size=1920,1080");

        // options.setAcceptInsecureCerts(true);
        options.addArguments("--allow-insecure-localhost");
        options.addArguments("--ignore-certificate-errors");
        options.addArguments("--allow-running-insecure-content");

        // DesiredCapabilities cap = DesiredCapabilities.chrome();
        // cap.acceptInsecureCerts();
        // cap.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
        // cap.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);

        // cap.setCapability(ChromeOptions.CAPABILITY, options);

        // options.setAcceptInsecureCerts(true);

        // options.merge(cap);

        options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

        // driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);

        driver = new ChromeDriver(options);

        // create a new HAR with the label "yahoo.com"
        proxy.newHar("https://www.google.com/");

        driver.get("https://www.google.com/");

        // get the HAR data
        Har har = proxy.getHar();

        // Writing Har to file

        har.getLog().toString();
        har.writeTo(new File("/Users/path/HAR.txt"));
        // driver.quit();
        // browserStackLocal.stop();
        proxy.stop();
    }

    }

【问题讨论】:

    标签: selenium ssl selenium-webdriver selenium-chromedriver browsermob-proxy


    【解决方案1】:

    修复如下:

    1- 从以下链接下载 browsermob-proxy 证书: https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-core/src/main/resources/sslSupport/ca-certificate-rsa.cer

    2- 在 OS X 中打开 Keychain Access 实用程序。

    • 选择左侧的系统选项。单击屏幕上的锁定图标 左上角以启用更改。

    enter image description here

    • 在左下角,选择“证书”选项。

    enter image description here

    • 将复制到桌面的证书拖到 证书。将 localhost 添加到系统钥匙串后, 双击它以再次打开它。展开信任部分并为 第一个选项,选择 Always Trust。

    enter image description here

    【讨论】:

      【解决方案2】:

      我认为--disable-web-security 是您想要的选项。

      【讨论】:

      • 谢谢,但我试过了,尝试登录时没有收到错误“加载资源失败:net::ERR_PROXY_CONNECTION_FAILED”
      • 是的,这是一个单独的问题。
      猜你喜欢
      • 2014-07-07
      • 2020-11-24
      • 2020-06-05
      • 2015-12-06
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多