How to set the ignore_ssl_errors option for Capybara Webkit in spec_helper.rb

笑着哭i 提交于 2019-12-05 12:48:05

Here's how to register the :webkit driver with the :ignore_ssl_errors option.

Capybara.register_driver :webkit do |app|
  Capybara::Driver::Webkit.new(app, :ignore_ssl_errors => true)
end

As of writing (capybara-webkit 1.7.1), the configuration seems to have been simplified:

Capybara::Webkit.configure do |config|
  config.ignore_ssl_errors
end

(source)

Somehow the above register_driver examples don't work with Capybara 1.1.4. The example below is taken from the capybara browser_spec.rb.

Capybara.register_driver :webkit_ignore_ssl do |app|
  browser = Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|
    browser.ignore_ssl_errors
  end
  Capybara::Webkit::Driver.new(app, :browser => browser)
end
Capybara.javascript_driver = :webkit_ignore_ssl

As @hjblok says, the interface has changed in recent versions of capybara-webkit. You can simplify the solution slightly:

Capybara.register_driver :webkit_ignore_ssl do |app|
  Capybara::Webkit::Driver.new(app).tap {|d| d.browser.ignore_ssl_errors }
end
Capybara.javascript_driver = :webkit_ignore_ssl

When createing a new webkit Object you can use this to ignore the ssl errors

Capybara::Driver::Webkit.new({ :ignore_ssl_errors => true})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!