Headless gem: webkit_server: cannot connect to X server
Asked Answered
P

4

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?

Pylos answered 12/7, 2012 at 9:27 Comment(0)
C
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?

Capp answered 16/7, 2012 at 1:37 Comment(2)
My CI don't executes any command for xvfb. This is handled inside the Headless gem (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 helpsPylos
same issue here. been at this for over four hours. seems like there are two people on the planet with this issue.Hydrology
Q
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
Qualify answered 30/8, 2012 at 21:36 Comment(1)
why do you check for the production environment in a spec configuration file? shouldnt this file NOT be loaded when in Production env?Dextrous
S
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
Supersonic answered 16/10, 2013 at 23:30 Comment(1)
The first two echo statements are unrelated and might be confusing for others.Canonize
C
1

Install xvfb

sudo apt-get install xvfb 

Then execute your command using xvfb

xvfb-run rspec
Chinkiang answered 30/9, 2014 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.