firefox - 通过 webdriver 控制 Firefox 的最佳方法

标签 firefox selenium selenium-webdriver firefox-addon firefox-addon-sdk

我需要通过 webdriver 控制 Firefox 浏览器。请注意,我并不是试图控制页面元素(即查找元素、单击、获取文本等);相反,我需要访问 Firefox 的分析器并强制 gc(即我需要 Firefox 的 Chrome Authority 和 sdk)。对于上下文,我正在创建一个微型基准测试框架,而不是运行普通的网络驱动程序测试。

显然原始网络驱动程序不起作用,所以我一直在尝试做的是

1)创建一个 Firefox 扩展/附加组件来满足我的需要:即

var customActions = function() {
  console.log('calling customActions.')
  // I need to access chrome authority:
  var {Cc,Ci,Cu} = require("chrome");
  Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
  Cu.forceGC();
  var file = require('sdk/io/file');
  // And do some writes:
  var textWriter = file.open('a/local/path.txt', 'w');
  textWriter.write('sample data');
  textWriter.close();
  console.log('called customActions.')
};

2) 将我的 customActions 函数公开到页面:

var mod = require("sdk/page-mod");
var data = require("sdk/self").data;
mod.PageMod({
  include: ['*'],
  contentScriptFile: data.url("myscript.js"),
  onAttach: function(worker) {
    worker.port.on('callCustomActions', function() {
      customActions();
    });
  }
});

myscript.js中:

exportFunction(function() {
  self.port.emit('callCustomActions');
}, unsafeWindow, {defineAs: "callCustomActions"});

3) 在我的 webdriver 测试期间加载 xpi,并调用全局函数 callCustomActions

<小时/>

关于这个过程的两个问题。

1)整个过程非常迂回。通过 webdriver 与 Firefox 扩展对话是否有更好的做法?

2) 我当前的解决方案效果不佳。如果我直接通过 cfx run 运行我的扩展(没有 webdriver),它会按预期工作。但是,当通过 webdriver 运行时,sdk 和 chrome 权限都不会执行任何操作。 顺便说一句,我知道我的函数正在被调用,因为日志行“calling customActions”。和“称为自定义操作”。两者都打印。

也许有一些 Firefox 首选项我需要设置但尚未设置?

最佳答案

您可能根本不需要该附加组件。 Mozilla 使用 Marionette除其他外,用于 Firefox OS 的测试自动化:

Marionette is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox or Firefox OS. It can control both the chrome (i.e. menus and functions) or the content (the webpage loaded inside the browsing context), giving a high level of control and ability to replicate user actions. In addition to performing actions on the browser, Marionette can also read the properties and attributes of the DOM.

If this sounds similar to Selenium/WebDriver then you're correct! Marionette shares much of the same ethos and API as Selenium/WebDriver, with additional commands to interact with Gecko's chrome interface. Its goal is to replicate what Selenium does for web content: to enable the tester to have the ability to send commands to remotely control a user agent.

关于firefox - 通过 webdriver 控制 Firefox 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29288922/

相关文章:

selenium - 您如何为基于 Polymer (JS) 的应用程序编写端到端测试(大约 2015 年 5 月)?

Java - Selenium Webdriver : Entering text into text field, 并自动从文本字段中删除

python - Selenium webdriver python,无法按值找到?

css - 在 Firefox 中使用小数计算宽度,但在 Webkit 中不带小数

python - Selenium 导致Windows错误

javascript - Oracle 的 deployjava.js 在 Firefox/Chrome 中不再起作用。我还可以做些什么?

java - 我怎样才能识别这个元素

java - 使用 Java 中断通过 Selenium 的文件上传?

css - 图标字体在 Firefox 中不可见

javascript - 在 Firefox 中查看带有表单的 PDF