← Back to Upcase

Facing issue while installing capybara-webkit on Ubuntu


(Kamal Garg) #1

I am running my rails development environment on Ubuntu-14.04 LTS.

I have added capybara-webkit to my bundler and executed ‘bundle install’.

group :development, :test do
    gem 'factory_girl'
    gem 'rspec-rails', '~> 3.0'
    gem 'capybara'
    gem "capybara-webkit"
end

Bundle install failed with error. I did the following and tried again…

sudo apt-get update
sudo apt-get install mesa-common-dev
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
sudo apt-get install libqt4-dev libqtwebkit-dev build-essential

This time ‘bundle install’ was successful. No error.

I added following to ‘Rails helper’ and restarted my rails application.

Capybara.javascript_driver = :webkit
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

I followed the instructions given in “http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara” and created a file “spec/support/wait_for_ajax.rb” with following content.

module WaitForAjax
  def wait_for_ajax
    Timeout.timeout(Capybara.default_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end
end

Then, I created a spec file "spec/features/guest_login_spec.rb with following test

feature "Guest attempt login" do
    scenario "with valid email and password", js: true do
        visit root_path
        click_on 'Login'
        wait_for_ajax
        reload_page
        expect(page).to have_css "#login"
    end
end

I tried to execute the test and got following error:

Failures:

  1) Guest attempt login with valid email and password
     Failure/Error: visit root_path
     Capybara::Webkit::ConnectionError:
       /home/ubuntu/.rvm/gems/ruby-2.0.0-p576/gems/capybara-webkit-1.3.1/bin/webkit_server failed to start.
     # /home/ubuntu/.rvm/gems/ruby-2.0.0-p576/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:75:in `parse_port'

I don’t have any idea about the issue. I am not sure whether the problem is with installation or test or in configuration. I tried to find solution in forums but in vein.

I will really appreciate if you can help me setting up the capybara-webkit correctly and fix this issue.

I am using:

OS:        Ubuntu 14.04 LTS on x86_64
Rails:     4.1.5
Ruby:      2.0.0p576
Bundler:   1.7.3

Gemfile.lock

$ cat Gemfile.lock | grep capybara
    capybara (2.4.4)
    capybara-webkit (1.3.1)
      capybara (>= 2.0.2, < 2.5.0)
  capybara
  capybara-webkit

Many Thanks,
Kamal