Selenium2 firefox:使用默认配置文件 [英] Selenium2 firefox: use the default profile
问题描述
应该是属性控制这个,但我认为文档与源代码不同步,因为据我所知, webdriver.firefox.bin
是唯一可用的。例如。启动硒:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin = not - 这里有
的作品(即抱怨)。但是这不起作用:
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默认
然后启动Selenium:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin =/ usr / local / src / selenium / myfirefox
火狐启动,但没有使用默认配置文件,更糟糕的是,一切都挂起:硒启动这种方式似乎无法与Firefox进行通信。
PS我看到了 Selenium - 自定义Firefox配置文件我试过了:
java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplatenot-there
它拒绝运行!兴奋,想着我可能会做些什么,我试过:
java -jar selenium-server-standalone-2.5.0。 jar -firefoxProfileTemplate /path/to/0abczyxw.default/
这没有任何作用。即它仍然以一个新的配置文件开始: - (
)Simon Stewart 在邮件列表回答了这个问题。
总结一下回复:你把你的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=> fi le_get_contents(/ your / profile / profile.zip.b64)))
将不会是我真正的个人资料,而是它的副本。所以书签不会被记住,缓存也不会被填充等。
Selenium2, by default, starts firefox with a fresh profile. I like that for a default, but for some good reasons (access to my bookmarks, saved passwords, use my add-ons, etc.) I want to start with my default profile.
There is supposed to be a property controlling this but I think the docs are out of sync with the source, because as far as I can tell webdriver.firefox.bin
is the only one that works. E.g. starting selenium with:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin=not-there
works (i.e. it complains). But this has no effect:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.profile=default
("default" is the name in profiles.ini, but I've also tried with "Profile0" which is the name of the section in profiles.ini).
I'm using PHPWebdriver (which uses JsonWireProtocol) to access:
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
I tried doing it from the PHP side:
$webdriver->connect("firefox","",array('profile'=>'default') );
or:
$webdriver->connect("firefox","",array('profile'=>'Profile0') );
with no success (firefox starts, but not using my profile).
I also tried the hacker's approach of creating a batch file:
#!/bin/bash
/usr/bin/firefox -P default
And then starting Selenium with: java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin="/usr/local/src/selenium/myfirefox"
Firefox starts, but not using by default profile and, worse, everything hangs: selenium does not seem able to communicate with firefox when started this way.
P.S. I saw Selenium - Custom Firefox profile I tried this:
java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate "not-there"
And it refuses to run! Excited, thinking I might be on to something, I tried:
java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate /path/to/0abczyxw.default/
This does nothing. I.e. it still starts with a new profile :-(
Simon Stewart answered this on the mailing list for me.
To summarize his reply: you take your firefox profile, zip it up (zip, not tgz), base64-encode it, then send the whole thing as a /session json request (put the base64 string in the firefox_profile key of the Capabilities object).
An example way to do this on Linux:
cd /your/profile
zip -r profile *
base64 profile.zip > profile.zip.b64
And then if you're using PHPWebDriver when connecting do:
$webdriver->connect("firefox", "", array("firefox_profile" => file_get_contents("/your/profile/profile.zip.b64")))
NOTE: It still won't be my real profile, rather a copy of it. So bookmarks won't be remembered, the cache won't be filled, etc.
这篇关于Selenium2 firefox:使用默认配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!