Module: Capybara::Settings

Extended by:
Settings
Included in:
Settings
Defined in:
lib/howitzer/capybara/settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_ff_profile_settingsObject


18
19
20
21
22
23
24
25
26
# File 'lib/howitzer/capybara/settings.rb', line 18

def self.base_ff_profile_settings
  profile = ::Selenium::WebDriver::Firefox::Profile.new
  profile['network.http.phishy-userpass-length'] = 255
  profile['browser.safebrowsing.malware.enabled'] = false
  profile['network.automatic-ntlm-auth.allow-non-fqdn'] = true
  profile['network.ntlm.send-lm-response'] = true
  profile['network.automatic-ntlm-auth.trusted-uris'] = settings.app_host
  profile
end

.define_driverObject

Defines driver based on specified test environment settings


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/howitzer/capybara/settings.rb', line 35

def define_driver
  case settings.driver.to_s.to_sym
    when :selenium
      define_selenium_driver
    when :selenium_dev
      define_selenium_dev_driver
    when :webkit
      define_webkit_driver
    when :poltergeist
      define_poltergeist_driver
    when :phantomjs
      define_phantomjs_driver
    when :sauce
      define_sauce_driver
    when :testingbot
      define_testingbot_driver
    when :browserstack
      define_browserstack_driver
    when :selenium_grid
      define_selenium_grid_driver
    else
      log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of [selenium, selenium_grid, selenium_dev, webkit, poltergeist, phantomjs, sauce, testingbot, browserstack]"
  end
end

Instance Method Details

#define_browserstack_driverObject


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/howitzer/capybara/settings.rb', line 210

def define_browserstack_driver
  task_name = rake_task_name
  caps_opts = {
      name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.bs_mobile ? settings.bs_m_browser : settings.bs_browser_name.upcase}",
      maxduration: settings.bs_max_duration.to_i,
      idletimeout: settings.bs_idle_timeout.to_i,
      project: settings.bs_project,
      build: settings.bs_build,
      resolution: settings.bs_resolution
  }

  if settings.bs_local
    caps_opts['browserstack.local'] = settings.bs_local
    caps_opts['browserstack.localIdentifier'] = settings.bs_local_ID
  end

  if settings.bs_mobile
    caps_opts[:browserName] = settings.bs_m_browser
    caps_opts[:platform] = settings.bs_m_platform
    caps_opts[:device] = settings.bs_m_device
  else
    caps_opts[:os] = settings.bs_os_name
    caps_opts[:os_version] = settings.bs_os_version
    caps_opts[:browser] = settings.bs_browser_name
    caps_opts[:browser_version] = settings.bs_browser_version
  end

  options = {
      url: settings.bs_url,
      desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps_opts),
      browser: :remote
  }
  Capybara.register_driver :browserstack do |app|
    driver = Capybara::Selenium::Driver.new(app, options)
    driver.browser.file_detector = lambda do |args|
      str = args.first.to_s
      str if File.exist?(str)
    end

    driver
  end
end

#rake_task_nameObject

Returns custom name for rake task

Returns:

  • string - Returns rake task name


321
322
323
# File 'lib/howitzer/capybara/settings.rb', line 321

def rake_task_name
  ENV['RAKE_TASK'].to_s.sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
end

#sauce_resource_path(name) ⇒ Object

Returns url of current Sauce Labs job

Parameters:

  • name - Your account name

Returns:

  • string - URL address of last running Sauce Labs job


264
265
266
267
268
# File 'lib/howitzer/capybara/settings.rb', line 264

def sauce_resource_path(name)
  host = "https://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
  path = "/rest/#{settings.sl_user}/jobs/#{session_id}/results/#{name}"
  "#{host}#{path}"
end

#session_idObject

Returns current session id


309
310
311
# File 'lib/howitzer/capybara/settings.rb', line 309

def session_id
  Capybara.current_session.driver.browser.instance_variable_get(:@bridge).session_id
end

#suite_nameObject

Returns custom name for Sauce Labs job

Returns:

  • string - Return name of current Sauce Labs job


294
295
296
297
298
299
300
301
302
# File 'lib/howitzer/capybara/settings.rb', line 294

def suite_name
  res = if ENV['RAKE_TASK']
          res = ENV['RAKE_TASK'].sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
          res.empty? ? 'ALL' : res
        else
          'CUSTOM'
        end
  "#{res} #{settings.sl_browser_name.upcase}"
end

#update_sauce_job_status(json_data = {}) ⇒ Object


279
280
281
282
283
284
# File 'lib/howitzer/capybara/settings.rb', line 279

def update_sauce_job_status(json_data = {})
  host = "http://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
  path = "/rest/v1/#{settings.sl_user}/jobs/#{session_id}"
  url = "#{host}#{path}"
  ::RestClient.put url, json_data.to_json, content_type: :json, accept: :json
end