Webkit_Server Hangs Periodically When Run from Capybara in Ruby

Headless gem: webkit_server: cannot connect to X server

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?

Is it possible to run capybara-webkit (i.e. forked webkit_server) on Heroku Cedar?

I spoke to Heroku support about this and their answer was that this is basically a) unsupported; b) very difficult, including (among other things) a statically built version of QtWebKit.

My own investigation into this on Amazon EC2 also made me realize that QtWebKit requires a running instance of Xvfb. I highly doubt this would be available on Heroku, and I suspect it would be extremely difficult to make it work.

My own approach has been to put this functionality on an EC2 instance. After making some attempts with Amazon's standard AMIs (their build and RHEL), I found that the packages available through Ubuntu's package management systems made it MUCH easier to get up an running.

Long story short: Heroku is a non-starter, Amazon EC2 with Ubuntu is the best way to go.

Upgrade to Rails 4 led to rspec output hanging

I had the same problem, but with capybara-webkit.

I found the solution here: webkit_server hangs periodically when run from Capybara in Ruby

# Gemfile
group :test do
gem 'thin'
end

# spec_helper.rb
Capybara.javascript_driver = :webkit
Capybara.server do |app, port|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port)
end

Access all loaded resources with Capybara or similar

As mentioned in an update, there seems to be a way to do this with Poltergeist (a Capybara driver). Here’s a quick and very “hackish” experiment:

require 'rubygems'
require 'capybara'
require 'capybara/poltergeist'

driver = Capybara::Poltergeist::Driver.new({})
port = Capybara::Poltergeist::Util.find_available_port
server = Capybara::Poltergeist::Server.new(port, 30)
client = Capybara::Poltergeist::Client.start(port,
:path => driver.options[:phantomjs],
:window_size => driver.options[:window_size],
:phantomjs_options => driver.phantomjs_options
)

browser = Capybara::Poltergeist::Browser.new(server, client, nil)
browser.visit('http://www.google.com/')

browser.network_traffic.each do |request|
# sorry, quick and dirty to see what we get:
request.response_parts.uniq(&:url).each do |response|
puts "#{response.url}: #{response.status}"
end
end

=>

http://www.google.com/: 200
http://ssl.gstatic.com/gb/images/b_8d5afc09.png: 200
http://www.google.com/images/srpr/logo1w.png: 200
http://www.google.com/images/srpr/nav_logo80.png: 200
http://www.google.com/xjs/_/js/hp/sb_he,pcc/rt=j/ver=FaiMBboaDLc.en_US./d=1/sv=1/rs=AItRSTMKxoHomLOW7ITf6OnfIEr5jQCEtA: 200

This however is very slow and of course far from anything usable. I’m planning on digging deeper into Poltergeist to maybe do the same on a lower level.



Related Topics



Leave a reply



Submit