2011-11-23 48 views
1

无法找到/打开Firefox的二进制 - 的webdriver /机器人框架无法找到/打开Firefox的二进制 - 的webdriver /机器人框架

我的测试运行在Java和FitNesse的罚款。使用Internet Explorer和Chrome通过机器人框架执行它们时,它们也运行良好。然而,当我通过火狐执行它们,使用“新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); 
    } 

我已经尝试在我的classpath,pythonpath(由robotframework使用)和路径中设置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 Windows 7的

我不能确定这是否是相关的,但作为一个解决办法,我一直试图让火狐通过远程浏览器运行。我一直在尝试下面的代码:

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) 

有没有人对如何解决或者我的问题任何想法?

任何帮助将不胜感激,我感到非常卡住在这个问题atm。当Internet Explorer已经做了两天的尝试让Firefox工作......感觉好像这个世界即将结束。

谢谢, 詹姆斯

编辑:1

这是我能够通过使用硒服务器上运行的Firefox。

+1

詹姆斯,仅供参考,网址为RemoteWebDriver出现在上面的帖子不正确。应该更像“http:// localhost:4444/wd/hub”?有趣的是,我遇到与Web Driver相反的问题,通过RemoteWebDriver启动Firefox时遇到问题,但Firefox通过本机FirefoxDriver运行正常。 IE在远程工作正常。 – David

回答

0

James,FYI,RemoteWebDriver的URL在上面的帖子中显示不正确。应该更像“localhost:4444/wd/hub”;?有趣的是,我遇到与Web Driver相反的问题,通过RemoteWebDriver启动Firefox时遇到问题,但Firefox通过本机FirefoxDriver运行正常。 IE在远程工作正常。 - 大卫12年4月4日在4:51

谢谢大卫!

0

我不明白你为什么没有在远程网格config.json文件中配置你的Firefox二进制文件?我就是这么做的。然后,您的DesiredCapabilities对象不需要定义它。有一个提示可以找到here

如果它工作,在JSON文件中的行可能看起来像:

"binary": "C:/Program Files/Mozilla Firefox/firefox.exe", 

我想它不会让你动态地从你的代码中设置二进制位置,但也许你可以试试那方法来证明它是否应该起作用或作为故障排除步骤。

0
FirefoxProfile profile = new FirefoxProfile(); 
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe")); 
driver = new FirefoxDriver(binary, profile); 

试试这个

0

这种问题,因为硒的网络驱动器的获得,不知道火狐的.exe文件。请检查C:\ Program Files(x86)\ Mozilla Firefox是否已在该位置执行exe文件,并且不要忘记设置具有Java jdk路径的环境变量。

来源: - 读[解决中找不到PATH硒Firefox的二进制] [1] http://www.tech4crack.com/solved-cannot-find-firefox-binary-in-path/