2012-09-24 58 views
10

背景:
我使用硒服務器-2.25.0與J-4號機組一起通過了一把運行我的GWT應用程序的UI測試場景。在我的IDE(Netbeans 7.2)中,我可以右鍵單擊我的項目,選擇「測試」,然後看到Firefox窗口隨着Selenium測試按預期運行而全部彈出(因爲它們應該)。從命令行,我也可以運行mvn integration-test並查看相同的內容。如何正確配置硒Maven插件用的Xvfb工作運行無頭

目標:
我試圖讓這些測試在顯示的Xvfb運行無頭,但我似乎遇到了麻煩這與Maven的工作。我可以事先手動運行export display=:2(:2作爲我的Xvfb顯示器),然後測試成功地在隱形顯示器中運行。

問題:
似乎沒有任何改變在所有當我包括here在我的pom.xml全<plugin>進入和運行mvn integration-test。我仍然看到Windows彈出全部,並且在Xvfb顯示器中運行的測試不是而是。如果我拿出來並再次運行,結果相同。但是,當我將階段從pre-integration-test更改爲qwertyasdf然而,Maven 確實抱怨無效的生命週期階段 - 所以我知道它並不完全忽略它,並且正在編輯適當的pom.xml。

謝謝!

回答

8

事實證明,「啓動服務器」和「停止服務器」的目標是啓動/停止SeleniumRC服務器。這是不是我想要的,因爲我所有的測試都使用WebDriver API。

顯然,pom DOES中的'xvfb'目標在指定的生命週期階段開始一個Xvfb會話 - 我想我以前沒有看到它。在它的配置中,您可以指定在哪裏編寫一個道具文件,詳細說明Xvfb運行在哪個顯示器上。在Java代碼中,可以讀取該文件,並將值傳遞給創建WebDriver時使用的FirefoxBinary。

相關的pom.xml位如下所示:

<properties> 
    <displayProps>target/selenium/display.properties</displayProps> 
</properties> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <systemPropertyVariables> 
        <display.props>${displayProps}</display.props> 
       </systemPropertyVariables> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>selenium-maven-plugin</artifactId> 
      <version>2.3</version> 
      <executions> 
       <execution> 
        <id>xvfb</id> 
        <phase>test-compile</phase> 
        <goals> 
         <goal>xvfb</goal> 
        </goals> 
        <configuration> 
         <displayPropertiesFile>${displayProps}</displayPropertiesFile> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

這第一自由顯示器上啓動的Xvfb(:20或以上)並寫入值到道具文件,我讀後來在使用我的Java代碼。

String xvfbPropsFile = System.getProperty("display.props"); 

FirefoxBinary ffox = new FirefoxBinary(); 
ffox.setEnvironmentProperty("DISPLAY", /*read value from xvfbPropsFile*/); 
WebDriver driver = new FirefoxDriver(ffox); 

現在驅動程序將控制Firefox實例在適當的顯示器中旋轉。瞧!

+0

我不能運行這個,我還得到一個「無顯示」錯誤:( –

+0

優秀,得益於它救了我的一天。 –

+1

請出示文件的內容'目標/硒/ display.properties' –

相關問題