Class: Webdrivers::ChromeFinder
- Inherits:
-
Object
- Object
- Webdrivers::ChromeFinder
- Defined in:
- lib/webdrivers/chrome_finder.rb
Class Method Summary collapse
- .linux_location ⇒ Object
- .linux_version(location) ⇒ Object
- .mac_location ⇒ Object
- .mac_version(location) ⇒ Object
- .version ⇒ Object
- .win_location ⇒ Object
- .win_version(location) ⇒ Object
Class Method Details
.linux_location ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/webdrivers/chrome_finder.rb', line 44 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 option if File.exist?(option) end end end |
.linux_version(location) ⇒ Object
60 61 62 |
# File 'lib/webdrivers/chrome_finder.rb', line 60 def linux_version(location) System.call("#{Shellwords.escape location} --product-version")&.strip end |
.mac_location ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/webdrivers/chrome_finder.rb', line 31 def mac_location directories = ['', File.('~')] 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 option if File.exist?(option) end end end |
.mac_version(location) ⇒ Object
64 65 66 |
# File 'lib/webdrivers/chrome_finder.rb', line 64 def mac_version(location) System.call("#{Shellwords.escape location} --version")&.strip end |
.version ⇒ Object
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_location ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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}" return option if File.exist?(option) end end end |