class Schur
Constants
- DRIVER_TYPES
- VERSION
Public Class Methods
call(driver=:mechanize, proxy=nil)
click to toggle source
# File lib/schur.rb, line 22 def self.call(driver=:mechanize, proxy=nil) case driver when :mechanize agent = Mechanize.new if proxy agent.set_proxy(proxy.host, proxy.port, proxy.id, proxy.pw) end agent when :poltergeist if proxy ::Capybara.register_driver :poltergeist_with_proxy do |app| ::Capybara::Poltergeist::Driver.new(app, phantomjs_options: ["--proxy=#{proxy.host}:#{proxy.port}", "--proxy-auth=#{proxy.id}:#{proxy.pw}"], js_errors: false, timeout: 100 ) end Capybara::Session.new(:poltergeist_with_proxy) else Capybara::Session.new(:poltergeist) end when :firefox if proxy ::Capybara.register_driver :firefox_with_proxy do |app| profile = ::Selenium::WebDriver::Firefox::Profile.new # profile.proxy = Selenium::WebDriver::Proxy.new(http: format('%s:%s', proxy.host, proxy.port)) profile["network.proxy.type"] = 1 profile["network.proxy.http"] = "http://#{proxy.id}:#{proxy.pw}@#{proxy.host}/" profile["network.proxy.http_port"] = 31280 ::Capybara::Selenium::Driver.new(app, profile: profile) end Capybara::Session.new(:firefox_with_proxy) else Capybara::Session.new(:firefox) end end end