lib/quke/driver_configuration.rb in quke-0.2.6 vs lib/quke/driver_configuration.rb in quke-0.2.7

- old
+ new

@@ -116,11 +116,14 @@ # For example when initialising the driver like this # # Capybara::Selenium::Driver.new( # app, # browser: :chrome, - # switches: ["--proxy-server=localhost:8080"] + # switches: [ + # "--proxy-server=localhost:8080", + # "--proxy-bypass-list=127.0.0.1,192.168.0.1" + # ] # ) # # Rather than setting the switches manually Quke::DriverConfiguration.chrome # is intended to manage what they should be based on the properties of the # Quke::Configuration instance its initialised with @@ -129,17 +132,24 @@ # app, # browser: :chrome, # switches: my_driver_config.chrome # ) # + # rubocop:disable Metrics/AbcSize def chrome - if config.use_proxy? - ["--proxy-server=#{config.proxy['host']}:#{config.proxy['port']}"] - else - [] - end + result = [] + + host = config.proxy['host'] + port = config.proxy['port'] + no_proxy = config.proxy['no_proxy'].tr(',', ';') + + result.push("--proxy-server=#{host}:#{port}") if config.use_proxy? + result.push("--proxy-bypass-list=#{no_proxy}") unless config.proxy['no_proxy'].empty? + + result end + # rubocop:enable Metrics/AbcSize # Returns an instance of Selenium::WebDriver::Remote::Capabilities to be # used when registering an instance of Capybara::Selenium::Driver, # configured to run using Firefox (the default). # @@ -167,15 +177,19 @@ # # rubocop:disable Metrics/AbcSize def firefox profile = Selenium::WebDriver::Firefox::Profile.new - if config.use_proxy? - profile.proxy = Selenium::WebDriver::Proxy.new( - http: "#{config.proxy['host']}:#{config.proxy['port']}", - ssl: "#{config.proxy['host']}:#{config.proxy['port']}" - ) - end + settings = {} + host = config.proxy['host'] + port = config.proxy['port'] + no_proxy = config.proxy['no_proxy'] + + settings[:http] = "#{host}:#{port}" if config.use_proxy? + settings[:ssl] = settings[:http] if config.use_proxy? + settings[:no_proxy] = no_proxy unless config.proxy['no_proxy'].empty? + + profile.proxy = Selenium::WebDriver::Proxy.new(settings) if config.use_proxy? profile end # rubocop:enable Metrics/AbcSize