0

我正在尝试在 selenium webdriver 中捕获网络流量,但我没有得到生成的 Har 文件。

FirefoxProfile profile = new FirefoxProfile();

File firebug = new File(System.getProperty("user.dir")
            + "/CaptureNetTraffic/firebug-2.0.1.xpi");
File netExport = new File(System.getProperty("user.dir")
            + "/CaptureNetTraffic/netExport-0.5.xpi");
try {
    profile.addExtension(firebug);
    profile.addExtension(netExport);
} catch (IOException io) {
    io.printStackTrace();
}

// Set default Firefox preferences
profile.setPreference("app.update.enabled", false);
String domain = "extension.firebug.";

// Set default Firebug preferences
profile.setPreference(domain + "currentVersion", "2.0");
profile.setPreference(domain + "addonBarOpened", true);
profile.setPreference(domain + "console.enableSites", true);
profile.setPreference(domain + "script.enableSites", true);
profile.setPreference(domain + "net.enableSites", true);
profile.setPreference(domain + "allPagesActivation", 1);
profile.setPreference(domain + "addonBarOpened", "on");
profile.setPreference(domain + "onByDefault", true);
profile.setPreference(domain + "defaultPanelName", "net");

// Set default NetExport preferences
profile.setPreference(domain + "netexport.alwaysEnableAutoExport",true);
profile.setPreference(domain + "netexport.Automation", true);
profile.setPreference(domain + "netexport.showPreview", false);
profile.setPreference(domain + "netexport.defaultLogDir", "D:\\myHar");
profile.setPreference(domain + "netexport.autoExportToFile", true);
profile.setPreference(domain + "netexport.sendToConfirmation", false);

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(capabilities); 
   driver.navigate().to("www.google.com");
4

0 回答 0