设置Http代理时,我无法使用Browsermob Proxy获取网络日志,它只会创建一个har文件,但我无法在文件中看到任何日志
以下是我的代码: -
String strFilePath = "./PerformanceLogs/PerformanceLogs.har";
String noProxy = "localhost, 127.0.0.1";
LegacyProxyServer server = new BrowserMobProxyServer();
server.start();
server.setCaptureHeaders(true);
server.setCaptureContent(true);
Proxy proxy = server.seleniumProxy().setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY)
.setNoProxy(noProxy);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
server.newHar("NetworkLogs");
driver.navigate().to("https://url-");
driver.findElements(xpath="").click();
pMonitor = new Prism_Selenium_Monitor_Tab(driver);
pMonitor.prism_monitor_credentialDeploy(URL,excelfile[0], excelfile[4]);
Har har = server.getHar();
File harFile = new File(strFilePath);
har.writeTo(harFile);
server.stop();
有人可以请我这个吗? 提前致谢
答案 0 :(得分:0)
出于某种原因,您正在启动LegacyProxy,请尝试启动BrowserMobProxyServer,即
BrowserMobProxyServer server = new BrowserMobProxyServer();
默认代理类型是HTTP,即尝试删除此部分:
.setNoProxy(NOPROXY);
这实际上应该不是问题,但在默认情况下,不需要为你的HAR命名,即这段代码是多余的:
server.newHar( “NetworkLogs”);
你可能只是:
server.newHar();