Class: Browser

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

Instance Method Summary collapse

Constructor Details

#initialize(baseurl, urls, resolutions, path, headless, wait, cookies = [], localStorage = []) ⇒ Browser

Returns a new instance of Browser.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/controller/browser.rb', line 10

def initialize(baseurl, urls, resolutions, path, headless, wait, cookies = [], localStorage = [])
  @absolute_image_path = path
  FileUtils.mkdir_p @absolute_image_path
  @baseurl = baseurl
  @urls = urls
  @resolutions = resolutions
  @headless = headless
  @wait = wait

  if cookies
    @cookies = cookies
  else
    @cookies = []
  end

  if localStorage
    @localStorage = localStorage
  else
    @localStorage = []
  end
end

Instance Method Details

#endObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/controller/browser.rb', line 41

def end
  begin #Timeout::Error
    Timeout::timeout(10) { @browser.close }
  rescue Timeout::Error
    browser_pid = @browser.driver.instance_variable_get(:@bridge).instance_variable_get(:@service).instance_variable_get(:@process).pid
    ::Process.kill('KILL', browser_pid)
    sleep 1
  end
  sleep 5 # to prevent xvfb to freeze
end

#record(version) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/controller/browser.rb', line 32

def record(version)
  browser_loader
  @urls.each do |url|
    @resolutions.each do |width|
      screenshot_recorder(width, url, version)
    end
  end
end