Project

General

Profile

Patch #34269 » 0002-Adds-GOOGLE_CHROME_OPTS_ARGS-environment-variable-to.patch

Marius BĂLTEANU, 2021-01-09 11:42

View differences:

doc/RUNNING_TESTS
77 77
`CAPYBARA_SERVER_PORT`: configure server port
78 78
`SELENIUM_REMOTE_URL`: remote Selenium URL
79 79
`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
80
`GOOGLE_CHROME_OPTS_ARGS`: configure Google Chrome Options arguments as a comma-delimited string. For example, it can be used to run the tests in headless mode:
81
    `export GOOGLE_CHROME_OPTS_ARGS="headless,disable-gpu,no-sandbox,disable-dev-shm-usage"`
80 82

  
81 83
One use case of these variables is to run the system tests on a remote Selenium/ChromeDriver (eg: Docker).
82 84

  
test/application_system_test_case.rb
21 21

  
22 22
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
23 23
  DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
24
  GOOGLE_CHROME_OPTS_ARGS = []
24 25

  
25 26
  # Allow running Capybara default server on custom IP address and/or port
26 27
  Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] if ENV['CAPYBARA_SERVER_HOST']
27 28
  Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] if ENV['CAPYBARA_SERVER_PORT']
28 29

  
30
  # Allow defining Google Chrome options arguments based on a comma-delimited string environment variable
31
  GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") if ENV['GOOGLE_CHROME_OPTS_ARGS']
32

  
29 33
  options = {}
30 34
  # Allow running tests using a remote Selenium hub
31 35
  options[:url] = ENV['SELENIUM_REMOTE_URL'] if ENV['SELENIUM_REMOTE_URL']
32 36
  options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome(
33 37
                  'goog:chromeOptions' => {
38
                    'args' => GOOGLE_CHROME_OPTS_ARGS,
34 39
                    'prefs' => {
35 40
                      'download.default_directory' => DOWNLOADS_PATH,
36 41
                      'download.prompt_for_download' => false,
(2-2/2)