需要在selenium webdriver代码中使用代理捕获网络流量 [英] Need to capture network traffic using proxy in selenium webdriver code
本文介绍了需要在selenium webdriver代码中使用代理捕获网络流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class Test_One {
/ **
* @param args
* @throws异常
$ / b $ b public static void main(String [] args)throws Exception {
// TODO自动生成的方法存根
ProxyServer server = new ProxyServer(8090);
server.start();
server.setCaptureHeaders(true);
server.setCaptureContent(true);
server.newHar(test);
DesiredCapabilities功能=新的DesiredCapabilities();
Proxy proxy = server.seleniumProxy();
FirefoxProfile配置文件=新的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驱动程序=新的FirefoxDriver(功能);
driver.get(http://www.google.com);
Har har1 = server.getHar();
server.stop();
driver.quit();
$ / code $ / pre
解决方案最新版本的Selenium Webdriver并不真正支持流量捕获。但是,您可以使用BrowserMob代理来捕获流量。 https://github.com/lightbody/browsermob-proxy 。自述文件中有关于如何使用Selenium的例子。
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();
}
}
解决方案 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.
这篇关于需要在selenium webdriver代码中使用代理捕获网络流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文