Cannot connect to X server error #402

naveediitb opened this Issue Oct 18, 2012 · 8 comments


None yet

6 participants


Running on Ubuntu
Checked both on EC2 and Linode

webkit_server: cannot connect to X server
/usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit/connection.rb:103:in attempt_connect' /usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit/connection.rb:96:inconnect'
/usr/lib/ruby/1.8/timeout.rb:62:in timeout' /usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit/connection.rb:94:inconnect'
/usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit/connection.rb:17:in initialize' /usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit.rb:26:innew'
/usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/driver/webkit.rb:26:in initialize' /usr/lib/ruby/gems/1.8/gems/capybara-webkit-0.12.1/lib/capybara/webkit.rb:5:innew'
/usr/lib/ruby/gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:in call' /usr/lib/ruby/gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:indriver'
/usr/lib/ruby/gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:157:in visit' /usr/lib/ruby/gems/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:invisit'

Need help.

Thank you

mfoo commented Oct 18, 2012

Webkit needs an X server in order to be able to render. If you're running on any Linux server distribution then you won't have an X server running. You can use the xvfb package to generate a virtual framebuffer for the duration of your tests. For example:

DISPLAY=localhost:1.0 xvfb-run cucumber

If you are running this on a build server you might have something like this:

DISPLAY=localhost:1.0 xvfb-run cucumber -p default -f junit -o cucumber

Thank you for the reply.
I am using capybara-webkit gem in my ruby(not rails) script

My Script

require 'rubygems'
require 'capybara-webkit'
require 'capybara/dsl'
require 'nokogiri'

include Capybara::DSL

Capybara.current_driver = :webkit

gem list on Linode

*** LOCAL GEMS ***

activesupport (3.2.8)
addressable (2.3.2)
bson (1.6.2)
bson_ext (1.6.2)
capybara (1.1.2)
capybara-webkit (0.12.1)
childprocess (0.3.6)
commonwatir (4.0.0)
ffi (1.1.5)
firewatir (1.9.4)
i18n (0.6.1)
json (1.7.3)
libwebsocket (0.1.5)
mime-types (1.19)
mongo (1.6.2)
multi_json (1.3.6)
nokogiri (1.5.2)
rack (1.4.1)
rack-test (0.6.2)
ruby-ole (
rubyzip (0.9.9)
selenium-webdriver (2.25.0)
spreadsheet (0.7.3)
watir-webdriver (0.6.1)
xpath (0.1.4)

I tried
DISPLAY=localhost:1.0 xvfb-run webkit
/usr/bin/xvfb-run: 181: webkit: not found

I tried this on my EC2 and on Linode

Please tell me if I am going wrong somewhere because its working fine on my local machine which is running on ubuntu 10.04 and does not even have xvfb package

mfoo commented Oct 18, 2012

Your local machine will have a desktop session which therefore has an X session running, that's why it works.

I tried
DISPLAY=localhost:1.0 xvfb-run webkit
/usr/bin/xvfb-run: 181: webkit: not found

You just need to pass the name of the executable you're using to xvfb-run. In the above, the webkit process doesn't seem to exist on the PATH. If webkit is really the executable that you're trying to run, check that it's installed. The only change that you should need to make between the command you run locally and command you run remotely is putting the DISPLAY...xvfb-run command in front.


Thank you man.. Worked perfectly :)

@naveediitb naveediitb closed this Oct 18, 2012

Is there a way to set this as the default x server on ubuntu server?

I mean, to not to run:

DISPLAY=localhost:1.0 xvfb-run rspec -t js spec

but, just

rspec -t js spec


nevermind, i'm just gonna alias it

jferris commented Apr 5, 2013

You can do an export DISPLAY=... in your shell profile.


How to fix the below error. i have installed QT5 and the environment is linux.

�[31mFailure/Error: login_as user, property�[0m
�[31m /home/jenkins/.rvm/gems/ext-jruby-1.7.20@resquared/gems/capybara-webkit-1.3.1/bin/webkit_server failed to start.�[0m
�[36m# /home/jenkins/.rvm/gems/ext-jruby-1.7.20@resquared/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:75:in `parse_port'�[0m


@pcsgithubid might want to check the solutions proposed here: #678

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment