我正在尝试让Hlenson执行Selenium测试,但到目前为止我还没有成功。 Hudson在Ubuntu上运行,Selenium无法打开显示。
我用于启动构建的命令是:
mvn clean selenium:xvfb install
错误日志:
[INFO] [selenium:xvfb {execution: default-cli}]
[INFO] Starting Xvfb...
[INFO] Using display: :20
[INFO] Using Xauthority file: /tmp/Xvfb4467650583214148352.Xauthority
Deleting: /tmp/Xvfb4467650583214148352.Xauthority
xauth: creating new authority file /tmp/Xvfb4467650583214148352.Xauthority
Created dir: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/selenium
Launching Xvfb
Waiting for Xvfb...
[INFO] Redirecting output to: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/selenium/xvfb.log
Xvfb started
...
[INFO] [selenium:start-server {execution: start}]
Launching Selenium Server
Waiting for Selenium Server...
[INFO] Including display properties from: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/selenium/display.properties
[INFO] Redirecting output to: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/selenium/server.log
[INFO] User extensions: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/selenium/user-extensions.js
Selenium Server started
[INFO] [selenium:selenese {execution: run-selenium}]
[INFO] Results will go to: /var/lib/hudson/jobs/Selenium/workspace/selenium/target/results-firefox-suite.html
...
<~30 seconds pause>
...
Error: no display specified
...
的pom.xml:
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<logOutput>true</logOutput>
<background>true</background>
<port>5123</port>
</configuration>
</execution>
<execution>
<id>run-selenium</id>
<phase>integration-test</phase>
<goals>
<goal>selenese</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
<configuration>
<browser>*firefox</browser>
<suite>src/test/selenium/suite.html</suite>
<startURL>http://localhost:${env.port}</startURL>
</configuration>
我也尝试通过添加xvfb的执行来使其工作,但也失败了。
答案 0 :(得分:4)
您需要在无头模式下运行Selenium启动的浏览器,这样他们就不会尝试打开显示器。这是一个很好的blog post,其中包含更多细节。
答案 1 :(得分:1)
如果您无法选择无头测试,则可以在没有无头模式的情况下运行测试,您只需指定一个显示器即可。
要进行快速测试,请尝试使用终端中的xhost +
禁用xhost访问控制。
在终端输入env
并取下分配给DISPLAY变量的号码,找出您的显示设置。例如DISPLAY:1.0
。
接下来,您需要在Hudson / Jenkins中设置显示变量。导航到Jenkins登录页面,然后单击 Manage Jenkins&gt; Manage Nodes&gt; Master&gt; Configure 。选中环境变量复选框,然后在名称框中设置DISPLAY,并将值设置为我们的示例:1.0
。
答案 2 :(得分:0)
嗯,也可能是你可以将Hlenson服务器(实际上是Selenium RC)设置为Hudson机器(虽然这需要X),并使用它来运行测试。似乎Maven selenium插件也接受端口值和所有,所以它应该使它连接到RC并启动你需要的浏览器。
但无头模式可能更适合您的需求。
答案 3 :(得分:-1)
无需在无头模式下运行。只要正确,Selenium可以使用当前的DISPLAY会话变量在本地或远程运行。请参阅http://thinkinginsoftware.blogspot.com/2015/02/setting-display-variable-to-avoid-no.html中的帖子,但简而言之:
# Check current DISPLAY value
$ echo $DISPLAY
:0
# If xclock fails as below the variable is incorrect
$ xclock
No protocol specified
No protocol specified
Error: Can't open display: :0
# Find the correct value for the current user session
$ xauth list|grep `uname -n`
uselenium/unix:10 MIT-MAGIC-COOKIE-1 48531d0fefcd0a9bde13c4b2f5790a72
# Export with correct value
$ export DISPLAY=:10
# Now xclock runs
$ xclock