How to use ssl method of Capybara Package

Best Capybara code snippet using Capybara.ssl

server_spec.rb

Source:server_spec.rb Github

copy

Full Screen

...57 it 'should support SSL' do58 begin59 key = File.join(Dir.pwd, 'spec', 'fixtures', 'key.pem')60 cert = File.join(Dir.pwd, 'spec', 'fixtures', 'certificate.pem')61 Capybara.server = :puma, { Host: "ssl://#{Capybara.server_host}?key=#{key}&cert=#{cert}" }62 app = proc { |_env| [200, {}, ['Hello SSL Server!']] }63 server = Capybara::Server.new(app).boot64 expect do65 Net::HTTP.start(server.host, server.port) { |http| http.get('/__idntify__') }66 end.to raise_error(EOFError)67 res = Net::HTTP.start(server.host, server.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |https|68 https.get('/')69 end70 expect(res.body).to include('Hello SSL Server!')71 ensure72 Capybara.server = :default73 end74 end75 context 'When Capybara.reuse_server is true' do76 before do77 @old_reuse_server = Capybara.reuse_server78 Capybara.reuse_server = true79 end80 after do81 Capybara.reuse_server = @old_reuse_server82 end83 it 'should use the existing server if it already running' do84 @app = proc { |_env| [200, {}, ['Hello Server!']] }85 @server1 = Capybara::Server.new(@app).boot86 @server2 = Capybara::Server.new(@app).boot87 res = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') }88 expect(res.body).to include('Hello Server')89 res = Net::HTTP.start(@server2.host, @server2.port) { |http| http.get('/') }90 expect(res.body).to include('Hello Server')91 expect(@server1.port).to eq(@server2.port)92 end93 it 'detects and waits for all reused server sessions pending requests' do94 done = 095 app = proc do |env|96 request = Rack::Request.new(env)97 sleep request.params['wait_time'].to_f98 done += 199 [200, {}, ['Hello Server!']]100 end101 server1 = Capybara::Server.new(app).boot102 server2 = Capybara::Server.new(app).boot103 expect do104 start_request(server1, 1.0)105 start_request(server2, 3.0)106 server1.wait_for_pending_requests107 end.to change { done }.from(0).to(2)108 expect(server2.send(:pending_requests?)).to eq(false)109 end110 end111 context 'When Capybara.reuse_server is false' do112 before do113 @old_reuse_server = Capybara.reuse_server114 Capybara.reuse_server = false115 end116 after do117 Capybara.reuse_server = @old_reuse_server118 end119 it 'should not reuse an already running server' do120 @app = proc { |_env| [200, {}, ['Hello Server!']] }121 @server1 = Capybara::Server.new(@app).boot122 @server2 = Capybara::Server.new(@app).boot123 res = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') }124 expect(res.body).to include('Hello Server')125 res = Net::HTTP.start(@server2.host, @server2.port) { |http| http.get('/') }126 expect(res.body).to include('Hello Server')127 expect(@server1.port).not_to eq(@server2.port)128 end129 it 'detects and waits for only one sessions pending requests' do130 done = 0131 app = proc do |env|132 request = Rack::Request.new(env)133 sleep request.params['wait_time'].to_f134 done += 1135 [200, {}, ['Hello Server!']]136 end137 server1 = Capybara::Server.new(app).boot138 server2 = Capybara::Server.new(app).boot139 expect do140 start_request(server1, 1.0)141 start_request(server2, 3.0)142 server1.wait_for_pending_requests143 end.to change { done }.from(0).to(1)144 expect(server2.send(:pending_requests?)).to eq(true)145 expect do146 server2.wait_for_pending_requests147 end.to change { done }.from(1).to(2)148 end149 end150 it 'should raise server errors when the server errors before the timeout' do151 begin152 Capybara.register_server :kaboom do153 sleep 0.1154 raise 'kaboom'155 end156 Capybara.server = :kaboom157 expect do158 Capybara::Server.new(proc { |e| }).boot159 end.to raise_error(RuntimeError, 'kaboom')160 ensure161 Capybara.server = :default162 end163 end164 it 'is not #responsive? when Net::HTTP raises a SystemCallError' do165 app = -> { [200, {}, ['Hello, world']] }166 server = Capybara::Server.new(app)167 allow(Net::HTTP).to receive(:start).and_raise(SystemCallError.allocate)168 expect(server.responsive?).to eq false169 end170 [EOFError, Net::ReadTimeout].each do |err|171 it "should attempt an HTTPS connection if HTTP connection returns #{err}" do172 app = -> { [200, {}, ['Hello, world']] }173 ordered_errors = [Errno::ECONNREFUSED, err]174 allow(Net::HTTP).to receive(:start).with(anything, anything, hash_excluding(:use_ssl)) do175 raise ordered_errors.shift176 end177 response = Net::HTTPSuccess.allocate178 allow(response).to receive(:body).and_return app.object_id.to_s179 allow(Net::HTTP).to receive(:start).with(anything, anything, hash_including(use_ssl: true)).and_return(response).once180 Capybara::Server.new(app).boot181 expect(Net::HTTP).to have_received(:start).exactly(3).times182 end183 end184 def start_request(server, wait_time)185 # Start request, but don't wait for it to finish186 socket = TCPSocket.new(server.host, server.port)187 socket.write "GET /?wait_time=#{wait_time} HTTP/1.0\r\n\r\n"188 sleep 0.1189 socket.close190 sleep 0.1191 end192end...

Full Screen

Full Screen

ssl

Using AI Code Generation

copy

Full Screen

1 def visit(url)2 @browser.navigate.to(url)3def visit(url)4 Capybara.visit(url)5visit("https://www.google.com/")

Full Screen

Full Screen

ssl

Using AI Code Generation

copy

Full Screen

1Capybara.visit('/')2 Capybara::Poltergeist::Driver.new(app, {inspector: true})3 Capybara::Poltergeist::Driver.new(app, {inspector: true, inspector_port: 1234})4 Capybara::Poltergeist::Driver.new(app, {inspector: true, inspector_port: 1234, inspector_host: '

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Capybara automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful