Module: Selenium::WebDriver::Platform Private

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

Overview

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.

API:

  • private

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.

API:

  • private



141
142
143
144
145
146
147
# File 'lib/selenium/webdriver/common/platform.rb', line 141

def assert_executable(path)
  assert_file(path)

  unless File.executable? path
    raise Error::WebDriverError, "not executable: #{path.inspect}"
  end
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.

API:

  • private



135
136
137
138
139
# File 'lib/selenium/webdriver/common/platform.rb', line 135

def assert_file(path)
  unless File.file? path
    raise Error::WebDriverError, "not a file: #{path.inspect}"
  end
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.

API:

  • private



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/selenium/webdriver/common/platform.rb', line 64

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

.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:

API:

  • private



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

def cygwin?
  !!(RUBY_PLATFORM =~ /cygwin/)
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.

API:

  • private



124
125
126
127
128
129
# File 'lib/selenium/webdriver/common/platform.rb', line 124

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.

API:

  • private



36
37
38
39
40
41
42
43
44
# File 'lib/selenium/webdriver/common/platform.rb', line 36

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

.exit_hook(&blk) ⇒ 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.

API:

  • private



149
150
151
152
153
154
155
# File 'lib/selenium/webdriver/common/platform.rb', line 149

def exit_hook(&blk)
  pid = Process.pid

  at_exit do
    yield if Process.pid == pid
  end
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.

API:

  • private



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/selenium/webdriver/common/platform.rb', line 157

def find_binary(*binary_names)
  paths = ENV['PATH'].split(File::PATH_SEPARATOR)
  binary_names.map! { |n| "#{n}.exe" } if windows?

  binary_names.each do |binary_name|
    paths.each do |path|
      exe = File.join(path, binary_name)
      return exe if File.executable?(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.

API:

  • private



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/selenium/webdriver/common/platform.rb', line 171

def find_in_program_files(*binary_names)
  paths = [
    ENV['PROGRAMFILES'] || "\\Program Files",
    ENV['ProgramFiles(x86)'] || "\\Program Files (x86)"
  ]

  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.

API:

  • private



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

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.

API:

  • private



213
214
215
216
217
218
# File 'lib/selenium/webdriver/common/platform.rb', line 213

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.

API:

  • private



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/selenium/webdriver/common/platform.rb', line 197

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:

API:

  • private



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

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:

API:

  • private



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

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:

API:

  • private



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

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.

API:

  • private



187
188
189
190
191
192
193
194
195
# File 'lib/selenium/webdriver/common/platform.rb', line 187

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

  if info.empty?
    raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
  end

  info[0][3]
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:

API:

  • private



98
99
100
# File 'lib/selenium/webdriver/common/platform.rb', line 98

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.

API:

  • private



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

def make_writable(file)
  File.chmod 0766, 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.

API:

  • private



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

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.

API:

  • private



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/selenium/webdriver/common/platform.rb', line 46

def os
  @os ||= (
    host_os = RbConfig::CONFIG['host_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

.ruby187?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:

API:

  • private



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

def ruby187?
  !!(RUBY_VERSION =~ /^1\.8\.7/)
end

.ruby19?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:

API:

  • private



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

def ruby19?
  !!(RUBY_VERSION =~ /^1\.9/)
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:

API:

  • private



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

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.

API:

  • private



120
121
122
# File 'lib/selenium/webdriver/common/platform.rb', line 120

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