class SugoiWebpageCapture::Browser

Constants

BROWSERS

Public Class Methods

new(browser_name = :firefox) click to toggle source
# File lib/sugoi_webpage_capture/browser.rb, line 22
def initialize(browser_name = :firefox)
  @browser_name = browser_name
  init
end

Public Instance Methods

capture(captured_url) { |self| ... } click to toggle source
# File lib/sugoi_webpage_capture/browser.rb, line 27
def capture(captured_url, &block)
  Capybara.reset_sessions!
  page.current_window.resize_to(*BROWSERS[@browser_name][:size])
  @screenshot = Screenshot.new(Tempfile.new(["ss", ".png"]))
  visit captured_url
  yield(self) if block_given?
  page.driver.save_screenshot(@screenshot.tempfile, full: true) # TODO Chtome full size capture
  @screenshot
end
quit() click to toggle source
# File lib/sugoi_webpage_capture/browser.rb, line 37
def quit
  @screenshot.tempfile.unlink if @screenshot
end

Private Instance Methods

init() click to toggle source
# File lib/sugoi_webpage_capture/browser.rb, line 43
def init
  raise("not found browser") unless BROWSERS.key?(@browser_name)
  Capybara.run_server = false
  Capybara.register_driver(@browser_name) do |app|
    Capybara::Selenium::Driver.new(app, opts)
  end
  Capybara.current_driver = @browser_name
end
opts() click to toggle source
# File lib/sugoi_webpage_capture/browser.rb, line 52
def opts
  h = {}
  if BROWSERS[@browser_name][:required_profile]
    h[:args] = ["--user-agent=#{BROWSERS[@browser_name][:ua]}"]
  end
  h[:browser] = BROWSERS[@browser_name][:browser]
  h
end