Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headless gem: webkit_server: cannot connect to X server

I've got some problems running capybara-webkit with the Headless gem, Xvfb and our ci server. We use this setup for automatic integration testing and javascript testing of our Ruby on Rails 3.2 app. During the tests it complains that

webkit_server: cannot connect to X server

But when I ps aux | grep Xvfb

deploy    1602  0.0  0.1  61696  1912 pts/2    S+   Jul10   0:00 /usr/bin/Xvfb :99 -screen 0 1280x1024x24 -ac

I see the Xvfb running. If I run the tests with --trace it also only shows the error log above and I can't debug the error.

Any ideas how I could get some more information, or even a solution?

like image 319
23tux Avatar asked Jul 12 '12 09:07

23tux


4 Answers

I was trying to get the capybara-webkit gem working with capybara and ended up using xvfb-run in the CI job for my tests.

xvfb-run bundle exec cucumber ...

What is the command your CI job is executing?

like image 101
mdgreenfield Avatar answered Nov 06 '22 03:11

mdgreenfield


We ran into the same issue... Turns out that in our spec_helper.rb we were missing the headless start command (below).

Here's our rspec config:

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/webkit'
require 'headless'

Capybara.register_driver :webkit do |app|
  Capybara::Driver::Webkit.new(app, :ignore_ssl_errors => true)
end

Capybara.javascript_driver = :webkit

# don't run on the local machine (since we don't have xvfb running locally)
if Rails.env.production?
    headless = Headless.new
    headless.start
end
like image 33
ryanjones Avatar answered Nov 06 '22 03:11

ryanjones


If you're using Travis CI, you might get some mileage from this configuration setting:

before_install:
- "echo 'gem: --no-document' > ~/.gemrc"
- "echo '--colour' > ~/.rspec"
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
like image 3
Dan Croak Avatar answered Nov 06 '22 01:11

Dan Croak


Install xvfb

sudo apt-get install xvfb 

Then execute your command using xvfb

xvfb-run rspec
like image 1
jlucasps Avatar answered Nov 06 '22 02:11

jlucasps