<commit_before>HOWITZER_KNOWN_DRIVERS = [
    :selenium,
    :selenium_grid,
    :webkit,
    :poltergeist,
    :phantomjs,
    :sauce,
    :testingbot,
    :browserstack
].freeze
unless HOWITZER_KNOWN_DRIVERS.include?(settings.driver.to_s.to_sym)
  log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of #{HOWITZER_KNOWN_DRIVERS}"
end

Capybara.configure do |config|
  config.run_server = false
  config.app_host = ''
  config.asset_host = Howitzer.app_uri.origin
  config.default_selector = :css
  config.default_max_wait_time = settings.timeout_small
  config.ignore_hidden_elements = true
  config.match = :one
  config.exact = true
  config.visible_text_only = true
  config.default_driver = settings.driver.to_s.to_sym
  config.javascript_driver = settings.driver.to_s.to_sym
end

require 'howitzer/capybara_helpers'
include Howitzer::CapybaraHelpers

# :selenium driver

Capybara.register_driver :selenium do |app|
  params = { browser: settings.sel_browser.to_s.to_sym }
  if ff_browser?
    ff_profile = Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
      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
    end
    params[:profile] = ff_profile
  end
  Capybara::Selenium::Driver.new app, params
end

# :webkit driver

if settings.driver.to_sym == :webkit
  load_driver_gem!(:webkit, 'capybara-webkit', 'capybara-webkit')
end

# :poltergeist driver

if settings.driver.to_sym == :poltergeist
  load_driver_gem!(:poltergeist, 'capybara/poltergeist', 'poltergeist')

  Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(
        app,
        js_errors: !settings.pjs_ignore_js_errors,
        phantomjs_options: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}"]
    )
  end
end

# :phantomjs driver

Capybara.register_driver :phantomjs do |app|
  Capybara::Selenium::Driver.new(
      app, browser: :phantomjs,
      desired_capabilities: {
          javascript_enabled: !settings.pjs_ignore_js_errors
      },
      args: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}"]
  )
end

# :sauce driver

Capybara.register_driver :sauce do |app|
  caps = required_cloud_caps.merge(
      maxDuration: settings.cloud_max_duration,
      idleTimeout: settings.cloud_sauce_idle_timeout,
      recordScreenshots: settings.cloud_sauce_record_screenshot,
      videoUploadOnPass: settings.cloud_sauce_video_upload_on_pass
  )
  url = "http://#{settings.cloud_auth_login}:#{settings.cloud_auth_pass}@ondemand.saucelabs.com:80/wd/hub"
  cloud_driver(app, caps, url)
end

# :testingbot driver

Capybara.register_driver :testingbot do |app|
  caps = required_cloud_caps.merge(
      maxduration: settings.cloud_max_duration,
      idletimeout: settings.cloud_testingbot_idle_timeout,
      screenshot: settings.cloud_testingbot_screenshots
  )
  url = "http://#{settings.cloud_auth_login}:#{settings.cloud_auth_pass}@hub.testingbot.com/wd/hub"
  cloud_driver(app, caps, url)
end

# :browserstack driver

Capybara.register_driver :browserstack do |app|
  caps = required_cloud_caps.merge(
      project: settings.cloud_bstack_project,
      build: settings.cloud_bstack_build<commit_msg>Update capybara.rb<commit_after>HOWITZER_KNOWN_DRIVERS = [
  :selenium,
  :selenium_grid,
  :webkit,
  :poltergeist,
  :phantomjs,
  :sauce,
  :testingbot,
  :browserstack
].freeze
unless HOWITZER_KNOWN_DRIVERS.include?(settings.driver.to_s.to_sym)
  log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of #{HOWITZER_KNOWN_DRIVERS}"
end

Capybara.configure do |config|
  config.run_server = false
  config.app_host = ''
  config.asset_host = Howitzer.app_uri.origin
  config.default_selector = :css
  config.default_max_wait_time = settings.timeout_small
  config.ignore_hidden_elements = true
  config.match = :one
  config.exact = true
  config.visible_text_only = true
  config.default_driver = settings.driver.to_s.to_sym
  config.javascript_driver = settings.driver.to_s.to_sym
end

require 'howitzer/capybara_helpers'
include Howitzer::CapybaraHelpers

# :selenium driver

Capybara.register_driver :selenium do |app|
  params = { browser: settings.sel_browser.to_s.to_sym }
  if ff_browser?
    ff_profile = Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
      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
    end
    params[:profile] = ff_profile
  end
  Capybara::Selenium::Driver.new app, params
end

# :webkit driver

if settings.driver.to_sym == :webkit
  load_driver_gem!(:webkit, 'capybara-webkit', 'capybara-webkit')
end

# :poltergeist driver

if settings.driver.to_sym == :poltergeist
  load_driver_gem!(:poltergeist, 'capybara/poltergeist', 'poltergeist')

  Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(
      app,
      js_errors: !settings.pjs_ignore_js_errors,
      phantomjs_options: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}"]
    )
  end
end

# :phantomjs driver

Capybara.register_driver :phantomjs do |app|
  Capybara::Selenium::Driver.new(
    app, browser: :phantomjs,
         desired_capabilities: {
           javascript_enabled: !settings.pjs_ignore_js_errors
         },
         args: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}"]
  )
end

# :sauce driver

Capybara.register_driver :sauce do |app|
  caps = required_cloud_caps.merge(
    maxDuration: settings.cloud_max_duration,
    idleTimeout: settings.cloud_sauce_idle_timeout,
    recordScreenshots: settings.cloud_sauce_record_screenshot,
    videoUploadOnPass: settings.cloud_sauce_video_upload_on_pass
  )
  url = "http://#{settings.cloud_auth_login}:#{settings.cloud_auth_pass}@ondemand.saucelabs.com:80/wd/hub"
  cloud_driver(app, caps, url)
end

# :testingbot driver

Capybara.register_driver :testingbot do |app|
  caps = required_cloud_caps.merge(
    maxduration: settings.cloud_max_duration,
    idletimeout: settings.cloud_testingbot_idle_timeout,
    screenshot: settings.cloud_testingbot_screenshots
  )
  url = "http://#{settings.cloud_auth_login}:#{settings.cloud_auth_pass}@hub.testingbot.com/wd/hub"
  cloud_driver(app, caps, url)
end

# :browserstack driver

Capybara.register_driver :browserstack do |app|
  caps = required_cloud_caps.merge(
    project: settings.cloud_bstack_project,
    build: settings.cloud_bstack_build
{'fraction_non_alphanumeric': 0.11236442516268981, 'fraction_numerical': 0.0014461315979754157, 'mean_word_length': 4.664209664209665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7176049', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2423, 'n_words': 382}