嗨,我试图在内部配置文件的环境设置中设置firefox配置文件名称。我试过了
environments: [
{ browserName: 'firefox',firefox_profile:'default' },
{firefox_profile:'default'}
],
和
environments: [
{ browserName: 'firefox',profile:'default' },
{profile:'default'}
],
和
capabilities: {
'selenium-version': '2.42.0',
firefox_profile:'default'
},
在Selenium功能中提到的但是火狐还是以匿名配置文件启动。
但是如果我使用watir,
def setup
@browser = Watir::Browser.new :firefox, :profile => 'default'
goto_ecp_console_manage_page
end
浏览器启动默认配置文件,它是'kinit-ed'(kerberos)
正如您提到的Selenium功能页面所指出的,firefox_profile
的值必须是base64编码的配置文件。具体来说,将Firefox配置文件目录压缩,对其进行Base64编码,并使用该字符串作为firefox_profile
的值。firefox-profile npm包可以简化这个过程。你会得到这样的结果:
environments: [
{ browserName: 'firefox', firefox_profile: 'UEsDBBQACAAIACynEk...'; },
...
],
我建议将配置文件字符串存储在一个单独的模块中,因为它将在250kb左右。
我使用@jason0x43建议依赖于firefox-profile Node.js模块,我创建了以下grunt任务fireforProfile4selenium
。通过在Gruntfile.js
中设置一个简单的配置,插件将使用压缩配置文件的Base64编码版本在磁盘上写入文件!
下面是grunt配置:
firefoxProfile4selenium: {
options: {
proxy: {
host: '...',
port: ...
},
bypass: [ 'localhost', '127.0.0.1', '...' ]
},
default: {
files: [{
dest: 'firefoxProfile.b64.txt'
}]
}
}
插件:
/*global require, module*/
var fs = require('fs'),
FirefoxProfile = require('firefox-profile'),
taskName = 'firefoxProfile4selenium';
module.exports = function (grunt) {
'use strict';
grunt.registerMultiTask(taskName, 'Prepares a Firefox profile for Selenium', function () {
var done = this.async(),
firefoxProfile = new FirefoxProfile(),
options = this.options(),
host = this.options().proxy.host,
port = this.options().proxy.host,
bypass = this.options().bypass,
dest = this.files[0].dest;
// Set the configuration type for considering the custom settings
firefoxProfile.setPreference('network.proxy.type', 2);
// Set the proxy host
firefoxProfile.setPreference('network.proxy.ftp', host);
firefoxProfile.setPreference('network.proxy.http', host);
firefoxProfile.setPreference('network.proxy.socks', host);
firefoxProfile.setPreference('network.proxy.ssl', host);
// Set the proxy port
firefoxProfile.setPreference('network.proxy.ftp_port', port);
firefoxProfile.setPreference('network.proxy.http_port', port);
firefoxProfile.setPreference('network.proxy.socks_port', port);
firefoxProfile.setPreference('network.proxy.ssl_port', port);
// Set the list of hosts that should bypass the proxy
firefoxProfile.setPreference('network.proxy.no_proxies_on', bypass.join(','));
firefoxProfile.encoded(function (zippedProfile) {
fs.writeFile(dest, zippedProfile, function (error) {
done(error); // FYI, done(null) reports a success, otherwise it's a failure
});
});
});
};