18 |
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
19 |
|
20 |
20 |
require_relative 'test_helper'
|
21 |
|
require 'webdrivers/chromedriver'
|
22 |
21 |
|
23 |
22 |
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
24 |
23 |
DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
|
25 |
|
GOOGLE_CHROME_OPTS_ARGS = []
|
26 |
24 |
|
27 |
25 |
# Allow running Capybara default server on custom IP address and/or port
|
28 |
26 |
Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] if ENV['CAPYBARA_SERVER_HOST']
|
29 |
27 |
Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] if ENV['CAPYBARA_SERVER_PORT']
|
30 |
28 |
|
31 |
29 |
# Allow defining Google Chrome options arguments based on a comma-delimited string environment variable
|
32 |
|
GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") if ENV['GOOGLE_CHROME_OPTS_ARGS']
|
|
30 |
GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].present? ? ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") : []
|
33 |
31 |
|
34 |
32 |
options = {}
|
|
33 |
if ENV['SELENIUM_REMOTE_URL']
|
|
34 |
options[:url] = ENV['SELENIUM_REMOTE_URL']
|
|
35 |
options[:browser] = :remote
|
|
36 |
else
|
|
37 |
require 'webdrivers/chromedriver'
|
|
38 |
end
|
|
39 |
|
35 |
40 |
# Allow running tests using a remote Selenium hub
|
36 |
|
options[:url] = ENV['SELENIUM_REMOTE_URL'] if ENV['SELENIUM_REMOTE_URL']
|
37 |
|
options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome(
|
38 |
|
'goog:chromeOptions' => {
|
39 |
|
'args' => GOOGLE_CHROME_OPTS_ARGS,
|
40 |
|
'prefs' => {
|
41 |
|
'download.default_directory' => DOWNLOADS_PATH.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR),
|
42 |
|
'download.prompt_for_download' => false,
|
43 |
|
'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
|
44 |
|
}
|
45 |
|
}
|
46 |
|
)
|
47 |
|
|
48 |
|
driven_by(
|
49 |
|
:selenium, using: :chrome, screen_size: [1024, 900],
|
50 |
|
options: options
|
51 |
|
)
|
|
41 |
driven_by :selenium, using: :chrome, screen_size: [1024, 900], options: options do |driver_option|
|
|
42 |
GOOGLE_CHROME_OPTS_ARGS.each do |arg|
|
|
43 |
driver_option.add_argument arg
|
|
44 |
end
|
|
45 |
driver_option.add_preference 'download.default_directory', DOWNLOADS_PATH.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
|
|
46 |
driver_option.add_preference 'download.prompt_for_download', false
|
|
47 |
driver_option.add_preference 'plugins.plugins_disabled', ["Chrome PDF Viewer"]
|
|
48 |
end
|
52 |
49 |
|
53 |
50 |
setup do
|
|
51 |
Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}"
|
54 |
52 |
# Allow defining a custom app host (useful when using a remote Selenium hub)
|
55 |
53 |
if ENV['CAPYBARA_APP_HOST']
|
56 |
54 |
Capybara.configure do |config|
|