Module: Webstract::ScreenshotBackend

Defined in:
lib/webstract/screenshot_backend.rb

Constant Summary collapse

USER_AGENTS =
{
  web: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31',
  android: 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
  ios: 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'
}
@@width =
1024
@@height =
768
@@accept_language =
'en-us,en;q=0.5'
@@basic_auth =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capybara_setup!Object

Capibara setup



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/webstract/screenshot_backend.rb', line 51

def self.capybara_setup!
  # By default Capybara will try to boot a rack application
  # automatically. You might want to switch off Capybara's
  # rack server if you are running against a remote application
  Capybara.run_server = false
  Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(app, {
      # Raise JavaScript errors to Ruby
      js_errors: false,
      debug: ENV['WEBSTRACT_DEBUG'] || false,
      # Additional command line options for PhantomJS
      phantomjs_options: ['--ignore-ssl-errors=yes'],
    })
  end
  Capybara.current_driver = :poltergeist
end

.setup {|_self| ... } ⇒ Object

Customize settings

Yields:

  • (_self)

Yield Parameters:



46
47
48
# File 'lib/webstract/screenshot_backend.rb', line 46

def self.setup
  yield(self)
end

.user_agentObject



34
35
36
# File 'lib/webstract/screenshot_backend.rb', line 34

def user_agent
  @user_agent ||= USER_AGENTS[:web]
end

.user_agent=(ua) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'lib/webstract/screenshot_backend.rb', line 37

def user_agent=(ua)
  agent_string = USER_AGENTS[ua]
  raise(ArgumentError.new('must be one of #{USER_AGENTS.inspect}')) unless agent_string
  @user_agent = agent_string
end

Instance Method Details

#widthObject

Browser settings Width



17
# File 'lib/webstract/screenshot_backend.rb', line 17

mattr_accessor :width