Class: Webdrivers::ChromeFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrivers/chrome_finder.rb

Class Method Summary collapse

Class Method Details

.linux_locationObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/webdrivers/chrome_finder.rb', line 50

def linux_location
  directories = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /opt/google/chrome]
  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)
    end
  end
end

.linux_version(location) ⇒ Object



66
67
68
# File 'lib/webdrivers/chrome_finder.rb', line 66

def linux_version(location)
  System.call("#{location} --product-version")&.strip
end

.mac_locationObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webdrivers/chrome_finder.rb', line 37

def mac_location
  directories = ['', File.expand_path('~')]
  files = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
           '/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)
    end
  end
end

.mac_version(location) ⇒ Object



70
71
72
# File 'lib/webdrivers/chrome_finder.rb', line 70

def mac_version(location)
  System.call("#{location} --version")&.strip
end

.versionObject

Raises:



6
7
8
9
10
11
12
13
14
# File 'lib/webdrivers/chrome_finder.rb', line 6

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

.win_locationObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/webdrivers/chrome_finder.rb', line 16

def win_location
  return Selenium::WebDriver::Chrome.path unless Selenium::WebDriver::Chrome.path.nil?

  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)
    end
  end
end

.win_version(location) ⇒ Object



62
63
64
# File 'lib/webdrivers/chrome_finder.rb', line 62

def win_version(location)
  System.call("powershell (Get-ItemProperty '#{location}').VersionInfo.ProductVersion")&.strip
end