Trying to run Selenium tests using Hudson - "Error: no display specified"
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 sta开发者_JAVA技巧rted
...
[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.
If headless testing is not an option for you it is possible to run the tests without headless mode, you just need to specify a display.
For a quick test, try disabling your xhost access controls using xhost +
in the terminal.
Find out what your display settings are by typing env
in the terminal and taking down the number assigned to your DISPLAY variable. For example DISPLAY:1.0
.
Next you need to set the display variable in Hudson/Jenkins. Navigate to the Jenkins landing page then click Manage Jenkins>Manage Nodes>Master>Configure. Check the Environment variables check box, then set DISPLAY in the name box, and the value to something like our example :1.0
.
Hmmh, it could also be that you could set up Selenium server (actually Selenium RC I think) to the Hudson machine (though this needs X), and use that in order to run your tests. It seems that Maven selenium plugin accepts also port value and all, so that should make it connect to RC and fire up the browsers you need.
But that headless mode might suit better to your needs.
There is no need to run in headless mode. Selenium can be run locally or remotely using a current DISPLAY session variable as long as it is correct. See my post in http://thinkinginsoftware.blogspot.com/2015/02/setting-display-variable-to-avoid-no.html but in short:
# 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
精彩评论