Class: GreenOnion::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/green_onion/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Browser

Returns a new instance of Browser.



6
7
8
9
10
# File 'lib/green_onion/browser.rb', line 6

def initialize(params={})
  @driver = params[:driver]
  @dimensions = params[:dimensions]
  load_driver
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



4
5
6
# File 'lib/green_onion/browser.rb', line 4

def dimensions
  @dimensions
end

#driverObject (readonly)

Returns the value of attribute driver.



4
5
6
# File 'lib/green_onion/browser.rb', line 4

def driver
  @driver
end

Instance Method Details

#load_driverObject



12
13
14
15
16
17
18
19
20
# File 'lib/green_onion/browser.rb', line 12

def load_driver
  begin
    require "green_onion/drivers/#{driver}"
    @driver_obj = GreenOnion.const_get(@driver.capitalize).new
  rescue LoadError => e
    raise e unless e.message.include?("green_onion/drivers")
    raise ArgumentError.new("#{@driver} is not supported by GreenOnion.")
  end
end

#snap_screenshot(url, path) ⇒ Object



22
23
24
# File 'lib/green_onion/browser.rb', line 22

def snap_screenshot(url, path)
  @driver_obj.record(url, path, @dimensions)
end