module Selenium::WebDriver::Platform
@api private
Public Instance Methods
assert_executable(path)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 143 def assert_executable(path) assert_file(path) return if File.executable? path raise Error::WebDriverError, "not executable: #{path.inspect}" end
assert_file(path)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 137 def assert_file(path) return if File.file? path raise Error::WebDriverError, "not a file: #{path.inspect}" end
bitsize()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 65 def bitsize @bitsize ||= if defined?(FFI::Platform::ADDRESS_SIZE) FFI::Platform::ADDRESS_SIZE elsif defined?(FFI) FFI.type_size(:pointer) == 4 ? 32 : 64 elsif jruby? Integer(ENV_JAVA['sun.arch.data.model']) else 1.size == 4 ? 32 : 64 end end
ci()
click to toggle source
# File 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?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 106 def cygwin? RUBY_PLATFORM.include?('cygwin') end
cygwin_path(path, **opts)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 118 def cygwin_path(path, **opts) flags = [] opts.each { |k, v| flags << "--#{k}" if v } `cygpath #{flags.join ' '} "#{path}"`.strip end
engine()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 33 def engine @engine ||= RUBY_ENGINE.to_sym end
exit_hook() { || ... }
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 151 def exit_hook pid = Process.pid at_exit { yield if Process.pid == pid } end
find_binary(*binary_names)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 157 def find_binary(*binary_names) paths = ENV['PATH'].split(File::PATH_SEPARATOR) if windows? binary_names.map! { |n| "#{n}.exe" } binary_names.dup.each { |n| binary_names << n.gsub('exe', 'bat') } end binary_names.each do |binary_name| paths.each do |path| full_path = File.join(path, binary_name) full_path = unix_path(full_path) if windows? exe = Dir.glob(full_path).find { |f| File.executable?(f) } return exe if exe end end nil end
find_in_program_files(*binary_names)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 177 def find_in_program_files(*binary_names) paths = [ ENV.fetch('PROGRAMFILES', '\\Program Files'), ENV.fetch('ProgramFiles(x86)', '\\Program Files (x86)'), ENV.fetch('ProgramW6432', '\\Program Files') ] paths.each do |root| binary_names.each do |name| exe = File.join(root, name) return exe if File.executable?(exe) end end nil end
home()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 29 def home @home ||= Dir.home end
interfaces()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 218 def interfaces interfaces = Socket.getaddrinfo('localhost', 8080).map { |e| e[3] } interfaces += ['0.0.0.0', Platform.ip] interfaces.compact.uniq end
ip()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 202 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
jruby?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 77 def jruby? engine == :jruby end
linux?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 93 def linux? os == :linux end
localhost()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 194 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
mac?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 89 def mac? os == :macosx end
make_writable(file)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 133 def make_writable(file) File.chmod 0o766, file end
null_device()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 110 def null_device File::NULL end
os()
click to toggle source
# File 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()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 81 def ruby_version RUBY_VERSION end
unix_path(path)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 125 def unix_path(path) path.tr(File::ALT_SEPARATOR, File::SEPARATOR) end
windows?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 85 def windows? os == :windows end
windows_path(path)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 129 def windows_path(path) path.tr(File::SEPARATOR, File::ALT_SEPARATOR) end
wrap_in_quotes_if_necessary(str)
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 114 def wrap_in_quotes_if_necessary(str) windows? && !cygwin? ? %("#{str}") : str end
wsl?()
click to toggle source
# File lib/selenium/webdriver/common/platform.rb, line 97 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