How to use new_http_client method of Selenium.WebDriver.Remote.Http Package

Best Selenium code snippet using Selenium.WebDriver.Remote.Http.new_http_client

default.rb

Source:default.rb Github

copy

Full Screen

...8 attr_accessor :proxy9 private10 def http11 @http ||= (12 http = new_http_client13 if server_url.scheme == "https"14 http.use_ssl = true15 http.verify_mode = OpenSSL::SSL::VERIFY_NONE16 end17 if @timeout18 http.open_timeout = @timeout19 http.read_timeout = @timeout20 end21 http22 )23 end24 def request(verb, url, headers, payload, redirects = 0)25 request = new_request_for(verb, url, headers)26 retried = false27 begin28 response = http.request(request, payload)29 rescue Errno::ECONNABORTED, Errno::ECONNRESET30 # this happens sometimes on windows?!31 raise if retried32 request = new_request_for(verb, url, headers)33 retried = true34 retry35 end36 if response.kind_of? Net::HTTPRedirection37 raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS38 request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)39 else40 create_response response.code, response.body, response.content_type41 end42 end43 def new_request_for(verb, url, headers)44 req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)45 if server_url.userinfo46 req.basic_auth server_url.user, server_url.password47 end48 req49 end50 def new_http_client51 if @proxy52 unless @proxy.respond_to?(:http) && url = @proxy.http53 raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"54 end55 proxy = URI.parse(url)56 clazz = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password)57 clazz.new(server_url.host, server_url.port)58 else59 Net::HTTP.new server_url.host, server_url.port60 end61 end62 end # Default63 end # Http64 end # Remote...

Full Screen

Full Screen

persistent.rb

Source:persistent.rb Github

copy

Full Screen

...8 def close9 @http.shutdown if @http10 end11 private12 def new_http_client13 proxy = nil14 if @proxy15 unless @proxy.respond_to?(:http) && url = @proxy.http16 raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"17 end18 proxy = URI.parse(url)19 end20 Net::HTTP::Persistent.new "webdriver", proxy21 end22 def response_for(request)23 http.request server_url, request24 end25 end # Persistent26 end # Http...

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 Selenium automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful