capybara.rb 1.03 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.javascript_driver = :chrome
Capybara.register_driver :chrome do |app|
8 9 10
  extra_args = []
  extra_args << 'headless' unless ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i

11
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
12
    chromeOptions: {
13
      'args' => %w[no-sandbox disable-gpu --window-size=1240,1400] + extra_args
14
    }
15
  )
16 17 18

  Capybara::Selenium::Driver
    .new(app, browser: :chrome, desired_capabilities: capabilities)
19 20
end

21
Capybara.default_max_wait_time = timeout
22 23
Capybara.ignore_hidden_elements = false

24 25
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
26 27 28 29
# 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
30 31

Spinach.hooks.before_run do
32
  TestEnv.eager_load_driver_server
33
end