如何跳过Capybara的SSL证书验证

时间:2013-12-19 17:34:36

标签: ruby capybara

我正在尝试测试通过HTTPS提供的网络应用,但我无法跳过证书验证:

#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "capybara"
require "capybara/dsl"
require "capybara-webkit"

Capybara.run_server = false
Capybara.register_driver :webkit do |app|
  Capybara::Driver::Webkit.new(app, :ignore_ssl_errors => true)
end
Capybara.current_driver = :webkit
Capybara.app_host = "https://foo.bar.com"

module Test
  class Net
include Capybara::DSL

def get_results
  visit('/index.jsp')
  fill_in "#UserId", :with => "sheldon"
  fill_in "#Pwd", :with => "cooper"
  click_button "Enter"

  page.save_screenshot('screenshot.png')
end
  end
end

spider = Test::Net.new
spider.get_results

我明白了:

net.rb:10:in `initialize': wrong number of arguments (2 for 0) (ArgumentError)
    from net.rb:10:in `new'
    from net.rb:10:in `block in <main>'
    from /usr/local/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/session.rb:69:in `call'
    from /usr/local/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/session.rb:69:in `driver'
    from /usr/local/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/session.rb:197:in `visit'
    from /usr/local/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
    from net.rb:20:in `get_results'
    from net.rb:31:in `<main>'

如何跳过它?

1 个答案:

答案 0 :(得分:4)

我相信API已经改变,您需要这样做:

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