无法使用Selenium Webdriver通过BrowserMob代理获取网络流量日志

时间:2016-04-27 04:38:30

标签: selenium proxy browsermob-proxy

设置Http代理时,我无法使用Browsermob Proxy获取网络日志,它只会创建一个har文件,但我无法在文件中看到任何日志

以下是我的代码: -

String strFilePath = "./PerformanceLogs/PerformanceLogs.har";
            String noProxy = "localhost, 127.0.0.1";

        LegacyProxyServer server = new BrowserMobProxyServer();
        server.start();
        server.setCaptureHeaders(true);
        server.setCaptureContent(true);
        Proxy proxy = server.seleniumProxy().setHttpProxy(PROXY)
                .setFtpProxy(PROXY)
                .setSslProxy(PROXY)
                .setNoProxy(noProxy);

         DesiredCapabilities capabilities = DesiredCapabilities.firefox();
         capabilities.setCapability(CapabilityType.PROXY, proxy);

         WebDriver driver = new FirefoxDriver(capabilities);

        server.newHar("NetworkLogs");
        driver.navigate().to("https://url-");

        driver.findElements(xpath="").click();

        pMonitor = new Prism_Selenium_Monitor_Tab(driver);
        pMonitor.prism_monitor_credentialDeploy(URL,excelfile[0], excelfile[4]);

        Har har = server.getHar();
        File harFile = new File(strFilePath);
        har.writeTo(harFile);
        server.stop();

有人可以请我这个吗? 提前致谢

1 个答案:

答案 0 :(得分:0)

  1. 出于某种原因,您正在启动LegacyProxy,请尝试启动BrowserMobProxyServer,即

    BrowserMobProxyServer server = new BrowserMobProxyServer();

  2. 默认代理类型是HTTP,即尝试删除此部分:

    .setNoProxy(NOPROXY);

  3. 这实际上应该不是问题,但在默认情况下,不需要为你的HAR命名,即这段代码是多余的:

    server.newHar( “NetworkLogs”);

  4. 你可能只是:

    server.newHar();