php - Selenium2 火狐 : use the default profile

标签 php firefox webdriver selenium-webdriver

默认情况下,Selenium2 以全新的配置文件启动 firefox。我喜欢默认设置,但出于一些充分的理由(访问我的书签、保存的密码、使用我的附加组件等)我想从我的默认配置文件开始。

supposed to be一个控制它的属性,但我认为文档与源代码不同步,因为据我所知,webdriver.firefox.bin 是唯一有效的。例如。开始 Selenium :

java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin=not-there

有效(即它提示)。但这没有效果:

java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.profile=default

(“default”是 profiles.ini 中的名称,但我也尝试使用“Profile0”,它是 profiles.ini 中的部分名称)。

我正在使用 PHPWebdriver (使用 JsonWireProtocol)访问:

$webdriver = new WebDriver("localhost", "4444");

$webdriver->connect("firefox");

我尝试从 PHP 端进行:

$webdriver->connect("firefox","",array('profile'=>'default') );

或:

$webdriver->connect("firefox","",array('profile'=>'Profile0') );

没有成功(firefox 启动,但没有使用我的配置文件)。

我也试过黑客创建批处理文件的方法:

#!/bin/bash
/usr/bin/firefox -P default

然后启动 Selenium: java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin="/usr/local/src/selenium/myfirefox"

Firefox 启动,但默认情况下不使用配置文件,更糟糕的是,一切都挂起:以这种方式启动时,selenium 似乎无法与 firefox 通信。

附言我看到了Selenium - Custom Firefox profile我试过这个:

java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate "not-there"

它拒绝运行!很兴奋,我想我可能会有所作为,我尝试了:

java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate /path/to/0abczyxw.default/

这什么都不做。 IE。它仍然以新的配置文件开头:-(

最佳答案

西蒙·斯图尔特 answered this on the mailing list对我来说。

总结一下他的回复:你把你的 firefox 配置文件压缩(zip,不是 tgz),对其进行 base64 编码,然后将整个文件作为 /session json request 发送。 (将 base64 字符串放入 Capabilities 对象的 firefox_profile 键中)。

在 Linux 上执行此操作的示例方法:

cd /your/profile
zip -r profile *
base64 profile.zip > profile.zip.b64

然后,如果您在连接时使用 PHPWebDriver,请执行以下操作:

$webdriver->connect("firefox", "", array("firefox_profile" => file_get_contents("/your/profile/profile.zip.b64")))

注意:它仍然不是我的真实个人资料,而是它的副本。所以书签不会被记住,缓存不会被填充等等。

关于php - Selenium2 火狐 : use the default profile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7328494/

相关文章:

html - Css :focus working on firefox only. 其他浏览器不支持

java - 找到不可见的值

java - 无法使用 webdriver 找到 javascript 框架

selenium - 通过 marionette 驱动程序在 Firefox 浏览器中设置代理

php - 如何强制 PHP 输出一个以零开头的数字?

PHP 从数据库中获取数据

html - css @-moz-keyframes 动画不适用于 firefox 18.0.1

javascript - 禁用 urlbar 过滤器 - Firefox 28

php - 当 session 在 Laravel 中过期时将用户重定向到登录页面

php - 单元测试函数 php