Firefox 特定命令
FirefoxDriver 公开了一些特定命令,例如设置上下文以运行“特权”javascript 代码或用于处理插件。这些现在在 Nightwatch 中直接可用,位于 firefox
命名空间中。
浏览器.firefox
更多信息
自定义 Firefox 配置文件
每个 Firefox WebDriver 实例都将使用匿名配置文件创建,确保浏览器历史记录不共享会话数据(cookie、历史记录、缓存、离线存储等)。
用于每个 WebDriver 会话的配置文件可以使用来自 Selenium 的 Options 类进行配置。Nightwatch 2 完全支持使用 selenium-webdriver
库创建的选项对象。
不会修改现有的 Firefox 配置文件;相反,WebDriver 会创建一份副本供其修改。WebDriver 正确运行需要某些浏览器首选项,这些首选项将始终被覆盖。
安装 Firefox 扩展
假设您需要安装名为 Firebug 的扩展。在您的 nightwatch.conf.js
中,您可以使用 Options 类来配置 WebDriver 会话,如下所示
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options() .addExtensions('../../../path/to/firebug.xpi') .setPreference('extensions.firebug.showChromeErrors', true);
module.exports = { src_folders: ['tests'], test_settings: { default: { browserName: 'firefox', desiredCapabilities: options } } };
或者作为一个函数
module.exports = { src_folders: ['tests'], test_settings: { default: { browserName: 'firefox', desiredCapabilities() { const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options() .addExtensions('../../../path/to/firebug.xpi') .setPreference('extensions.firebug.showChromeErrors', true); return options; } }
} };