Skip to content

Commit be272a8

Browse files
Fix system tests with Chrome cached by Selenium
Follow-up to rails#49908. When Selenium resolves the driver path to a copy of Chrome that it has downloaded / cached, it mutates the `Selenium::WebDriver::Chrome::Options` object it receives, and relies on those changes later when the options are used. If `Selenium::WebDriver::Chrome::Service.driver_path` is set but a different options object is used, Selenium will raise "cannot find Chrome binary". Therefore, this commit ensures that the options object passed to `Selenium::WebDriver::DriverFinder.path` is the same options object used by the driver later.
1 parent fb09e7f commit be272a8

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

actionpack/lib/action_dispatch/system_testing/browser.rb

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionDispatch
44
module SystemTesting
55
class Browser # :nodoc:
6-
attr_reader :name, :options
6+
attr_reader :name
77

88
def initialize(name)
99
@name = name
@@ -21,9 +21,18 @@ def type
2121
end
2222
end
2323

24+
def options
25+
@options ||=
26+
case type
27+
when :chrome
28+
::Selenium::WebDriver::Chrome::Options.new
29+
when :firefox
30+
::Selenium::WebDriver::Firefox::Options.new
31+
end
32+
end
33+
2434
def configure
25-
initialize_options
26-
yield options if block_given? && options
35+
yield options if block_given?
2736
end
2837

2938
# driver_path is lazily initialized by default. Eagerly set it to
@@ -38,16 +47,6 @@ def preload
3847
end
3948

4049
private
41-
def initialize_options
42-
@options ||=
43-
case type
44-
when :chrome
45-
::Selenium::WebDriver::Chrome::Options.new
46-
when :firefox
47-
::Selenium::WebDriver::Firefox::Options.new
48-
end
49-
end
50-
5150
def set_default_options
5251
case name
5352
when :headless_chrome
@@ -71,10 +70,7 @@ def set_headless_firefox_browser_options
7170
end
7271

7372
def resolve_driver_path(namespace)
74-
namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(
75-
options || namespace::Options.new,
76-
namespace::Service
77-
)
73+
namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(options, namespace::Service)
7874
end
7975
end
8076
end

actionpack/test/dispatch/system_testing/driver_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DriverTest < ActiveSupport::TestCase
1414
driver = ActionDispatch::SystemTesting::Driver.new(:selenium, using: :chrome, screen_size: [1400, 1400], options: { url: "http://example.com/wd/hub" })
1515
assert_equal :selenium, driver.instance_variable_get(:@driver_type)
1616
assert_equal :chrome, driver.instance_variable_get(:@browser).name
17-
assert_nil driver.instance_variable_get(:@browser).options
17+
assert_instance_of Selenium::WebDriver::Chrome::Options, driver.instance_variable_get(:@browser).options
1818
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
1919
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
2020
end

0 commit comments

Comments
 (0)