Class: SugoiWebpageCapture::Browser
- Inherits:
-
Object
- Object
- SugoiWebpageCapture::Browser
- 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
- #capture(captured_url) {|_self| ... } ⇒ Object
-
#initialize(browser_name = :firefox) ⇒ Browser
constructor
A new instance of Browser.
- #quit ⇒ Object
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
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 |
#quit ⇒ Object
37 38 39 |
# File 'lib/sugoi_webpage_capture/browser.rb', line 37 def quit @screenshot.tempfile.unlink if @screenshot end |