2012-11-22 31 views
29

我正在運行一些Selenium測試。當我直接從Eclipse啓動它們時,一切正常。但是,當我基於Maven開始他們那裏出現以下異常:未能通過Maven中的Selenium連接到二進制FirefoxBinary

org.openqa.selenium.WebDriverException(Failed to connect to binary FirefoxBinary(C:\winapp\Firefox\firefox.exe) on port 7055; process output follows: 
null 
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45' 
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_35' 
Driver info: driver.version: FirefoxDriver) 

我使用的是Firefox ESR 10.0.10。我也用Selenium 2.25.0來試用它。

這是我最新的pom.xml的版本:

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.26.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-server</artifactId> 
     <version>2.26.0</version> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.servlet</groupId> 
       <artifactId>servlet-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>com.thoughtworks.xstream</groupId> 
     <artifactId>xstream</artifactId> 
     <version>1.4.1</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.jdom</groupId> 
     <artifactId>jdom2</artifactId> 
     <version>2.0.3</version> 
    </dependency> 
</dependencies> 

如果我能有更多的信息來支持你,請讓我知道。

編輯:更新後的pom.xml

EDIT2:什麼最想知道我的,就是我可以從Eclipse運行測試,而不答的問題。他們只是occure,如果我叫「MVN安裝」例如

+0

硒 - 服務器神器具有相關的servlet的API-2.5神器,你應該排除,如果你的項目將在Web應用程序容器內運行 - 硒hq.org。 –

+0

另外爲什麼你需要硒-α依賴? –

+0

我剛試過一些東西。現在我已經添加了排除並刪除了selenium-api依賴項,但問題依然如此 – kirschmichel

回答

5

我想出了問題所在。

我加載了一些擴展來添加到我用來實例化FireFoxDriver的FirefoxProfile。這些插件位於Java/main/resources下。在Eclipse中一切正常,但我無法通過Maven訪問這些插件。將這些文件複製到一個臨時文件夾並從這裏加載後,甚至可以從Maven中運行。

感謝您的幫助

3

嘗試添加以下內容到POM

更新:

<dependency> 
    <groupId>org.seleniumhq.webdriver</groupId> 
    <artifactId>selenium-firefox-driver</artifactId> 
    <version>2.XX.X</version> 
</dependency> 

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-server</artifactId> 
    <version>2.XX.X</version> 
</dependency> 
+0

我發現的最新版本是0.9.7376。添加到我的POM後,仍然存在相同的問題 – kirschmichel

+0

對不起我忘了更新版本。 –

+1

即使使用此版本,錯誤仍然會發生 – kirschmichel

26

當我遇到這個錯誤通常是兩件事情之一。

硒版本不支持的瀏覽器版本 仔細檢查硒/瀏覽器版本是相同的在Eclipse的Maven VS跑時。 仔細檢查Eclipse和Maven配置爲使用相同的Selenium版本。 當我的瀏覽器自動更新時,這發生在我身上,所以我在瀏覽器中關閉了它。

Selenium測試正在無頭模式下運行 如果您在與Eclipse相同的機器上手動執行mvn,則不太可能。 在我的Jenkins服務器上通過Maven運行Selenium時發生這種情況。詹金斯服務器正在無頭模式下運行。花了我一分鐘來弄清楚無頭的東西,我想在Linux中設置一個DISPLAY env變量或其他東西。

+0

感謝您的回答馬修,但我確實做了第一步很多次,第二次不適合我,因爲我運行測試在同一臺物理機器上 – kirschmichel

+2

設置DISPLAY env變量後,問題是否解決?我想我正遇到同樣的問題。 – jlars62

+0

DISPLAY修復它。另外,如果它與連接的監視器或HtmlUnit驅動程序一起工作,它可能是一個無頭的問題。 –

0

如果你在試圖解決這一問題,更新Firefox和硒到最新版本,並且您仍然面臨的問題,您可以使用「重新啓動來更新已經更新的Firefox 」。

關閉Firefox並確保Firefox可執行文件不再運行。然後嘗試你的測試。它現在應該工作。

我猜這是關係時,當您使用「重新啓動來更新」

1

我們有一個類似的問題,經過Linux更新出現正是火狐二進制更新。 我們測試了很多硒版本(2.42.2和2.43.1)和firefox(27.0.1到32.0.2)的組合,但問題始終存在。

我們在OpenMandriva下,該項目在Eclipse和Maven下。

我們爲我們找到了一個解決方案,那就是更換以下Maven依賴

<dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.43.1</version> 
    </dependency> 

通過以下所有的國家:

<dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-firefox-driver</artifactId> 
     <version>2.43.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-support</artifactId> 
     <version>2.43.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-api</artifactId> 
     <version>2.43.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
     <version>3.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.3.5</version> 
    </dependency> 

我不知道這個解決方案只是隱藏真正的問題?

-2

當Firefox緩存文件夾所在的磁盤上沒有剩餘空間時,也會發生同樣的問題。只需釋放空間並啓動您的腳本!

0

我只好用Firefox 36這一問題,還人們面臨着同樣的在35和44

對於總之,升級您的Firefox 37或將其降級到任何低於33

-1

找不到firefoxbinary路徑。 請在使用firefox驅動程序之前設置firefox路徑。在我的構建路徑ios-server-0.6.5-jar-with-dependencies.jar,並使用組合 -

System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 
0

爭奪這一段時間,並試圖大部分(如果不是全部)在這裏列出的選項中,我終於通過刪除未使用的JAR擺脫這種錯誤後的FF34和硒罐2.48.2

只是想發佈此作爲另一種選擇,以防任何人遇到這個虛弱的問題。

0
my recommendation is 

    ===> switch to firefox version 50.0 [latest One] , 

    ===> download the gecko driver from [.](https://github.com/mozilla/geckodriver/releases) and 

    ===> Selenium version 3.0.1 
    <dependency> 
       <groupId>org.seleniumhq.selenium</groupId> 
       <artifactId>selenium-java</artifactId> 
       <version>3.0.1</version> 
    </dependency> 

    ==> On your Code 
private WebDriver driver; 
System.setProperty("webdriver.gecko.driver", "PATH to GECKO DRIVER"); 
     driver = new FirefoxDriver(); 

    and yes you see the below output in your console : 


    Dec 17, 2016 6:40:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end 
    14819XXXXXXX5 mozprofile::profile INFO Using profile path C:\Users\User\AppData\Local\XXXXX\rust_XXXprofile.OXXXXXXXXXXX7S 
    148XXXXXXXXX0 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe 
    148XXXXXXXXX1 geckodriver::marionette INFO Connecting to Marionette on localhost:XXXXXXX 
    148198XXXX077 Marionette INFO Listening on port 53532 
    Dec 17, 2016 6:40:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
    INFO: Detected dialect: W3C 
    [Child 4104] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line XXXX 
    Dec 17, 2016 6:41:13 PM org.openqa.selenium.os.UnixProcess destroy 
相關問題