【发布时间】:2012-01-04 10:27:18
【问题描述】:
无法找到/打开 Firefox 二进制文件 - webdriver/robot 框架
我的测试在 java 和 Fitnesse 中运行良好。当通过带有 Internet Explorer 和 Chrome 的机器人框架执行它们时,它们也运行良好。但是,当我通过 Firefox 执行它们时,使用“new FirefoxDriver()”,我收到以下错误:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more
在 FirefoxBinary 和 FirefoxDriver 类中,这些行对应于以下代码:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
}
我尝试在我的类路径、pythonpath(由机器人框架使用)和路径中设置 Firefox 二进制文件的路径。我还编写了以下代码行来尝试强制找到二进制文件:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
我尝试在两台计算机上执行测试,我的工作计算机和家用计算机。此外,我尝试使用使用 firefox.exe –p 创建的 firefox 配置文件,并在 java 代码中创建一个。我已经尝试过 Firefox 6-8。不幸的是,这些都没有奏效。
我也在使用/曾经使用过: Java 1.6 硒 2.9.0/2.13.0 视窗 7
我不确定这是否相关,但作为一种解决方法,我一直试图让 Firefox 通过远程浏览器运行。我一直在尝试以下代码:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);
但是,当我运行上述命令时,我收到以下错误消息:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
有人知道如何解决我的问题吗?
任何帮助将不胜感激,我对这个问题感到非常困惑。在 Internet Explorer 已经运行的情况下尝试让 Firefox 运行两天......感觉好像世界即将结束。
谢谢, 詹姆斯
编辑:1
我可以使用 selenium-server 来运行 Firefox。
【问题讨论】:
-
James,仅供参考,RemoteWebDriver 的 URL 在上面的帖子中显示不正确。应该更像“localhost:4444/wd/hub”?有趣的是,我在使用 Web Driver 时遇到了相反的问题,通过 RemoteWebDriver 启动 Firefox 时遇到问题,但 Firefox 通过本机 FirefoxDriver 运行良好。 IE 在远程上运行良好。