jco*_*ert 10 selenium maven headless-browser xvfb selenium-webdriver
背景:
我正在使用selenium-server-2.25.0与J-Unit 4一起为我的GWT应用程序运行一些UI测试场景.在我的IDE(Netbeans 7.2)中,我可以右键单击我的项目,选择"Test",然后看到Firefox窗口全部弹出(因为它们应该),Selenium测试按预期运行.从命令行,我也可以运行mvn integration-test并查看相同的内容.
目标:
我正在尝试让这些测试在Xvfb显示器中无头运行,但我似乎无法将其与Maven一起使用.我可以export display=:2事先手动运行(:2是我的Xvfb显示),然后测试然后DO在隐形显示中成功运行.
问题:
似乎没有任何改变都当我包括完整的<plugin>从入门这里在我的pom.xml和运行mvn integration-test.我仍然看到Windows全部弹出,测试运行不在 Xvfb显示器中.如果我把它取出并再次运行,结果相同.当我从改变相位pre-integration-test,以qwertyasdf然而,Maven的并不抱怨无效的生命周期阶段-所以我知道它不是完全无视它,我编辑相应的pom.xml.
谢谢!
事实证明,'start-server'和'stop-server'目标是用于启动/停止SeleniumRC服务器.这不是我想要的,因为我的所有测试都使用WebDriver API.
显然,pom中的'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>
Run Code Online (Sandbox Code Playgroud)
这将在第一次自由显示(:20或更高版本)时启动Xvfb,并将值写入我读取并稍后在Java代码中使用的props文件.
String xvfbPropsFile = System.getProperty("display.props");
FirefoxBinary ffox = new FirefoxBinary();
ffox.setEnvironmentProperty("DISPLAY", /*read value from xvfbPropsFile*/);
WebDriver driver = new FirefoxDriver(ffox);
Run Code Online (Sandbox Code Playgroud)
现在,驱动程序将控制在适当的显示中旋转的Firefox实例.瞧!
| 归档时间: |
|
| 查看次数: |
6276 次 |
| 最近记录: |