Interface Test-browsermob-proxy
Provides the command line method or is embedded into the Java project to generate the HAR file plug-in through api, which is a sub-project of selenium. The specific process is a bit similar to fenders der or Charles. How to enable a port to monitor all HTTP requests under a port for data capture.
Java API dependency
compile 'net.lightbody.bmp:browsermob-core-littleproxy:2.1.0-beta-4' compile 'org.seleniumhq.selenium:selenium-java:2.49.0'
Code
BrowserMobProxy proxy = new BrowserMobProxyServer(); proxy.start(); Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); WebDriver driver = new FirefoxDriver(capabilities); proxy.newHar("http://www.baidu.com"); driver.get("http://www.baidu.com"); Har har = proxy.getHar(); har.writeTo(new File("baidu.com.har")); driver.close();
The running process is as follows:
Command Line
Download the release version, decompress it, go to the bin directory, and execute the command
sh browsermob-proxy
Output the following information:
58deMacBook-Pro-7:bin wuxian$ sh browsermob-proxy Running BrowserMob Proxy using LittleProxy implementation. To revert to the legacy implementation, run the proxy with the command-line option '--use-littleproxy false'. [INFO 2016-01-14T19:23:50,254 net.lightbody.bmp.proxy.Main] (main) Starting BrowserMob Proxy version 2.1.0-beta-4 [INFO 2016-01-14T19:23:51,510 org.eclipse.jetty.util.log] (main) jetty-7.x.y-SNAPSHOT [INFO 2016-01-14T19:23:51,546 org.eclipse.jetty.util.log] (main) started o.e.j.s.ServletContextHandler{/,null} [INFO 2016-01-14T19:23:52,463 org.eclipse.jetty.util.log] (main) Started SelectChannelConnector@auto.58corp.com:8080