diff --git a/rb/lib/selenium/webdriver/common/driver_finder.rb b/rb/lib/selenium/webdriver/common/driver_finder.rb index 654ed535323c9..b70e57b26ef4c 100644 --- a/rb/lib/selenium/webdriver/common/driver_finder.rb +++ b/rb/lib/selenium/webdriver/common/driver_finder.rb @@ -49,7 +49,7 @@ def browser_path? def paths @paths ||= begin - path = @service.executable_path || resolve_class_path + path = @service.executable_path || env_path || class_path path ? paths_from_service(path) : paths_from_manager rescue StandardError => e WebDriver.logger.error("Exception occurred: #{e.message}") @@ -58,7 +58,11 @@ def paths end end - def resolve_class_path + def env_path + ENV.fetch(@service.class::DRIVER_PATH_ENV_KEY, nil) + end + + def class_path path = @service.class.driver_path path.is_a?(Proc) ? path.call : path end diff --git a/rb/lib/selenium/webdriver/common/service.rb b/rb/lib/selenium/webdriver/common/service.rb index f588205366160..f948ac7268c63 100644 --- a/rb/lib/selenium/webdriver/common/service.rb +++ b/rb/lib/selenium/webdriver/common/service.rb @@ -69,7 +69,6 @@ def driver_path=(path) def initialize(path: nil, port: nil, log: nil, args: nil) port ||= self.class::DEFAULT_PORT args ||= [] - path ||= env_path @executable_path = path @host = Platform.localhost @@ -88,7 +87,7 @@ def initialize(path: nil, port: nil, log: nil, args: nil) end def launch - @executable_path ||= env_path || DriverFinder.new(nil, self).driver_path + @executable_path ||= DriverFinder.new(nil, self).driver_path ServiceManager.new(self).tap(&:start) end @@ -96,10 +95,6 @@ def shutdown_supported self.class::SHUTDOWN_SUPPORTED end - def env_path - ENV.fetch(self.class::DRIVER_PATH_ENV_KEY, nil) - end - private def warn_driver_log_override diff --git a/rb/lib/selenium/webdriver/safari.rb b/rb/lib/selenium/webdriver/safari.rb index 37a9e536091d7..855a8903b5be3 100644 --- a/rb/lib/selenium/webdriver/safari.rb +++ b/rb/lib/selenium/webdriver/safari.rb @@ -33,7 +33,6 @@ def technology_preview end def technology_preview! - Service.driver_path = technology_preview @use_technology_preview = true end @@ -47,11 +46,7 @@ def path=(path) end def path - @path ||= '/Applications/Safari.app/Contents/MacOS/Safari' - return @path if File.file?(@path) && File.executable?(@path) - raise Error::WebDriverError, 'Safari is only supported on Mac' unless Platform.os.mac? - - raise Error::WebDriverError, 'Unable to find Safari' + @path ||= nil end end end # Safari diff --git a/rb/lib/selenium/webdriver/safari/options.rb b/rb/lib/selenium/webdriver/safari/options.rb index 352132648207f..4bb6492ad9864 100644 --- a/rb/lib/selenium/webdriver/safari/options.rb +++ b/rb/lib/selenium/webdriver/safari/options.rb @@ -26,7 +26,8 @@ class Options < WebDriver::Options # @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari CAPABILITIES = {automatic_inspection: 'safari:automaticInspection', automatic_profiling: 'safari:automaticProfiling'}.freeze - BROWSER = Selenium::WebDriver::Safari.technology_preview? ? 'Safari Technology Preview' : 'safari' + BROWSER = 'safari' + TECHNOLOGY_PREVIEW = 'Safari Technology Preview' def add_option(name, value = nil) key = name.is_a?(Hash) ? name.keys.first : name @@ -35,9 +36,8 @@ def add_option(name, value = nil) super end - def as_json(*) - @options[:browser_name] = Safari.technology_preview? ? 'Safari Technology Preview' : 'safari' - super + def browser_name + @options[:browser_name] = Safari.technology_preview? ? TECHNOLOGY_PREVIEW : BROWSER end end # Options end # Safari diff --git a/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs b/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs index aaef2f6131f6c..ef87fee7bddc6 100644 --- a/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs +++ b/rb/sig/lib/selenium/webdriver/common/driver_finder.rbs @@ -20,7 +20,9 @@ module Selenium def paths: -> untyped - def resolve_class_path: -> String? + def class_path: -> String? + + def env_path: -> String? def paths_from_service: (String path) -> Hash[Symbol, String] diff --git a/rb/sig/lib/selenium/webdriver/safari/options.rbs b/rb/sig/lib/selenium/webdriver/safari/options.rbs index 6ae1af64afe5f..c67d12f04e679 100644 --- a/rb/sig/lib/selenium/webdriver/safari/options.rbs +++ b/rb/sig/lib/selenium/webdriver/safari/options.rbs @@ -6,11 +6,13 @@ module Selenium CAPABILITIES: Hash[Symbol, String] - BROWSER: untyped + BROWSER: String + + TECHNOLOGY_PREVIEW: String def add_option: (untyped name, ?untyped? value) -> untyped - def as_json: (*untyped) -> untyped + def browser_name: () -> String end end end