使用Selenium和Firefox Portable

时间:2016-05-03 14:32:04

标签: selenium firefox selenium-grid selenium-firefoxdriver portable-applications

我正在设置中,我需要使用Firefox Portable 38.7.1进行我的Selenium测试(版本2.53.0)。一切正常,但现在我需要配置一个代理。

我在默认配置文件中配置了它(它保存在${FF_PORTABLE_PATH}/Data/profile/prefs.js

user_pref("network.proxy.http", "proxyHost");
user_pref("network.proxy.http_port", proxyPort);
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.ssl", "proxyHost");
user_pref("network.proxy.ssl_port", 51854);
user_pref("network.proxy.type", 1);
...

手动启动浏览器时,此功能正常。但是,当Selenium触发时,会创建并使用匿名配置文件,但不会设置我的代理设置。

我尝试在启动节点时指定配置文件。

起初我尝试了using -Dwebdriver.firefox.profile

java -jar selenium-server-standalone-2.53.0.jar -role node -Dwebdriver.firefox.profile=default

然后我尝试将默认配置文件用作模板using -firefoxProfileTemplate

java -jar selenium-server-standalone-2.53.0.jar -role node -firefoxProfileTemplate "${FF_PORTABLE_PATH}/Data" -nodeConfig ...

我还创建了一个新的配置文件(使用ProfilistPortable插件)并在节点启动时指定了它(带有webdriver.firefox.profile - 参数)。

在所有情况下,Selenium节点都使用" clean"打开Firefox便携版。没有我的代理设置的匿名个人资料。

任何人都可以帮我解决如何使用Firefox Portable进行此设置吗?我真的不需要单独的个人资料。只要我可以强制Selenium使用配置了代理的配置文件,我就可以了。

这是我的nodeConfig:

{
    "capabilities": [
        {
            "browserName": "firefox",
            "version": "38.7.1",
            "firefox_binary": "${FF_PORTABLE_PATH}\\FirefoxPortable.exe",
            "platform": "WINDOWS",
            "maxInstances": 1,
            "seleniumProtocol": "WebDriver"
        }
    ],
    "configuration": {
        "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "maxSession": 1,
        "port": 5550,
        "host": "ip",
        "register": true,
        "registerCycle": 5000,
        "hubHost": "localhost",
        "hubPort": 4440
    }
}

我在上面的例子中使用了$ {FF_PORTABLE_PATH}。实际上,这个(完全限定的)路径在我的所有设置中都是硬编码的。

1 个答案:

答案 0 :(得分:0)

我有同样的问题。深入研究硒代码,我找到了解决方案。

FirefoxBinary binary = new FirefoxBinary(new File(portablePath.trim()));
File profile_dir = new File(portablePath.trim().replace("FirefoxPortable.exe", "/Data/profile"));
fp = new FirefoxProfile(profile_dir);
dc.setCapability(FirefoxDriver.PROFILE, fp);
driver  = new FirefoxDriver( binary , fp, dc);
相关问题