]> source.dussan.org Git - redmine.git/commitdiff
Adds CAPYBARA_SERVER_HOST, CAPYBARA_SERVER_PORT, SELENIUM_REMOTE_URL and CAPYBARA_APP...
authorGo MAEDA <maeda@farend.jp>
Thu, 19 Nov 2020 05:11:59 +0000 (05:11 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 19 Nov 2020 05:11:59 +0000 (05:11 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@20428 e93f8b46-1217-0410-a6f0-8f06a7374b81

doc/RUNNING_TESTS
test/application_system_test_case.rb

index 983b791071bcc2b22d83bcb0deb1039561c51721..5dec68c23e5cd56e5b98eeec937fbff4668cbdbc 100644 (file)
@@ -72,6 +72,14 @@ https://sites.google.com/a/chromium.org/chromedriver/
 Capybara tests can be run with:
 `rails test:system`
 
+The following environment variables can be used to configure your system tests setup:
+`CAPYBARA_SERVER_HOST`: configure server to run on a custom IP which can be, for example, your remote Selenium IP or 0.0.0.0 to listen an all connections
+`CAPYBARA_SERVER_PORT`: configure server port
+`SELENIUM_REMOTE_URL`: remote Selenium URL
+`CAPYBARA_APP_HOST`: by default, the tests expect to have the application running on your localhost. Using this variable, you can set a custom URL
+
+One use case of these variables is to run the system tests on a remote Selenium/ChromeDriver (eg: Docker).
+
 Running RuboCop, a static code analyzer
 =======================================
 
index 7f6097ceedaa93323304001b45e256d8f1304c72..d5bbe7a4fc3115797cfb757930e369e13e0ebd1e 100644 (file)
@@ -22,22 +22,34 @@ require File.expand_path('../test_helper', __FILE__)
 class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
   DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
 
+  # Allow running Capybara default server on custom IP address and/or port
+  Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] if ENV['CAPYBARA_SERVER_HOST']
+  Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] if ENV['CAPYBARA_SERVER_PORT']
+
+  options = {}
+  # Allow running tests using a remote Selenium hub
+  options.merge!(url: ENV['SELENIUM_REMOTE_URL']) if ENV['SELENIUM_REMOTE_URL']
+  options.merge!(desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
+                  'chromeOptions' => {
+                    'prefs' => {
+                      'download.default_directory' => DOWNLOADS_PATH,
+                      'download.prompt_for_download' => false,
+                      'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
+                    }
+                  }
+                ))
+
   driven_by(
     :selenium, using: :chrome, screen_size: [1024, 900],
-    options: {
-      desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
-        'chromeOptions' => {
-          'prefs' => {
-            'download.default_directory' => DOWNLOADS_PATH,
-            'download.prompt_for_download' => false,
-            'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
-          }
-        }
-      )
-    }
+    options: options
   )
 
   setup do
+    # Allow defining a custom app host (useful when using a remote Selenium hub)
+    Capybara.configure do |config|
+      config.app_host = ENV['CAPYBARA_APP_HOST']
+    end if ENV['CAPYBARA_APP_HOST']
+
     clear_downloaded_files
     Setting.delete_all
     Setting.clear_cache