0001-Adds-CAPYBARA_SERVER_HOST-CAPYBARA_SERVER_PORT-SELEN.patch

Marius BALTEANU, 2020-11-17 20:26

Download (3.43 KB)

View differences:

doc/RUNNING_TESTS
72 72
Capybara tests can be run with:
73 73
`rails test:system`
74 74

  
75
The following environment variables can be used to configure your system tests setup:
76
`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
77
`CAPYBARA_SERVER_PORT`: configure server port
78
`SELENIUM_REMOTE_URL`: remote Selenium URL
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

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

  
75 83
Running RuboCop, a static code analyzer
76 84
=======================================
77 85

  
test/application_system_test_case.rb
22 22
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
23 23
  DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
24 24

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

  
29
  options = {}
30
  # Allow running tests using a remote Selenium hub
31
  options.merge!(url: ENV['SELENIUM_REMOTE_URL']) if ENV['SELENIUM_REMOTE_URL']
32
  options.merge!(desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
33
                  'chromeOptions' => {
34
                    'prefs' => {
35
                      'download.default_directory' => DOWNLOADS_PATH,
36
                      'download.prompt_for_download' => false,
37
                      'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
38
                    }
39
                  }
40
                ))
41

  
25 42
  driven_by(
26 43
    :selenium, using: :chrome, screen_size: [1024, 900],
27
    options: {
28
      desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
29
        'chromeOptions' => {
30
          'prefs' => {
31
            'download.default_directory' => DOWNLOADS_PATH,
32
            'download.prompt_for_download' => false,
33
            'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
34
          }
35
        }
36
      )
37
    }
44
    options: options
38 45
  )
39 46

  
40 47
  setup do
48
    # Allow defining a custom app host (useful when using a remote Selenium hub)
49
    Capybara.configure do |config|
50
      config.app_host = ENV['CAPYBARA_APP_HOST']
51
    end if ENV['CAPYBARA_APP_HOST']
52

  
41 53
    clear_downloaded_files
42 54
    Setting.delete_all
43 55
    Setting.clear_cache
44
-