如何为BrowserMobProxyServer创建日志文件

时间:2019-02-22 09:31:52

标签: java selenium proxy selenium-chromedriver browsermob-proxy

这里我正在尝试使用代理打开chrome,但是chrome显示错误“ ERR_PROXY_CONNECTION_FAILED” ,因此我需要BrowseProxyServer日志进行调试,请提出如何保存它们的提示。

public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", chrome_path);
        System.setProperty("webdriver.chrome.logfile", "chromedriver.log");
        System.setProperty("webdriver.chrome.verboseLogging", "true");
        BrowserMobProxyServer proxy = new BrowserMobProxyServer();
        // SSL related
        proxy.setTrustAllServers(true);
        proxy.start();

        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
        ChromeOptions options = new ChromeOptions();
        options.setCapability(CapabilityType.PROXY, seleniumProxy);
        options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
        options.addArguments("--ignore-certificate-errors");

        WebDriver driver = new ChromeDriver(options);

        driver.get("https://space.com/?tmn-debug=2&tmn-ip=73.222.216.161");
        try {
            Thread.sleep(5000);
            Har har = proxy.getHar();
            java.io.StringWriter writer = new java.io.StringWriter();
            har.writeTo(writer);
            String harAsString = writer.toString();
            System.out.println(harAsString);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.close();
        proxy.stop();
    }

}

0 个答案:

没有答案