The browsermob-proxy in use is 2.1.5. The code is running well but no request and response capture in the har files. Could u help review the code and point where is wrong? Many thanks !
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
testCompile group: 'net.lightbody.bmp', name: 'browsermob-proxy', version: '2.1.5'
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
System.setProperty("webdriver.firefox.bin",
"C:\\Program Files\\Mozilla Firefox\\updated\\firefox.exe");
String driverPath=System.getProperty("user.dir")+"/geckodriver-v0.29.0-win64/geckodriver.exe";
System.setProperty("webdriver.gecko.driver",driverPath);
WebDriver driver = new FirefoxDriver(capabilities);
// enable more detailed HAR capture, if desired (see CaptureType for the
// complete list)
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT,CaptureType.REQUEST_HEADERS);
System.out.println(driver.getCurrentUrl());
WebElement searchBox = driver.findElement(By.id("kw"));
searchBox.sendKeys("Selenium");
driver.findElement(By.id("su")).submit();;
System.out.println(driver.getCurrentUrl());
// get the HAR data
Har har = proxy.getHar();
System.out.println(proxy.getPort());
FileOutputStream fos = new FileOutputStream("C:\\Work\\HAR-Information-baidu.har");
har.writeTo(fos);
proxy.stop();
driver.close();