Module: Selenium::WebDriver::Platform Private

Defined in:
build/rb/lib/selenium/webdriver/common/platform.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.assert_executable(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



126
127
128
129
130
131
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 126

def assert_executable(path)
  assert_file(path)

  return if File.executable? path
  raise Error::WebDriverError, "not executable: #{path.inspect}"
end

.assert_file(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



121
122
123
124
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 121

def assert_file(path)
  return if File.file? path
  raise Error::WebDriverError, "not a file: #{path.inspect}"
end

.bitsizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
66
67
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 57

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

.ciObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 52

def ci
  return :travis if ENV['TRAVIS']
  :jenkins if ENV['JENKINS']
end

.cygwin?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


93
94
95
96
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 93

def cygwin?
  RUBY_PLATFORM =~ /cygwin/
  !Regexp.last_match.nil?
end

.cygwin_path(path, opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
113
114
115
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 110

def cygwin_path(path, opts = {})
  flags = []
  opts.each { |k, v| flags << "--#{k}" if v }

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

.engineObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def engine
  @engine ||= defined?(RUBY_ENGINE) ? RUBY_ENGINE.to_sym : :ruby
end

.exit_hookObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



133
134
135
136
137
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 133

def exit_hook
  pid = Process.pid

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

.find_binary(*binary_names) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 139

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.tr!('\\', '/') 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 159

def find_in_program_files(*binary_names)
  paths = [
    ENV['PROGRAMFILES'] || '\\Program Files',
    ENV['ProgramFiles(x86)'] || '\\Program Files (x86)',
    ENV['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

.homeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 27

def home
  # jruby has an issue with ENV['HOME'] on Windows
  @home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
end

.interfacesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



199
200
201
202
203
204
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 199

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

  interfaces.compact.uniq
end

.ipObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 183

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

.ironruby?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def ironruby?
  engine == :ironruby
end

.jruby?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def jruby?
  engine == :jruby
end

.linux?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def linux?
  os == :linux
end

.localhostObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



176
177
178
179
180
181
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 176

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?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def mac?
  os == :macosx
end

.make_writable(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



117
118
119
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 117

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

.null_deviceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
101
102
103
104
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 98

def null_device
  @null_device ||= if defined?(File::NULL)
                     File::NULL
                   else
                     Platform.windows? ? 'NUL' : '/dev/null'
                   end
end

.osObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'build/rb/lib/selenium/webdriver/common/platform.rb', line 36

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_versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def ruby_version
  RUBY_VERSION
end

.windows?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def windows?
  os == :windows
end

.wrap_in_quotes_if_necessary(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

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