123456789_123456789_123456789_123456789_123456789_

Module: Selenium::WebDriver::Platform Private

Do not use. This module is for internal use only.
Relationships & Source Files
Defined in: rb/lib/selenium/webdriver/common/platform.rb

Class Attribute Summary

Class Method Summary

Class Attribute Details

.cygwin?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 102

def cygwin?
  RUBY_PLATFORM.include?('cygwin')
end

.jruby?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 65

def jruby?
  engine == :jruby
end

.linux?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 85

def linux?
  os == :linux
end

.mac?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 81

def mac?
  os == :macosx
end

.truffleruby?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 69

def truffleruby?
  engine == :truffleruby
end

.unix?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 89

def unix?
  os == :unix
end

.windows?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 77

def windows?
  os == :windows
end

.wsl?Boolean (readonly, mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 93

def wsl?
  return false unless linux?

  File.read('/proc/version').downcase.include?('microsoft')
rescue Errno::EACCES
  # the file cannot be accessed on Linux on DeX
  false
end

Class Method Details

.assert_executable(path) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 141

def assert_executable(path)
  assert_file(path)

  return if File.executable? path

  raise Error::WebDriverError, "not executable: #{path.inspect}"
end

.assert_file(path) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 135

def assert_file(path)
  return if File.file? path

  raise Error::WebDriverError, "not a file: #{path.inspect}"
end

.ci (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 53

def ci
  if ENV['TRAVIS']
    :travis
  elsif ENV['JENKINS']
    :jenkins
  elsif ENV['APPVEYOR']
    :appveyor
  elsif ENV['GITHUB_ACTIONS']
    :github
  end
end

.cygwin_path(path, only_cygwin: false, **opts) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 114

def cygwin_path(path, only_cygwin: false, **opts)
  return path if only_cygwin && !cygwin?

  flags = []
  opts.each { |k, v| flags << "--#{k}" if v }

  `cygpath #{flags.join ' '} "#{path}"`.strip
end

.engine (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 33

def engine
  @engine ||= RUBY_ENGINE.to_sym
end

.exit_hook (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 149

def exit_hook
  pid = Process.pid

  at_exit { yield if Process.pid == pid }
end

.home (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 29

def home
  @home ||= Dir.home
end

.interfaces (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 179

def interfaces
  interfaces = Socket.getaddrinfo('localhost', 8080).map { |e| e[3] }
  interfaces += ['0.0.0.0', Platform.ip]

  interfaces.compact.uniq
end

.ip (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 163

def ip
  orig = Socket.do_not_reverse_lookup
  Socket.do_not_reverse_lookup = true

  begin
    UDPSocket.open do |s|
      s.connect '8.8.8.8', 53
      return s.addr.last
    end
  ensure
    Socket.do_not_reverse_lookup = orig
  end
rescue Errno::ENETUNREACH, Errno::EHOSTUNREACH
  # no external ip
end

.localhost (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 155

def localhost
  info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM

  return info[0][3] unless info.empty?

  raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
end

.make_writable(file) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 131

def make_writable(file)
  File.chmod 0o766, file
end

.null_device (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 106

def null_device
  File::NULL
end

.os (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 37

def os
  host_os = RbConfig::CONFIG['host_os']
  @os ||= case host_os
          when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
            :windows
          when /darwin|mac os/
            :macosx
          when /linux/
            :linux
          when /solaris|bsd/
            :unix
          else
            raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
          end
end

.ruby_version (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 73

def ruby_version
  RUBY_VERSION
end

.unix_path(path) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 123

def unix_path(path)
  path.tr(File::ALT_SEPARATOR, File::SEPARATOR)
end

.windows_path(path) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 127

def windows_path(path)
  path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
end

.wrap_in_quotes_if_necessary(str) (mod_func)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/platform.rb', line 110

def wrap_in_quotes_if_necessary(str)
  windows? && !cygwin? ? %("#{str}") : str
end