2010-06-16 18 views
2

我试图让Selenium测试工作,当他们由哈德森执行,但我一直没有成功。 Hudson在Ubuntu上运行,Selenium无法打开显示。试图使用Hudson运行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添加执行,但也失败了。

回答

4

您需要在无头模式下运行由Selenium启动的浏览器,以便它们不会尝试打开显示器。这是一个很好的blog post与更多的细节。

0

嗯,它也可能是你可以设置Selenium服务器(实际上是Selenium RC我认为)到Hudson机器(尽管这需要X),并使用它来运行你的测试。看来Maven selenium插件也接受端口值和全部,所以应该使它连接到RC并启动你需要的浏览器。

但是这种无头模式可能更适合您的需求。

1

如果无头测试不适合您,可以在无头模式下运行测试,您只需指定显示。

要进行快速测试,请尝试在终端中使用xhost +禁用xhost访问控制。

通过在终端中输入env并记下分配给DISPLAY变量的数字,找出您的显示设置。例如DISPLAY:1.0

接下来你需要在Hudson/Jenkins中设置显示变量。导航至Jenkins登录页面,然后单击管理詹金斯>管理节点>主站>配置。检查环境变量复选框,然后在名称框中设置DISPLAY,并将值设置为像我们的示例:1.0

-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 
相关问题