Module: Howitzer::CapybaraHelpers

Defined in:
lib/howitzer/capybara_helpers.rb

Overview

This module holds capybara helpers methods

Constant Summary collapse

CHECK_YOUR_SETTINGS_MSG =

:nodoc:

'Please check your settings'.freeze
HOWITZER_KNOWN_BROWSERS =

:nodoc:

[ #:nodoc:
  CLOUD_BROWSERS = [
    SAUCE = :sauce,
    TESTINGBOT = :testingbot,
    BROWSERSTACK = :browserstack,
    CROSSBROWSERTESTING = :crossbrowsertesting
  ].freeze,
  LOCAL_BROWSERS = [
    HEADLESS_CHROME = :headless_chrome,
    PHANTOMJS = :phantomjs,
    POLTERGEIST = :poltergeist,
    SELENIUM = :selenium,
    SELENIUM_GRID = :selenium_grid,
    WEBKIT = :webkit
  ].freeze
].freeze

Instance Method Summary collapse

Instance Method Details

#chrome_browser?Boolean

Returns whether or not current browser is Google Chrome.

Returns:

  • (Boolean)

    whether or not current browser is Google Chrome.

Raises:



53
54
55
# File 'lib/howitzer/capybara_helpers.rb', line 53

def chrome_browser?
  browser?(:chrome) || Howitzer.driver == HEADLESS_CHROME.to_s
end

#cloud_driver(app, caps, url) ⇒ Capybara::Selenium::Driver

Buids selenium driver for a cloud service

Parameters:

  • app (<Rack>)

    a rack application that this server will contain

  • caps (Hash)

    remote capabilities

  • url (String)

    a remote hub url

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/howitzer/capybara_helpers.rb', line 119

def cloud_driver(app, caps, url)
  http_client = ::Selenium::WebDriver::Remote::Http::Default.new
  http_client.read_timeout = Howitzer.cloud_http_idle_timeout
  http_client.open_timeout = Howitzer.cloud_http_idle_timeout

  options = {
    url: url,
    desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps),
    http_client: http_client,
    browser: :remote
  }
  driver = Capybara::Selenium::Driver.new(app, options)
  driver.browser.file_detector = remote_file_detector
  driver
end

#cloud_driver?Boolean

Returns true if current driver related with SauceLab, Testingbot or Browserstack cloud service

Returns:

  • (Boolean)

    true if current driver related with SauceLab, Testingbot or Browserstack cloud service



28
29
30
# File 'lib/howitzer/capybara_helpers.rb', line 28

def cloud_driver?
  CLOUD_BROWSERS.include?(Howitzer.driver.to_sym)
end

#cloud_resource_path(kind) ⇒ String

Note:

Currently SauceLabs is supported only

Returns path to cloud resources (logs, videos, etc.)

Returns:

  • (String)

    path to cloud resources (logs, videos, etc.)

Raises:

  • (ArgumentError)

    if unknown kind



139
140
141
142
143
144
145
# File 'lib/howitzer/capybara_helpers.rb', line 139

def cloud_resource_path(kind)
  case Howitzer.driver.to_sym
  when SAUCE then sauce_resource_path(kind)
  else
    '[NOT IMPLEMENTED]'
  end
end

#duration(time_in_numeric) ⇒ String

Returns formatted duration time

Parameters:

  • time_in_numeric (Integer)

    number of seconds

Returns:

  • (String)

    formatted duration time



68
69
70
71
72
73
74
75
# File 'lib/howitzer/capybara_helpers.rb', line 68

def duration(time_in_numeric)
  secs = time_in_numeric.to_i
  mins = secs / 60
  hours = mins / 60
  return "[#{hours}h #{mins % 60}m #{secs % 60}s]" if hours.positive?
  return "[#{mins}m #{secs % 60}s]" if mins.positive?
  return "[0m #{secs}s]" if secs >= 0
end

#ff_browser?Boolean

Returns whether or not current browser is FireFox.

Returns:

  • (Boolean)

    whether or not current browser is FireFox.

Raises:



45
46
47
# File 'lib/howitzer/capybara_helpers.rb', line 45

def ff_browser?
  browser? :ff, :firefox
end

#ie_browser?Boolean

Returns whether or not current browser is Internet Explorer.

Returns:

  • (Boolean)

    whether or not current browser is Internet Explorer.

Raises:



37
38
39
# File 'lib/howitzer/capybara_helpers.rb', line 37

def ie_browser?
  browser? :ie, :iexplore
end

#load_driver_gem!(driver, lib, gem) ⇒ Object

Tries to load appropriate driver gem

Parameters:

  • driver (String)

    a driver name

  • lib (String)

    what is required to load

  • gem (String)

    a gem name

Raises:

  • (LoadError)

    if the gem is missing in a bunder context



95
96
97
98
99
100
# File 'lib/howitzer/capybara_helpers.rb', line 95

def load_driver_gem!(driver, lib, gem)
  require lib
rescue LoadError
  raise LoadError,
        "`:#{driver}` driver is unable to load `#{lib}`, please add `gem '#{gem}'` to your Gemfile."
end

#required_cloud_capsHash

Returns selenium capabilities required for a cloud driver

Returns:

  • (Hash)

    selenium capabilities required for a cloud driver



104
105
106
107
108
109
110
111
# File 'lib/howitzer/capybara_helpers.rb', line 104

def required_cloud_caps
  {
    platform: Howitzer.cloud_platform,
    browserName: Howitzer.cloud_browser_name,
    version: Howitzer.cloud_browser_version,
    name: "#{prefix_name} #{Howitzer.cloud_browser_name}"
  }
end

#safari_browser?Boolean

Returns whether or not current browser is Safari.

Returns:

  • (Boolean)

    whether or not current browser is Safari.

Raises:



61
62
63
# File 'lib/howitzer/capybara_helpers.rb', line 61

def safari_browser?
  browser? :safari
end

#update_cloud_job_status(json_data = {}) ⇒ Object

Note:

SauceLabs is currently supported only

Updates a job status on the job cloud

Parameters:

  • json_data (Hash) (defaults to: {})

    for example, (passed: true)



81
82
83
84
85
86
87
# File 'lib/howitzer/capybara_helpers.rb', line 81

def update_cloud_job_status(json_data = {})
  case Howitzer.driver.to_sym
  when SAUCE then update_sauce_job_status(json_data)
  else
    '[NOT IMPLEMENTED]'
  end
end