Skip to content

Commit

Permalink
Merge pull request #50296 from jonathanhefner/follow-up-49908-fix-cac…
Browse files Browse the repository at this point in the history
…hed-chrome

Fix system tests with Chrome cached by Selenium
  • Loading branch information
jonathanhefner committed Dec 7, 2023
2 parents fb09e7f + be272a8 commit 049c951
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions actionpack/lib/action_dispatch/system_testing/browser.rb
Expand Up @@ -3,7 +3,7 @@
module ActionDispatch
module SystemTesting
class Browser # :nodoc:
attr_reader :name, :options
attr_reader :name

def initialize(name)
@name = name
Expand All @@ -21,9 +21,18 @@ def type
end
end

def options
@options ||=
case type
when :chrome
::Selenium::WebDriver::Chrome::Options.new
when :firefox
::Selenium::WebDriver::Firefox::Options.new
end
end

def configure
initialize_options
yield options if block_given? && options
yield options if block_given?
end

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

private
def initialize_options
@options ||=
case type
when :chrome
::Selenium::WebDriver::Chrome::Options.new
when :firefox
::Selenium::WebDriver::Firefox::Options.new
end
end

def set_default_options
case name
when :headless_chrome
Expand All @@ -71,10 +70,7 @@ def set_headless_firefox_browser_options
end

def resolve_driver_path(namespace)
namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(
options || namespace::Options.new,
namespace::Service
)
namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(options, namespace::Service)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/dispatch/system_testing/driver_test.rb
Expand Up @@ -14,7 +14,7 @@ class DriverTest < ActiveSupport::TestCase
driver = ActionDispatch::SystemTesting::Driver.new(:selenium, using: :chrome, screen_size: [1400, 1400], options: { url: "http://example.com/wd/hub" })
assert_equal :selenium, driver.instance_variable_get(:@driver_type)
assert_equal :chrome, driver.instance_variable_get(:@browser).name
assert_nil driver.instance_variable_get(:@browser).options
assert_instance_of Selenium::WebDriver::Chrome::Options, driver.instance_variable_get(:@browser).options
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
end
Expand Down

0 comments on commit 049c951

Please sign in to comment.