Capybara webkit invalid response error, how to debug?

◇◆丶佛笑我妖孽 提交于 2019-11-29 02:06:10

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!

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.

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!