need phantomjs >= 2.1
require 'capybara/poltergeist'
require 'phantomjs'
Capybara.register_driver :poltergeist do |app|
path_to_certs = '/home/evg2108/RubymineProjects/megafon_sbms/certificates/'
path_to_ca_certs = path_to_certs
cert = OpenSSL::PKCS12.new(File.open("#{path_to_certs}/my_certificate.pfx"), 'password')
f = File.open("#{path_to_certs}/key.key", 'w')
f.write(cert.key.to_s)
f.close
key = f.path
f = File.open("#{path_to_certs}/certificate.cer", 'w')
f.write(cert.certificate.to_s)
f.close
certificate = f.path
f = File.open("#{path_to_certs}/ca.crt", 'w')
f.write(cert.ca_certs.map(&:to_s).join)
f.close
ca_file = f.path
Capybara::Poltergeist::Driver.new(app, {
js_errors: false,
timeout: 100,
phantomjs: Phantomjs.path,
phantomjs_options: %W(--load-images=no --ignore-ssl-errors=yes --ssl-protocol=any --ssl-client-certificate-file=#{certificate} --ssl-client-key-file=#{key} --ssl-certificates-path=#{path_to_ca_certs})})
end
Capybara.configure do |config|
config.run_server = false
config.default_wait_time = 60
end
Capybara.default_driver = :poltergeist
@agent = Capybara::Session.new :poltergeist
@agent.visit('https://site_with_client_certificate_auth.org')