Class: SugoiWebpageCapture::Browser

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/sugoi_webpage_capture/browser.rb

Constant Summary collapse

BROWSERS =
{
  firefox: { ua: "", browser: :firefox, size: [1024, 768] },
  chrome:  { ua: "", browser: :chrome, size: [1024, 768] },
  iphone5: {
    ua: "Mozilla/5.0 (iPod touch; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4",
    browser: :chrome,
    size:[320, 568],
    required_profile: true
  },
  iphone6: {
    ua: "Mozilla/5.0 (iPod touch; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4",
    browser: :chrome,
    size: [375, 667],
    required_profile: true
  },
}

Instance Method Summary collapse

Constructor Details

#initialize(browser_name = :firefox) ⇒ Browser

Returns a new instance of Browser.



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

def initialize(browser_name = :firefox)
  @browser_name = browser_name
  init
end

Instance Method Details

#capture(captured_url) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
35
# 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

#quitObject



37
38
39
# File 'lib/sugoi_webpage_capture/browser.rb', line 37

def quit
  @screenshot.tempfile.unlink if @screenshot
end