summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-01-05 11:16:42 +0100
committerBrett Walker <bwalker@gitlab.com>2018-01-22 17:25:10 +0100
commitdb73ad93939bbf0b510a218d2e184d8050545224 (patch)
tree16aec04b12d05c8dcd9fe62e9d56bba26cc714bc
parentf344f7cecc926a998c2f498f943193337acef953 (diff)
downloadgitlab-ce-db73ad93939bbf0b510a218d2e184d8050545224.tar.gz
refactored Capybara configuration
and made similar to other Capybara configurations (including honoring the `CHROME_HEADLESS` environment variable
-rw-r--r--qa/qa.rb4
-rw-r--r--qa/qa/runtime/browser.rb56
-rw-r--r--qa/qa/specs/support/capybara_config.rb67
3 files changed, 73 insertions, 54 deletions
diff --git a/qa/qa.rb b/qa/qa.rb
index 4803432aeee..588af147731 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -138,6 +138,10 @@ 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 14b2a488760..c2bb98beb0a 100644
--- a/qa/qa/runtime/browser.rb
+++ b/qa/qa/runtime/browser.rb
@@ -7,6 +7,7 @@ module QA
module Runtime
class Browser
include QA::Scenario::Actable
+ extend QA::Specs::Support::CapybaraConfig
def initialize
self.class.configure!
@@ -34,60 +35,7 @@ module QA
end
def self.configure!
- 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 is false
- if 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
+ self.configure_capybara
end
class Session
diff --git a/qa/qa/specs/support/capybara_config.rb b/qa/qa/specs/support/capybara_config.rb
new file mode 100644
index 00000000000..186479e9cd9
--- /dev/null
+++ b/qa/qa/specs/support/capybara_config.rb
@@ -0,0 +1,67 @@
+module QA
+ module Specs
+ module Support
+ module CapybaraConfig
+ def configure_capybara
+ return if Capybara.drivers.include?(:chrome)
+
+ # Give CI some extra time
+ timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 10
+
+ 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