From ce82acab234409623c297bb560ccf714f9652e24 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Thu, 7 May 2020 15:37:37 +0300 Subject: [PATCH] Load selenium/webdriver only if needed Currently, 'selenium-webdriver' gem is required to use system tests even if a non-selenium driver is used (such as Poltergeist, Cuprite, etc.). We should require it only if Selenium is used by a user --- actionpack/lib/action_dispatch/system_test_case.rb | 1 - actionpack/lib/action_dispatch/system_testing/driver.rb | 5 ++++- actionpack/test/dispatch/system_testing/driver_test.rb | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb index 5645544545..c757d2d5a1 100644 --- a/actionpack/lib/action_dispatch/system_test_case.rb +++ b/actionpack/lib/action_dispatch/system_test_case.rb @@ -4,7 +4,6 @@ gem "capybara", ">= 3.26" require "capybara/dsl" require "capybara/minitest" -require "selenium/webdriver" require "action_controller" require "action_dispatch/system_testing/driver" require "action_dispatch/system_testing/browser" diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb index 26bc950b4a..1c2595be68 100644 --- a/actionpack/lib/action_dispatch/system_testing/driver.rb +++ b/actionpack/lib/action_dispatch/system_testing/driver.rb @@ -10,7 +10,10 @@ module ActionDispatch @options = options[:options] || {} @capabilities = capabilities - @browser.preload unless name == :rack_test + if name == :selenium + require "selenium/webdriver" + @browser.preload + end end def use diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb index 3cf372aaf0..20d3732de5 100644 --- a/actionpack/test/dispatch/system_testing/driver_test.rb +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -148,9 +148,13 @@ class DriverTest < ActiveSupport::TestCase ::Selenium::WebDriver::Chrome::Service.driver_path = original_driver_path end - test "does not preload if :rack_test is set" do + test "does not preload if used driver is not :selenium" do assert_not_called_on_instance_of(ActionDispatch::SystemTesting::Browser, :preload) do ActionDispatch::SystemTesting::Driver.new(:rack_test, using: :chrome) end + + assert_not_called_on_instance_of(ActionDispatch::SystemTesting::Browser, :preload) do + ActionDispatch::SystemTesting::Driver.new(:poltergeist) + end end end