Sha256: 72bca81a6fbe1c2697b4b058bf65a6a39754c6d1bc793fe2181aa29a2574bda2

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

require 'billy'
require 'watir'

module Billy
  module Browsers
    class Watir < ::Watir::Browser

      def initialize(name, args = {})
        args = case name
          when :chrome then configure_chrome(args)
          when :phantomjs then configure_phantomjs(args)
          when :firefox then configure_firefox(args)
          else
            raise NameError, "Invalid browser driver specified. (Expected: :chrome, :phantomjs, :firefox)"
        end
        super
      end

      private

      def configure_chrome(args)
        args[:switches] ||= []
        args[:switches] += %W[--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}]
        args
      end

      def configure_phantomjs(args)
        args[:driver_opts] ||= {}
        args[:driver_opts][:args] ||= []
        args[:driver_opts][:args] += %W[--proxy=#{Billy.proxy.host}:#{Billy.proxy.port}]
        args
      end

      def configure_firefox(args)
        args[:profile] ||= Selenium::WebDriver::Firefox::Profile.new
        args[:profile].proxy = Selenium::WebDriver::Proxy.new(
          http: "#{Billy.proxy.host}:#{Billy.proxy.port}",
          ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}"
        )
        args
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puffing-billy-2.1.1 lib/billy/browsers/watir.rb
puffing-billy-2.1.0 lib/billy/browsers/watir.rb
puffing-billy-2.0.0 lib/billy/browsers/watir.rb
puffing-billy-1.1.3 lib/billy/browsers/watir.rb
puffing-billy-1.1.2 lib/billy/browsers/watir.rb
puffing-billy-1.1.1 lib/billy/browsers/watir.rb
puffing-billy-1.1.0 lib/billy/browsers/watir.rb
puffing-billy-1.0.0 lib/billy/browsers/watir.rb