Skip to content

Commit d364cfb

Browse files
authored
Merge pull request rails#42672 from jonathanhefner/system-testing-browser-iff-selenium
Configure browser only when using Selenium
2 parents 8db2310 + 0009699 commit d364cfb

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

actionpack/lib/action_dispatch/system_testing/driver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module SystemTesting
55
class Driver # :nodoc:
66
def initialize(name, **options, &capabilities)
77
@name = name
8-
@browser = Browser.new(options[:using])
98
@screen_size = options[:screen_size]
109
@options = options[:options] || {}
1110
@capabilities = capabilities
1211

1312
if name == :selenium
1413
require "selenium/webdriver"
14+
@browser = Browser.new(options[:using])
1515
@browser.preload
1616
end
1717
end
@@ -28,7 +28,7 @@ def registerable?
2828
end
2929

3030
def register
31-
@browser.configure(&@capabilities)
31+
@browser&.configure(&@capabilities)
3232

3333
Capybara.register_driver @name do |app|
3434
case @name

actionpack/test/dispatch/system_testing/driver_test.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,11 @@ class DriverTest < ActiveSupport::TestCase
148148
::Selenium::WebDriver::Chrome::Service.driver_path = original_driver_path
149149
end
150150

151-
test "does not preload if used driver is not :selenium" do
152-
assert_not_called_on_instance_of(ActionDispatch::SystemTesting::Browser, :preload) do
153-
ActionDispatch::SystemTesting::Driver.new(:rack_test, using: :chrome)
154-
end
151+
test "does not configure browser if driver is not :selenium" do
152+
# sanity check
153+
assert ActionDispatch::SystemTesting::Driver.new(:selenium).instance_variable_get(:@browser)
155154

156-
assert_not_called_on_instance_of(ActionDispatch::SystemTesting::Browser, :preload) do
157-
ActionDispatch::SystemTesting::Driver.new(:poltergeist)
158-
end
155+
assert_nil ActionDispatch::SystemTesting::Driver.new(:rack_test).instance_variable_get(:@browser)
156+
assert_nil ActionDispatch::SystemTesting::Driver.new(:poltergeist).instance_variable_get(:@browser)
159157
end
160158
end

0 commit comments

Comments
 (0)