capybara.rb 1.57 KB
Newer Older
1
require 'capybara-screenshot/spinach'
2

3
# Give CI some extra time
4
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 30
5

6 7
Capybara.register_driver :chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
8 9 10 11 12 13
    # This enables access to logs with `page.driver.manage.get_log(:browser)`
    loggingPrefs: {
      browser: "ALL",
      client: "ALL",
      driver: "ALL",
      server: "ALL"
14
    }
15
  )
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument("window-size=1240,1400")

  # Chrome won't work properly in a Docker container in sandbox mode
  options.add_argument("no-sandbox")

  # Run headless by default unless CHROME_HEADLESS specified
  unless ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i
    options.add_argument("headless")

    # Chrome documentation says this flag is needed for now
    # https://developers.google.com/web/updates/2017/04/headless-chrome#cli
    options.add_argument("disable-gpu")
  end

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: capabilities,
    options: options
  )
38 39
end

40
Capybara.javascript_driver = :chrome
41
Capybara.default_max_wait_time = timeout
42 43
Capybara.ignore_hidden_elements = false

44 45
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
46 47 48 49
# From https://github.com/mattheworiordan/capybara-screenshot/issues/84#issuecomment-41219326
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
  driver.browser.save_screenshot(path)
end
50 51

Spinach.hooks.before_run do
52
  TestEnv.eager_load_driver_server
53
end