lib/webdrivers/chrome_finder.rb in webdrivers-4.0.1 vs lib/webdrivers/chrome_finder.rb in webdrivers-4.1.0
- old
+ new
@@ -1,37 +1,49 @@
# frozen_string_literal: true
module Webdrivers
+ #
+ # @api private
+ #
class ChromeFinder
class << self
def version
- location = Selenium::WebDriver::Chrome.path || send("#{System.platform}_location")
version = send("#{System.platform}_version", location)
raise VersionError, 'Failed to find Chrome binary or its version.' if version.nil? || version.empty?
Webdrivers.logger.debug "Browser version: #{version}"
version[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
end
- def win_location
- return Selenium::WebDriver::Chrome.path unless Selenium::WebDriver::Chrome.path.nil?
+ def location
+ user_defined_location || send("#{System.platform}_location")
+ end
+ private
+
+ def user_defined_location
+ if Selenium::WebDriver::Chrome.path
+ Webdrivers.logger.debug "Selenium::WebDriver::Chrome.path: #{Selenium::WebDriver::Chrome.path}"
+ return Selenium::WebDriver::Chrome.path
+ end
+
+ return if ENV['WD_CHROME_PATH'].nil?
+
+ Webdrivers.logger.debug "WD_CHROME_PATH: #{ENV['WD_CHROME_PATH']}"
+ ENV['WD_CHROME_PATH']
+ end
+
+ def win_location
envs = %w[LOCALAPPDATA PROGRAMFILES PROGRAMFILES(X86)]
directories = ['\\Google\\Chrome\\Application', '\\Chromium\\Application']
file = 'chrome.exe'
directories.each do |dir|
envs.each do |root|
option = "#{ENV[root]}\\#{dir}\\#{file}"
- next unless File.exist?(option)
-
- # Fix for JRuby on Windows - #41 and #130.
- # Escape space and parenthesis with backticks.
- option = option.gsub(/([\s()])/, '`\1') if RUBY_PLATFORM == 'java'
-
- return System.escape_path(option)
+ return option if File.exist?(option)
end
end
end
def mac_location
@@ -40,11 +52,11 @@
'/Applications/Chromium.app/Contents/MacOS/Chromium']
directories.each do |dir|
files.each do |file|
option = "#{dir}/#{file}"
- return System.escape_path(option) if File.exist?(option)
+ return option if File.exist?(option)
end
end
end
def linux_location
@@ -52,24 +64,24 @@
files = %w[google-chrome chrome chromium chromium-browser]
directories.each do |dir|
files.each do |file|
option = "#{dir}/#{file}"
- return System.escape_path(option) if File.exist?(option)
+ return option if File.exist?(option)
end
end
end
def win_version(location)
System.call("powershell (Get-ItemProperty '#{location}').VersionInfo.ProductVersion")&.strip
end
def linux_version(location)
- System.call("#{location} --product-version")&.strip
+ System.call(location, '--product-version')&.strip
end
def mac_version(location)
- System.call("#{location} --version")&.strip
+ System.call(location, '--version')&.strip
end
end
end
end