2011-11-23 46 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/