如何在不自动导出的情况下使用SeleniumWebDriver从java生成Har文件?
我在selenium中使用netexport api和firebug实现自动化如何在不自动导出的情况下使用SeleniumWebDriver从java生成Har文件?,java,selenium,firebug,har,netexport,Java,Selenium,Firebug,Har,Netexport,我在selenium中使用netexport api和firebug实现自动化 有两种情况。 自动导出:我在java中启用了带有FF自定义配置文件的此选项,一旦页面加载完成,har文件将自动生成。我也能够解析文件 2.某些页面具有Ajax调用,并在特定DIV中更新响应。因此,我无法捕获/保存特定ajax请求(REST服务)的har文件,因为页面未加载。我想要请求/响应的详细信息是否可以在java中从selenium webdriver手动导出har文件 如果我们在SeleniumWebDrive
有两种情况。
是否可以在java中从selenium webdriver手动导出har文件 如果我们在SeleniumWebDriver(java)中有任何返回har文件或json字符串的命令/函数就好了,我们可以在需要时调用它
自动导出选项为每次页面加载生成har文件
找到了使用AutoIt脚本从java手动导出har文件的解决方法。
需要启用Firefox中的firebug插件,默认情况下将显示网络面板视图,我们可以选择手动导出har文件。
使用Autoit工具,我们可以记录手动导出功能并编译脚本,该脚本将提供.exe文件,我们可以从java调用exe文件
将PhantomJS与BrowserMobProxy一起使用。PhantomJS帮助我们创建支持JavaScript的页面。以下代码也适用于HTTPS web地址 将'phantomjs.exe'放在C驱动器中,您将在C驱动器本身中获得'HAR-Information.HAR'文件 请确保不要在url末尾放置'/',如
driver.get("https://www.google.co.in/")
应该是
driver.get("https://www.google.co.in");
否则,它将不起作用
package makemyhar;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.CaptureType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MakeMyHAR {
public static void main(String[] args) throws IOException, InterruptedException {
//BrowserMobProxy
BrowserMobProxy server = new BrowserMobProxyServer();
server.start(0);
server.setHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
server.newHar("Google");
//PHANTOMJS_CLI_ARGS
ArrayList<String> cliArgsCap = new ArrayList<>();
cliArgsCap.add("--proxy=localhost:"+server.getPort());
cliArgsCap.add("--ignore-ssl-errors=yes");
//DesiredCapabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"C:\\phantomjs.exe");
//WebDriver
WebDriver driver = new PhantomJSDriver(capabilities);
driver.get("https://www.google.co.in");
//HAR
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream("C:\\HAR-Information.har");
har.writeTo(fos);
server.stop();
driver.close();
}
}
package-makemyhar;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.util.ArrayList;
导入net.lightbody.bmp.BrowserMobProxy;
导入net.lightbody.bmp.BrowserMobProxyServer;
导入net.lightbody.bmp.core.har.har;
导入net.lightbody.bmp.proxy.CaptureType;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.phantomjs.PhantomJSDriver;
导入org.openqa.selenium.phantomjs.PhantomJSDriverService;
导入org.openqa.selenium.remote.CapabilityType;
导入org.openqa.selenium.remote.DesiredCapabilities;
公共类MakeMyHAR{
公共静态void main(字符串[]args)引发IOException、InterruptedException{
//BrowserMobProxy
BrowserMobProxy服务器=新建BrowserMobProxyServer();
服务器启动(0);
setHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
server.enableHarCaptureTypes(CaptureType.REQUEST\u内容、CaptureType.RESPONSE\u内容);
server.newHar(“谷歌”);
//幻影
ArrayList cliArgsCap=新的ArrayList();
cliArgsCap.add(“--proxy=localhost:+server.getPort());
cliArgsCap.add(“--ignoressl errors=yes”);
//期望的能力
DesiredCapabilities=新的DesiredCapabilities();
Capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
setCapability(CapabilityType.SUPPORTS_JAVASCRIPT,true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);
setCapability(PhantomJSDriverService.PHANTOMJS_可执行文件_路径_属性,“C:\\PHANTOMJS.exe”);
//网络驱动程序
WebDriver=新的PhantomJSDriver(功能);
驱动程序。获取(“https://www.google.co.in");
//哈尔
Har=server.getHar();
FileOutputStream fos=新的FileOutputStream(“C:\\HAR Information.HAR”);
har.writeTo(fos);
server.stop();
driver.close();
}
}
虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-@ShawnMehan完成了。为什么是必要的,我想我会把整件事都放在这里。只有一个stackoverflow页面具有相同的内容。您可以使用Autoit在此处提供脚本吗?