使用Chrome浏览器获取空的har文件 使用以下罐子: BMP:2.1.5 硒版:3.14 Chrome版本:74 Chrome驱动程式:2.37 但是har文件无法捕获任何网络流量
尝试同时使用https和http,但获取具有以下内容的har文件。 ({“ log”:{“ version”:“ 1.2”,“ creator”:{“ name”:“ BrowserMob Proxy”,“ version”:“ 2.1.5”,“ comment”:“”},“ pages” :[{“ id”:“ BMP.har”,“ startedDateTime”:“ 2019-05-27T06:33:24.278Z”,“ title”:“ BMP.har”,“ pageTimings”:{“ comment”:“ “},”评论“:”“}],”条目“:[],”评论“:”“}} )
公共类BrowserMob {
public static WebDriver driver;
public static BrowserMobProxyServer proxy;
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\212744776\\eclipse-workspace\\Browser-Mob\\resources\\chromedriver.exe");
proxy = new BrowserMobProxyServer();
proxy.setMitmDisabled(true);
proxy.setTrustAllServers(true);
proxy.setHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
proxy.enableHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
proxy.start();
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
try {
String hostIp = Inet4Address.getLocalHost().getHostAddress();
seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());
} catch (UnknownHostException e) {
e.printStackTrace();
Assert.fail("invalid Host Address");
}
ChromeOptions options = new ChromeOptions();
DesiredCapabilities capabilities = new DesiredCapabilities();
options.addArguments("--ignore-certificates-errors");
capabilities.setCapability(ChromeOptions.CAPABILITY, capabilities);
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
driver = new ChromeDriver(options);
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
try {
proxy.newHar("BMP.har");
driver.get("https://10.12.42.121/");
//driver.get("https://google.com");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(proxy.getHar().getLog().getEntries().size());
Har har = proxy.getHar();
File harFile = new File("BMPTraffic.har");
har.writeTo(harFile);
} catch (IOException ioe) {
ioe.printStackTrace();
}
driver.quit();
proxy.stop();
}
}