I’m trying to get Selenium tests to work when they are executed by Hudson, but I have not been successful so far. Hudson is running on Ubuntu, and Selenium is unable to open display.
Command I use for launching the build is:
mvn clean selenium:xvfb install
error log:
[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>
I’ve also tried to get it working by adding execution for xvfb, but also it failed.
You need to run the browsers launched by Selenium in headless mode so that they don’t try to open a display. Here’s a good blog post with more details.