selenium - 如何在远程webdriver/grid配置中在节点端设置firefox配置文件

标签 selenium selenium-webdriver remotewebdriver selenium-grid2

始终建议在 DesiredCapabilities 中设置 firefox 配置文件,并将其通过集线器运行的线路。像下面

DesiredCapabilities caps = DesiredCapabilities.firefox();

    FirefoxProfile profile=new FirefoxProfile(new File("Local Path to firefox profile folder"));
    caps.setCapability(FirefoxDriver.PROFILE, profile);

URL url = new URL("http://localhost:4444/wd/hub");      
WebDriver driver= new RemoteWebDriver(url,caps );

但是通过 http 将巨大的 87-90 mb 配置文件信息发送到集线器,对于每个 selenium 测试用例都会减慢测试用例的执行速度。

我试过用 "Dwebdriver.firefox.profile=E:\\Firefox_Profile_Location":"", 配置网格节点json 节点配置文件中的属性,如下所示。
{
"configuration":
{
.//Other Settings
.//Other Settings
.//Other Settings
"Dwebdriver.firefox.profile=E:\\Firefox_Profile_Location":"",
"maxSession":7,
"registerCycle":5000,
"register":true
},
"capabilities":
[

{"browserName":"firefox",
"seleniumProtocol":"WebDriver",
"maxInstances":5,
"platform":"VISTA"
}
]
}

但是使用上述配置运行会引发以下错误。

WebDriverException: Firefox profile 'E:\Firefox_Profile_Location' named in system property 'webdriver.firefox.profile' not found



高级感谢您提供有关如何从节点端配置 firefox 配置文件的任何帮助。

最佳答案

您需要在 capabilities 中提供配置文件对象作为 base64 编码的 zip:

var fs = require('fs');
capabilities: [
  {
    browserName: 'firefox',
    seleniumProtocol: 'WebDriver',
    maxInstances: 5,
    platform: 'VISTA',
    firefox_profile: new Buffer(fs.readFileSync("./profile.zip")).toString('base64')
  }
]

此外,Firefox 会为给定的配置文件创建丢失的文件。因此,您应该根据需要在配置文件中保留必要的文件:

Preferences:  user.js
Passwords:    key3.db
              logins.json
Cookies:      cookies.sqlite
Certificate:  cert8.sqlite
Extensions:   extensions/

关于selenium - 如何在远程webdriver/grid配置中在节点端设置firefox配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39398117/

相关文章:

python - 在全屏模式下使用 selenium 截取屏幕截图

testing - Selenium 问题

java - 有没有办法在 Java 驱动程序中使用 PhantomJS 的 onResourceRequested 回调?

java - 无法调用使其静态或添加无参数错误消息不理解逻辑

java - 继承远程 webdriver 语法

python - 如何让 Python 中的 Selenium WebDriver 休眠几毫秒

javascript - Selenium Webdriver 处理弹出窗口

ruby - 远程 Webdriver 功能 - 移动用户代理

python - 使用 Python 和 WebDriver 断言/验证ElementPresent?

java - Eclipse 中的控制台输出颜色