Class: Girbot::BrowserHolder

Inherits:
Object
  • Object
show all
Defined in:
lib/girbot/browser_holder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(which = 'firefox', proxy = nil) ⇒ BrowserHolder

Returns a new instance of BrowserHolder.



5
6
7
8
# File 'lib/girbot/browser_holder.rb', line 5

def initialize which='firefox', proxy=nil
  @which = which
  @proxy = proxy
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



3
4
5
# File 'lib/girbot/browser_holder.rb', line 3

def browser
  @browser
end

#proxyObject

Returns the value of attribute proxy.



3
4
5
# File 'lib/girbot/browser_holder.rb', line 3

def proxy
  @proxy
end

#whichObject

Returns the value of attribute which.



3
4
5
# File 'lib/girbot/browser_holder.rb', line 3

def which
  @which
end

Instance Method Details

#chromeObject



28
29
30
# File 'lib/girbot/browser_holder.rb', line 28

def chrome
  Watir::Browser.new :chrome
end

#chrome_proxy(proxy) ⇒ Object



32
33
34
35
# File 'lib/girbot/browser_holder.rb', line 32

def chrome_proxy proxy
  switches = "--proxy-server=#{proxy}"
  Watir::Browser.new :chrome, :switches => switches
end

#firefoxObject



18
19
20
# File 'lib/girbot/browser_holder.rb', line 18

def firefox
  Watir::Browser.new :firefox
end

#firefox_proxy(proxy) ⇒ Object



22
23
24
25
26
# File 'lib/girbot/browser_holder.rb', line 22

def firefox_proxy proxy
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile.proxy = Selenium::WebDriver::Proxy.new :http => proxy, :ssl => proxy
  Watir::Browser.new :firefox, :profile => profile
end

#initObject



10
11
12
13
14
15
16
# File 'lib/girbot/browser_holder.rb', line 10

def init
  if @proxy.nil?
    @browser = send(@which)
  else
    @browser = send("#{@which}_proxy", @proxy)
  end
end