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
Instance Method Summary collapse
-
#chrome_browser? ⇒ Boolean
Whether or not current browser is Google Chrome.
-
#cloud_driver(app, caps, url) ⇒ Capybara::Selenium::Driver
Buids selenium driver for a cloud service.
-
#cloud_driver? ⇒ Boolean
True if current driver related with SauceLab, Testingbot or Browserstack cloud service.
-
#cloud_resource_path(kind) ⇒ String
Path to cloud resources (logs, videos, etc.).
-
#duration(time_in_numeric) ⇒ String
Formatted duration time.
-
#ff_browser? ⇒ Boolean
Whether or not current browser is FireFox.
-
#ie_browser? ⇒ Boolean
Whether or not current browser is Internet Explorer.
-
#load_driver_gem!(driver, lib, gem) ⇒ Object
Tries to load appropriate driver gem.
-
#required_cloud_caps ⇒ Hash
Selenium capabilities required for a cloud driver.
-
#safari_browser? ⇒ Boolean
Whether or not current browser is Safari.
-
#update_cloud_job_status(json_data = {}) ⇒ Object
Updates a job status on the job cloud.
Instance Method Details
#chrome_browser? ⇒ Boolean
Returns whether or not current browser is Google Chrome.
37 38 39 |
# File 'lib/howitzer/capybara_helpers.rb', line 37 def chrome_browser? browser? :chrome end |
#cloud_driver(app, caps, url) ⇒ Capybara::Selenium::Driver
Buids selenium driver for a cloud service
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/howitzer/capybara_helpers.rb', line 103 def cloud_driver(app, caps, url) http_client = ::Selenium::WebDriver::Remote::Http::Default.new http_client.timeout = Howitzer.cloud_http_idle_timeout = { url: url, desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps), http_client: http_client, browser: :remote } driver = Capybara::Selenium::Driver.new(app, ) 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.
12 13 14 |
# File 'lib/howitzer/capybara_helpers.rb', line 12 def cloud_driver? [:sauce, :testingbot, :browserstack].include?(Howitzer.driver.to_sym) end |
#cloud_resource_path(kind) ⇒ String
Currently SauceLabs is supported only
Returns path to cloud resources (logs, videos, etc.).
122 123 124 125 126 127 128 |
# File 'lib/howitzer/capybara_helpers.rb', line 122 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.
52 53 54 55 56 57 58 59 |
# File 'lib/howitzer/capybara_helpers.rb', line 52 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.
29 30 31 |
# File 'lib/howitzer/capybara_helpers.rb', line 29 def ff_browser? browser? :ff, :firefox end |
#ie_browser? ⇒ Boolean
Returns whether or not current browser is Internet Explorer.
21 22 23 |
# File 'lib/howitzer/capybara_helpers.rb', line 21 def ie_browser? browser? :ie, :iexplore end |
#load_driver_gem!(driver, lib, gem) ⇒ Object
Tries to load appropriate driver gem
79 80 81 82 83 84 |
# File 'lib/howitzer/capybara_helpers.rb', line 79 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_caps ⇒ Hash
Returns selenium capabilities required for a cloud driver.
88 89 90 91 92 93 94 95 |
# File 'lib/howitzer/capybara_helpers.rb', line 88 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.
45 46 47 |
# File 'lib/howitzer/capybara_helpers.rb', line 45 def safari_browser? browser? :safari end |
#update_cloud_job_status(json_data = {}) ⇒ Object
SauceLabs is currently supported only
Updates a job status on the job cloud
65 66 67 68 69 70 71 |
# File 'lib/howitzer/capybara_helpers.rb', line 65 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 |