Sha256: 19763fd4f3bc7b0ba42335b547ec82c2101c2b66684a88407a9664731253035e

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 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[:headless] = true
        args[:proxy] = {
          http: "#{Billy.proxy.host}:#{Billy.proxy.port}",
          ssl: "#{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-4.0.0 lib/billy/browsers/watir.rb
puffing-billy-3.2.0 lib/billy/browsers/watir.rb
puffing-billy-3.1.0 lib/billy/browsers/watir.rb
puffing-billy-3.0.4 lib/billy/browsers/watir.rb
puffing-billy-3.0.3 lib/billy/browsers/watir.rb
puffing-billy-3.0.2 lib/billy/browsers/watir.rb
puffing-billy-3.0.1 lib/billy/browsers/watir.rb
puffing-billy-3.0.0 lib/billy/browsers/watir.rb