18

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?

23tux
  • 14,104
  • 15
  • 88
  • 187

4 Answers4

14

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?

mdgreenfield
  • 176
  • 1
  • 2
  • My CI don't executes any command for xvfb. This is handled inside the Headless gem (https://github.com/leonid-shevtsov/headless). Now I had a closer look on that, and i could figure out, that headless starts the Xvfb server with this command `system "#{CliUtil.path_to("Xvfb")} :#{display} -screen 0 #{dimensions} -ac >/dev/null 2>&1 &"`, where `CliUtil.path_to("Xvfb")` refers to ``which #{app}`.strip`. In my case the server returns `/usr/bin/Xvfb`. Ok, I try to temporarly override this method, so that it returns `xvfb-run` instead. Maybe that helps – 23tux Jul 21 '12 at 20:42
  • same issue here. been at this for over four hours. seems like there are two people on the planet with this issue. – kikuchiyo Jul 23 '12 at 06:05
5

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
ryanjones
  • 5,383
  • 4
  • 28
  • 24
  • 3
    why do you check for the production environment in a spec configuration file? shouldnt this file NOT be loaded when in Production env? – Peter P. Oct 16 '13 at 21:23
3

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
Dan Croak
  • 1,639
  • 13
  • 13
1

Install xvfb

sudo apt-get install xvfb 

Then execute your command using xvfb

xvfb-run rspec
jlucasps
  • 890
  • 7
  • 8