diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-01-05 14:24:10 +0100 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-01-22 17:25:10 +0100 |
commit | e4a94fab6297b5f19bc4d15f55c5d38f41df35f2 (patch) | |
tree | 062578bca1bf24dea1e48714b47daa18a8f8b2fa | |
parent | 3513e6aae3a9f9463c4436c51e9914d481c4d4c3 (diff) | |
download | gitlab-ce-e4a94fab6297b5f19bc4d15f55c5d38f41df35f2.tar.gz |
move capybara config back to Browser and add Runtime::Env
-rw-r--r-- | qa/qa.rb | 4 | ||||
-rw-r--r-- | qa/qa/runtime/browser.rb | 56 | ||||
-rw-r--r-- | qa/qa/runtime/env.rb | 2 | ||||
-rw-r--r-- | qa/qa/specs/support/capybara_config.rb | 64 |
4 files changed, 55 insertions, 71 deletions
@@ -138,10 +138,6 @@ module QA module Specs autoload :Config, 'qa/specs/config' autoload :Runner, 'qa/specs/runner' - - module Support - autoload :CapybaraConfig, 'qa/specs/support/capybara_config' - end end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index c2bb98beb0a..7907c5bca43 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -7,7 +7,6 @@ module QA module Runtime class Browser include QA::Scenario::Actable - extend QA::Specs::Support::CapybaraConfig def initialize self.class.configure! @@ -35,7 +34,60 @@ module QA end def self.configure! - self.configure_capybara + return if Capybara.drivers.include?(:chrome) + + Capybara.register_driver :chrome do |app| + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + # This enables access to logs with `page.driver.manage.get_log(:browser)` + loggingPrefs: { + browser: "ALL", + client: "ALL", + driver: "ALL", + server: "ALL" + } + ) + + options = Selenium::WebDriver::Chrome::Options.new + options.add_argument("window-size=1240,1680") + + # 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 QA::Runtime::Env.chrome_headless? + 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 + + # Disable /dev/shm use in CI. See https://gitlab.com/gitlab-org/gitlab-ee/issues/4252 + options.add_argument("disable-dev-shm-usage") if QA::Runtime::Env.running_in_ci? + + Capybara::Selenium::Driver.new( + app, + browser: :chrome, + desired_capabilities: capabilities, + options: options + ) + end + + # Keep only the screenshots generated from the last failing test suite + Capybara::Screenshot.prune_strategy = :keep_last_run + + # 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 + + Capybara.configure do |config| + config.default_driver = :chrome + config.javascript_driver = :chrome + config.default_max_wait_time = 10 + # https://github.com/mattheworiordan/capybara-screenshot/issues/164 + config.save_path = 'tmp' + end end class Session diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index d5c28e9a7db..afc5bd0f6ef 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -4,7 +4,7 @@ module QA extend self def chrome_headless? - (ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0 + ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i end def running_in_ci? diff --git a/qa/qa/specs/support/capybara_config.rb b/qa/qa/specs/support/capybara_config.rb deleted file mode 100644 index 11b376036f7..00000000000 --- a/qa/qa/specs/support/capybara_config.rb +++ /dev/null @@ -1,64 +0,0 @@ -module QA - module Specs - module Support - module CapybaraConfig - def configure_capybara - return if Capybara.drivers.include?(:chrome) - - Capybara.register_driver :chrome do |app| - capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( - # This enables access to logs with `page.driver.manage.get_log(:browser)` - loggingPrefs: { - browser: "ALL", - client: "ALL", - driver: "ALL", - server: "ALL" - } - ) - - options = Selenium::WebDriver::Chrome::Options.new - options.add_argument("window-size=1240,1680") - - # 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 - - # 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'] - - Capybara::Selenium::Driver.new( - app, - browser: :chrome, - desired_capabilities: capabilities, - options: options - ) - end - - # Keep only the screenshots generated from the last failing test suite - Capybara::Screenshot.prune_strategy = :keep_last_run - - # 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 - - Capybara.configure do |config| - config.default_driver = :chrome - config.javascript_driver = :chrome - config.default_max_wait_time = 10 - # https://github.com/mattheworiordan/capybara-screenshot/issues/164 - config.save_path = 'tmp' - end - end - end - end - end -end |