4

我正在使用 HAR Export XPI 来获取使用 selenium 遍历的页面的网络流量。我正在将 XPI 添加到 ffv46(因为无法将 XPI 添加到最新的 ff 浏览器)。我使用了下面提到的配置文件设置 -

profile.setPreference("app.update.enabled", false);
profile.setPreference("extensions.netmonitor.har.enableAutomation", true);
profile.setPreference("extensions.netmonitor.har.contentAPIToken", "true");
profile.setPreference("extensions.netmonitor.har.autoConnect", true);
profile.setPreference("devtools.netmonitor.enabled", true);
profile.setPreference("devtools.netmonitor.har.pageLoadedTimeout", "50000");
profile.setPreference("devtools.netmonitor.har.defaultLogDir", "FOLDER_ON_SYSTEM");
profile.setPreference("devtools.netmonitor.har.enableAutoExportToFile", false);

我正在注入以下 javascript 来获取 HAR 文件。

function triggerExport() {

  var options = {
    token: "true",
    getData: true,
    fileName: "Export_%y%m%d_%H%M%S"
  };
  HAR.triggerExport(options).then(result => {
      console.log(result);
  });
};

if (typeof HAR === 'undefined') 
{
    console.log("Calling Undefined");
    addEventListener('har-api-ready', event => {
        console.log("har api ready");
        console.log(event);
        triggerExport();
    }, false);
} 
else 
{
    console.log("Calling defined");
    triggerExport();
}

但是没有生成 HAR 文件。有什么我想念的吗。此外,如果我尝试在 FF 控制台中键入 HAR,我会收到未定义的消息,这会导致函数失败。

是否还有其他我缺少的设置。

提前致谢 !!!!

4

1 回答 1

4

由于我没有运气使用其他建议的解决方案来解决这个问题(AFAIKbrowsermob proxy和 XPI 有一段时间没有更新),我创建了一个小的 npm 模块来将硒测试捕获为 HAR 文件 -链接

我使用 Chrome 开发工具协议来捕获 Fetch 事件,你可以在这里查看我的逻辑

在这里添加我关于如何将 selenium 测试转换为 API 测试的完整文章。

于 2019-12-10T10:18:42.283 回答