Exploring
Exploring

Reputation: 3429

Error: cannot open display: :0 for Selenium tests

Firstly I was getting the following error:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified

So I have used export DISPLAY=:0 to circumvent this problem. Followed to that I have found Selenium tests were running using the root user and all was fine.

However now I can see when these tests are getting executed from Jenkins the following error is coming up:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
No protocol specified
Error: cannot open display: :0

I am running this on a Redhat 6 box.

Upvotes: 1

Views: 7004

Answers (2)

sjmach
sjmach

Reputation: 434

The best approach to solve this problem is making changes to the jenkins start script.

The solution that works on Ubuntu for me correctly is as follows:

1.Open Jenkins shell script located at: /etc/init.d/jenkins.

2.Add the following lines as follows before PATH variable:

/usr/bin/X :0 vt7 -ac
export DISPLAY=:0
xhost +

Upvotes: 1

Amey
Amey

Reputation: 8548

You can download the Jenkins xvnc plugin and make that plugin start(and export) a virtual display for selenium to use. The jenkins user may not have access to the :0 display.

Upvotes: 3

Related Questions