Capybara webkit invalid response error, how to debug?
Asked Answered
M

4

10

I'm trying to write a request spec for a web page.

This page works in development without error.

But running in capybara webkit I get this error after trying to submit the form:

 Failure/Error: Unable to find matching line from backtrace
 Capybara::Driver::Webkit::WebkitInvalidResponseError:
   Unable to load URL: https://127.0.0.1:33416/sign_in

In an effort to find out the cause I've started stripping out markup and JavaScript on the page. To the point where it is an empty form with a plain submit button. I still get the above error!

The test is now literally:

it "should be able create a new foo", :js, :focus do
  visit new_foo_path
  find('#submit').click
end

This test does however work if I remove the :js option:

it "should be able create a new foo", :focus do
  visit new_foo_path
  find('#submit').click
end

Javascript tests do work in other pages on this application...

This is making no sense to me. Does anyone have any suggestions how to debug from here?

Thanks for any help

Monteux answered 1/8, 2012 at 10:15 Comment(0)
D
7

The error you're seeing is most likely capybara-webkit's cryptic way of telling you that there is some sort of exception in the page. I had the same problem a while back, and the "Unable to load URL" thing totally threw me off, making it hard to find the actual problem.

As a few things to try, I'd suggest:

  • Make sure you have the latest version of capybara-webkit installed.
  • Check elements of the test other than the actual form, e.g. the controller logic and any models that are involved. Strip everything out until you have nothing.
  • Check out the discussion on this issue and follow leads from there. I'm pretty sure it's the same problem or a related one.

Good luck!

Disaccredit answered 9/8, 2012 at 8:53 Comment(2)
thanks...absolutely right in my case had nothing to do with selenium at all!Tice
The problem was I was forcing ssl in my application_controller with no exclusion for the test environmentTice
S
19

Add the following to your capybara config.

require 'rack/utils'
Capybara.app = Rack::ShowExceptions.new(NameOfYourRailsApp::Application)

When you get an error now you'll see it on stdout and rack will render a page with details about the environment(cookies etc.) and the backtrace.

Sourpuss answered 30/8, 2012 at 10:34 Comment(2)
I've been looking for this for what seems like forever. I was having VCR recording errors that weren't showing up anywhere, so I had no idea what was going on. Now I can see the problem. Thank you!Houghton
This should be the accepted answer (my answer was just a few suggestions, this one really solves the problem).Disaccredit
D
7

The error you're seeing is most likely capybara-webkit's cryptic way of telling you that there is some sort of exception in the page. I had the same problem a while back, and the "Unable to load URL" thing totally threw me off, making it hard to find the actual problem.

As a few things to try, I'd suggest:

  • Make sure you have the latest version of capybara-webkit installed.
  • Check elements of the test other than the actual form, e.g. the controller logic and any models that are involved. Strip everything out until you have nothing.
  • Check out the discussion on this issue and follow leads from there. I'm pretty sure it's the same problem or a related one.

Good luck!

Disaccredit answered 9/8, 2012 at 8:53 Comment(2)
thanks...absolutely right in my case had nothing to do with selenium at all!Tice
The problem was I was forcing ssl in my application_controller with no exclusion for the test environmentTice
E
3

I'm working with subdomains and I could make it work adding the following to spec_helper.rb:

Capybara.configure do |config|
  config.javascript_driver = :webkit
  config.server_port = 3000
  config.app_host = "http://subdomain.local.host:3000"
end

Obviously adding before 127.0.0.1 subdomain.local.host to my /etc/hosts file

Elisavetgrad answered 27/8, 2013 at 22:49 Comment(1)
This works as long as you're already running your app locally. If you rely on Capybara starting your app automatically, e.g. with Puma, then configuring app_host might make the driver visit the absolute url (if capabable, e.g. Selenium). This can be an issue if you're not expecting to visit a live site outside of your local network =) See: github.com/teamcapybara/capybara/blob/3.35.3/lib/capybara/…Mastiff
L
2

I had a similar issue and was able to fix it by enabling page.driver.browser.ignore_ssl_errors for :js enabled tests. Here's the code that worked for me:

config.before(:each) do
    if Capybara.current_driver == :webkit
      # Need to manually specify ignoring of SSL errors
      page.driver.browser.ignore_ssl_errors
    end
end
Lynnalynne answered 17/2, 2015 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.