2016-12-07 22:45:34 -05:00
|
|
|
require 'capybara-screenshot/spinach'
|
2015-04-25 14:20:15 -04:00
|
|
|
|
2015-04-25 14:22:21 -04:00
|
|
|
# Give CI some extra time
|
2017-03-31 03:55:46 -04:00
|
|
|
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 30
|
2015-04-25 14:22:21 -04:00
|
|
|
|
2017-06-17 01:07:14 -04:00
|
|
|
Capybara.register_driver :chrome do |app|
|
|
|
|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
2017-11-29 00:47:38 -05:00
|
|
|
# This enables access to logs with `page.driver.manage.get_log(:browser)`
|
|
|
|
loggingPrefs: {
|
|
|
|
browser: "ALL",
|
|
|
|
client: "ALL",
|
|
|
|
driver: "ALL",
|
|
|
|
server: "ALL"
|
2017-06-17 01:07:14 -04:00
|
|
|
}
|
2016-11-28 03:50:08 -05:00
|
|
|
)
|
2017-06-17 01:07:14 -04:00
|
|
|
|
2017-11-29 00:47:38 -05:00
|
|
|
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
|
|
|
|
|
2017-12-22 02:40:56 -05:00
|
|
|
# Disable /dev/shm use in CI. See https://gitlab.com/gitlab-org/gitlab-ee/issues/4252
|
|
|
|
options.add_argument("disable-dev-shm-usage") if ENV['CI'] || ENV['CI_SERVER']
|
|
|
|
|
2017-11-29 00:47:38 -05:00
|
|
|
Capybara::Selenium::Driver.new(
|
|
|
|
app,
|
|
|
|
browser: :chrome,
|
|
|
|
desired_capabilities: capabilities,
|
|
|
|
options: options
|
|
|
|
)
|
2015-04-25 14:20:15 -04:00
|
|
|
end
|
|
|
|
|
2017-11-29 00:47:38 -05:00
|
|
|
Capybara.javascript_driver = :chrome
|
2016-03-15 14:03:17 -04:00
|
|
|
Capybara.default_max_wait_time = timeout
|
2015-04-25 14:20:15 -04:00
|
|
|
Capybara.ignore_hidden_elements = false
|
|
|
|
|
2016-12-07 22:45:34 -05:00
|
|
|
# Keep only the screenshots generated from the last failing test suite
|
|
|
|
Capybara::Screenshot.prune_strategy = :keep_last_run
|
2017-06-17 01:35:46 -04:00
|
|
|
# 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
|
2016-01-28 20:45:03 -05:00
|
|
|
|
|
|
|
Spinach.hooks.before_run do
|
2017-03-30 10:30:05 -04:00
|
|
|
TestEnv.eager_load_driver_server
|
2016-01-28 20:45:03 -05:00
|
|
|
end
|