Need to capture network traffic using proxy in sel

2019-02-25 02:10发布

Need capture network traffic using proxy in selenium webdriver code.. I've tried with below code but after opening browser google.com is not loading getting the error "proxy server that is refusing connections"

public class Test_One {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ProxyServer server = new ProxyServer(8090);
         server.start();
         server.setCaptureHeaders(true);

         server.setCaptureContent(true);
         server.newHar("test");
         DesiredCapabilities capabilities = new DesiredCapabilities();
         Proxy proxy = server.seleniumProxy();
         FirefoxProfile profile = new FirefoxProfile();
         profile.setAcceptUntrustedCertificates(true);
         profile.setAssumeUntrustedCertificateIssuer(true);
         profile.setPreference("network.proxy.http", "localhost");
         profile.setPreference("network.proxy.http_port", 8090);
         profile.setPreference("network.proxy.ssl", "localhost");
         profile.setPreference("network.proxy.ssl_port", 8090);
         profile.setPreference("network.proxy.type", 1);
         profile.setPreference("network.proxy.no_proxies_on", "");
         profile.setProxyPreferences(proxy);
         capabilities.setCapability(FirefoxDriver.PROFILE,profile);
         capabilities.setCapability(CapabilityType.PROXY, proxy);
         WebDriver driver = new FirefoxDriver(capabilities);
         driver.get("http://www.google.com");
         Har har1 = server.getHar();
         server.stop();
         driver.quit();
         }
}

1条回答
祖国的老花朵
2楼-- · 2019-02-25 03:02

The latest version of Selenium Webdriver does not really support traffic capture. You can however, use BrowserMob proxy to capture traffic. https://github.com/lightbody/browsermob-proxy . The README has examples on how to do that with Selenium.

查看更多
登录 后发表回答