Sha256: f9e406a29462c47b99d5821a38c5e68ffa98e3f2b280842cb77ce59f05ea7e88

Contents?: true

Size: 1.12 KB

Versions: 20

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
require 'proxy_rb/drivers/basic_driver'
require 'capybara'
require 'selenium-webdriver'
require 'proxy_rb/errors'

# ProxyRb
module ProxyRb
  # Drivers
  module Drivers
    # Driver for Selenium
    class SeleniumDriver < BasicDriver
      # Register proxy
      #
      # @param [HttpProxy] proxy
      #   The HTTP proxy which should be used for fetching content
      def register(proxy)
        if proxy.empty?
          ::Capybara.current_driver = :selenium
          return
        end

        profile = Selenium::WebDriver::Firefox::Profile.new
        # profile.proxy = Selenium::WebDriver::Proxy.new(http: proxy.full_url)
        profile.proxy = Selenium::WebDriver::Proxy.new(http: format('%s:%s', proxy.host, proxy.port))

        unless ::Capybara.drivers.key? proxy.to_ref
          ::Capybara.register_driver proxy.to_ref do |app|
            ::Capybara::Selenium::Driver.new(app, profile: profile)
          end
        end

        ::Capybara.current_driver = proxy.to_ref
      end

      def timeout_errors
        []
      end

      def failure_errors
        []
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
proxy_rb-1.0.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.6 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.5 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.4 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.3 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.2 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.1 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.10.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.9.3 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.9.2 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.9.1 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.9.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.8.3 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.8.2 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.8.1 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.8.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.7.1 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.7.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.6.0 lib/proxy_rb/drivers/selenium_driver.rb
proxy_rb-0.5.0 lib/proxy_rb/drivers/selenium_driver.rb