selenium-webdriver 2.53.3 → 3.142.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +665 -8
  3. data/Gemfile +2 -0
  4. data/LICENSE +1 -1
  5. data/README.md +2 -3
  6. data/lib/selenium/server.rb +76 -73
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +7 -0
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +102 -0
  9. data/lib/selenium/webdriver/{phantomjs.rb → atoms.rb} +10 -14
  10. data/lib/selenium/webdriver/chrome/bridge.rb +30 -101
  11. data/lib/selenium/webdriver/chrome/driver.rb +127 -0
  12. data/lib/selenium/webdriver/chrome/options.rb +190 -0
  13. data/lib/selenium/webdriver/chrome/profile.rb +21 -20
  14. data/lib/selenium/webdriver/chrome/service.rb +26 -93
  15. data/lib/selenium/webdriver/chrome.rb +15 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +52 -58
  17. data/lib/selenium/webdriver/common/alert.rb +7 -15
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +18 -22
  19. data/lib/selenium/webdriver/common/driver.rb +72 -72
  20. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +45 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +50 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/{has_input_devices.rb → has_debugger.rb} +11 -27
  23. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +6 -10
  24. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +51 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +7 -8
  26. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +51 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +2 -4
  28. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +2 -4
  29. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +3 -5
  30. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +2 -5
  31. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +6 -9
  32. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +9 -7
  33. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +3 -8
  34. data/lib/selenium/webdriver/common/element.rb +59 -39
  35. data/lib/selenium/webdriver/common/error.rb +259 -104
  36. data/lib/selenium/webdriver/common/file_reaper.rb +6 -14
  37. data/lib/selenium/webdriver/common/html5/local_storage.rb +8 -10
  38. data/lib/selenium/webdriver/common/html5/session_storage.rb +8 -10
  39. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +8 -16
  40. data/lib/selenium/webdriver/common/interactions/input_device.rb +54 -0
  41. data/lib/selenium/webdriver/common/interactions/interaction.rb +53 -0
  42. data/lib/selenium/webdriver/{safari/browser.rb → common/interactions/interactions.rb} +17 -14
  43. data/lib/selenium/webdriver/common/interactions/key_actions.rb +145 -0
  44. data/lib/selenium/webdriver/common/interactions/key_input.rb +66 -0
  45. data/lib/selenium/webdriver/{android.rb → common/interactions/none_input.rb} +14 -6
  46. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +363 -0
  47. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +139 -0
  48. data/lib/selenium/webdriver/common/keyboard.rb +10 -14
  49. data/lib/selenium/webdriver/common/keys.rb +102 -82
  50. data/lib/selenium/webdriver/common/log_entry.rb +7 -8
  51. data/lib/selenium/webdriver/common/logger.rb +115 -0
  52. data/lib/selenium/webdriver/common/logs.rb +4 -6
  53. data/lib/selenium/webdriver/common/manager.rb +177 -0
  54. data/lib/selenium/webdriver/common/mouse.rb +12 -14
  55. data/lib/selenium/webdriver/common/navigation.rb +4 -6
  56. data/lib/selenium/webdriver/common/options.rb +26 -127
  57. data/lib/selenium/webdriver/common/platform.rb +75 -101
  58. data/lib/selenium/webdriver/common/port_prober.rb +7 -19
  59. data/lib/selenium/webdriver/common/profile_helper.rb +8 -11
  60. data/lib/selenium/webdriver/common/proxy.rb +68 -74
  61. data/lib/selenium/webdriver/common/search_context.rb +28 -37
  62. data/lib/selenium/webdriver/common/service.rb +219 -0
  63. data/lib/selenium/webdriver/common/socket_lock.rb +15 -16
  64. data/lib/selenium/webdriver/common/socket_poller.rb +30 -28
  65. data/lib/selenium/webdriver/common/target_locator.rb +16 -18
  66. data/lib/selenium/webdriver/common/timeouts.rb +6 -8
  67. data/lib/selenium/webdriver/common/touch_action_builder.rb +5 -10
  68. data/lib/selenium/webdriver/common/touch_screen.rb +22 -23
  69. data/lib/selenium/webdriver/common/w3c_action_builder.rb +212 -0
  70. data/lib/selenium/webdriver/common/w3c_manager.rb +45 -0
  71. data/lib/selenium/webdriver/common/wait.rb +17 -16
  72. data/lib/selenium/webdriver/common/window.rb +50 -17
  73. data/lib/selenium/webdriver/common/zipper.rb +9 -13
  74. data/lib/selenium/webdriver/common.rb +21 -7
  75. data/lib/selenium/webdriver/edge/bridge.rb +34 -63
  76. data/lib/selenium/webdriver/edge/driver.rb +66 -0
  77. data/lib/selenium/webdriver/edge/options.rb +80 -0
  78. data/lib/selenium/webdriver/edge/service.rb +23 -95
  79. data/lib/selenium/webdriver/edge.rb +13 -13
  80. data/lib/selenium/webdriver/firefox/binary.rb +45 -60
  81. data/lib/selenium/webdriver/firefox/driver.rb +50 -0
  82. data/lib/selenium/webdriver/firefox/extension/prefs.json +3 -12
  83. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  84. data/lib/selenium/webdriver/firefox/extension.rb +20 -10
  85. data/lib/selenium/webdriver/firefox/launcher.rb +16 -22
  86. data/lib/selenium/webdriver/firefox/legacy/driver.rb +83 -0
  87. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +49 -0
  88. data/lib/selenium/webdriver/firefox/marionette/driver.rb +90 -0
  89. data/lib/selenium/webdriver/firefox/options.rb +162 -0
  90. data/lib/selenium/webdriver/firefox/profile.rb +47 -48
  91. data/lib/selenium/webdriver/firefox/profiles_ini.rb +11 -18
  92. data/lib/selenium/webdriver/firefox/service.rb +24 -95
  93. data/lib/selenium/webdriver/firefox/util.rb +2 -4
  94. data/lib/selenium/webdriver/firefox.rb +27 -12
  95. data/lib/selenium/webdriver/ie/driver.rb +85 -0
  96. data/lib/selenium/webdriver/ie/options.rb +138 -0
  97. data/lib/selenium/webdriver/ie/service.rb +54 -0
  98. data/lib/selenium/webdriver/ie.rb +12 -10
  99. data/lib/selenium/webdriver/remote/bridge.rb +100 -564
  100. data/lib/selenium/webdriver/remote/capabilities.rb +98 -100
  101. data/lib/selenium/webdriver/remote/driver.rb +51 -0
  102. data/lib/selenium/webdriver/remote/http/common.rb +34 -22
  103. data/lib/selenium/webdriver/remote/http/curb.rb +13 -14
  104. data/lib/selenium/webdriver/remote/http/default.rb +62 -43
  105. data/lib/selenium/webdriver/remote/http/persistent.rb +12 -9
  106. data/lib/selenium/webdriver/remote/oss/bridge.rb +594 -0
  107. data/lib/selenium/webdriver/remote/oss/commands.rb +223 -0
  108. data/lib/selenium/webdriver/remote/response.rb +48 -28
  109. data/lib/selenium/webdriver/remote/server_error.rb +3 -5
  110. data/lib/selenium/webdriver/remote/w3c/bridge.rb +605 -0
  111. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +310 -0
  112. data/lib/selenium/webdriver/remote/w3c/commands.rb +157 -0
  113. data/lib/selenium/webdriver/remote.rb +10 -16
  114. data/lib/selenium/webdriver/safari/bridge.rb +17 -101
  115. data/lib/selenium/webdriver/{firefox/w3c_bridge.rb → safari/driver.rb} +27 -25
  116. data/lib/selenium/webdriver/safari/options.rb +29 -31
  117. data/lib/selenium/webdriver/safari/service.rb +38 -0
  118. data/lib/selenium/webdriver/safari.rb +27 -27
  119. data/lib/selenium/webdriver/support/abstract_event_listener.rb +19 -4
  120. data/lib/selenium/webdriver/support/block_event_listener.rb +3 -5
  121. data/lib/selenium/webdriver/support/color.rb +60 -43
  122. data/lib/selenium/webdriver/support/escaper.rb +43 -0
  123. data/lib/selenium/webdriver/support/event_firing_bridge.rb +39 -41
  124. data/lib/selenium/webdriver/support/select.rb +45 -97
  125. data/lib/selenium/webdriver/support.rb +3 -2
  126. data/lib/selenium/webdriver/{iphone.rb → version.rb} +3 -7
  127. data/lib/selenium/webdriver.rb +36 -23
  128. data/lib/selenium-webdriver.rb +2 -2
  129. data/selenium-webdriver.gemspec +42 -29
  130. metadata +331 -262
  131. data/lib/selenium/client/base.rb +0 -151
  132. data/lib/selenium/client/driver.rb +0 -29
  133. data/lib/selenium/client/errors.rb +0 -28
  134. data/lib/selenium/client/extensions.rb +0 -132
  135. data/lib/selenium/client/idiomatic.rb +0 -507
  136. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  137. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -32
  138. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -32
  139. data/lib/selenium/client/legacy_driver.rb +0 -1722
  140. data/lib/selenium/client/protocol.rb +0 -123
  141. data/lib/selenium/client/selenium_helper.rb +0 -49
  142. data/lib/selenium/client.rb +0 -57
  143. data/lib/selenium/rake/server_task.rb +0 -176
  144. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  145. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  146. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  147. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  148. data/lib/selenium/webdriver/common/w3c_error.rb +0 -194
  149. data/lib/selenium/webdriver/edge/legacy_support.rb +0 -117
  150. data/lib/selenium/webdriver/firefox/bridge.rb +0 -89
  151. data/lib/selenium/webdriver/ie/bridge.rb +0 -88
  152. data/lib/selenium/webdriver/ie/server.rb +0 -133
  153. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
  154. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -78
  155. data/lib/selenium/webdriver/phantomjs/service.rb +0 -130
  156. data/lib/selenium/webdriver/remote/commands.rb +0 -211
  157. data/lib/selenium/webdriver/remote/w3c_bridge.rb +0 -668
  158. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +0 -236
  159. data/lib/selenium/webdriver/remote/w3c_commands.rb +0 -132
  160. data/lib/selenium/webdriver/safari/resources/client.js +0 -7255
  161. data/lib/selenium/webdriver/safari/server.rb +0 -187
  162. data/lib/selenium-client.rb +0 -21
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  class Navigation
23
-
24
23
  def initialize(bridge)
25
24
  @bridge = bridge
26
25
  end
@@ -38,7 +37,7 @@ module Selenium
38
37
  #
39
38
 
40
39
  def back
41
- @bridge.goBack
40
+ @bridge.go_back
42
41
  end
43
42
 
44
43
  #
@@ -46,7 +45,7 @@ module Selenium
46
45
  #
47
46
 
48
47
  def forward
49
- @bridge.goForward
48
+ @bridge.go_forward
50
49
  end
51
50
 
52
51
  #
@@ -56,7 +55,6 @@ module Selenium
56
55
  def refresh
57
56
  @bridge.refresh
58
57
  end
59
-
60
58
  end # Navigation
61
59
  end # WebDriver
62
60
  end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -19,136 +19,35 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- class Options
23
-
24
- #
25
- # @api private
26
- #
27
-
28
- def initialize(bridge)
29
- @bridge = bridge
30
- end
31
-
32
- #
33
- # Add a cookie to the browser
34
- #
35
- # @param [Hash] opts the options to create a cookie with.
36
- # @option opts [String] :name A name
37
- # @option opts [String] :value A value
38
- # @option opts [String] :path ('/') A path
39
- # @option opts [String] :secure (false) A boolean
40
- # @option opts [Time,DateTime,Numeric,nil] :expires (nil) Expiry date, either as a Time, DateTime, or seconds since epoch.
41
- #
42
- # @raise [ArgumentError] if :name or :value is not specified
43
- #
44
-
45
- def add_cookie(opts = {})
46
- raise ArgumentError, "name is required" unless opts[:name]
47
- raise ArgumentError, "value is required" unless opts[:value]
48
-
49
- opts[:path] ||= "/"
50
- opts[:secure] ||= false
51
-
52
- if obj = opts.delete(:expires)
53
- opts[:expiry] = seconds_from(obj).to_i
22
+ module Common
23
+ class Options
24
+ private
25
+
26
+ def generate_as_json(value)
27
+ if value.respond_to?(:as_json)
28
+ value.as_json
29
+ elsif value.is_a?(Hash)
30
+ value.each_with_object({}) { |(key, val), hash| hash[convert_json_key(key)] = generate_as_json(val) }
31
+ elsif value.is_a?(Array)
32
+ value.map(&method(:generate_as_json))
33
+ elsif value.is_a?(Symbol)
34
+ value.to_s
35
+ else
36
+ value
37
+ end
54
38
  end
55
39
 
56
- @bridge.addCookie opts
57
- end
58
-
59
- #
60
- # Get the cookie with the given name
61
- #
62
- # @param [String] name the name of the cookie
63
- # @return [Hash, nil] the cookie, or nil if it wasn't found.
64
- #
65
-
66
- def cookie_named(name)
67
- all_cookies.find { |c| c[:name] == name }
68
- end
69
-
70
- #
71
- # Delete the cookie with the given name
72
- #
73
- # @param [String] name the name of the cookie to delete
74
- #
75
-
76
- def delete_cookie(name)
77
- @bridge.deleteCookie name
78
- end
79
-
80
- #
81
- # Delete all cookies
82
- #
40
+ def convert_json_key(key)
41
+ key = camel_case(key) if key.is_a?(Symbol)
42
+ return key if key.is_a?(String)
83
43
 
84
- def delete_all_cookies
85
- @bridge.deleteAllCookies
86
- end
87
-
88
- #
89
- # Get all cookies
90
- #
91
- # @return [Array<Hash>] list of cookies
92
- #
93
-
94
- def all_cookies
95
- @bridge.getAllCookies.map do |cookie|
96
- {
97
- :name => cookie["name"],
98
- :value => cookie["value"],
99
- :path => cookie["path"],
100
- :domain => cookie["domain"] && strip_port(cookie["domain"]),
101
- :expires => cookie["expiry"] && datetime_at(cookie['expiry']),
102
- :secure => cookie["secure"]
103
- }
44
+ raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}"
104
45
  end
105
- end
106
-
107
- def timeouts
108
- @timeouts ||= Timeouts.new(@bridge)
109
- end
110
-
111
- #
112
- # @api beta This API may be changed or removed in a future release.
113
- #
114
-
115
- def logs
116
- @logs ||= Logs.new(@bridge)
117
- end
118
-
119
- #
120
- # @api beta This API may be changed or removed in a future release.
121
- #
122
46
 
123
- def window
124
- @window ||= Window.new(@bridge)
125
- end
126
-
127
- private
128
-
129
- SECONDS_PER_DAY = 86_400.0
130
-
131
- def datetime_at(int)
132
- DateTime.civil(1970) + (int / SECONDS_PER_DAY)
133
- end
134
-
135
- def seconds_from(obj)
136
- case obj
137
- when Time
138
- obj.to_f
139
- when DateTime
140
- (obj - DateTime.civil(1970)) * SECONDS_PER_DAY
141
- when Numeric
142
- obj
143
- else
144
- raise ArgumentError, "invalid value for expiration date: #{obj.inspect}"
47
+ def camel_case(str)
48
+ str.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
145
49
  end
146
- end
147
-
148
- def strip_port(str)
149
- str.split(":", 2).first
150
- end
151
-
152
- end # Options
50
+ end # Options
51
+ end # Common
153
52
  end # WebDriver
154
53
  end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -22,43 +22,32 @@ require 'socket'
22
22
 
23
23
  module Selenium
24
24
  module WebDriver
25
-
26
25
  # @api private
27
26
  module Platform
28
-
29
27
  module_function
30
28
 
31
29
  def home
32
- # jruby has an issue with ENV['HOME'] on Windows
33
- @home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
30
+ @home ||= Dir.home
34
31
  end
35
32
 
36
33
  def engine
37
- @engine ||= (
38
- if defined? RUBY_ENGINE
39
- RUBY_ENGINE.to_sym
40
- else
41
- :ruby
42
- end
43
- )
34
+ @engine ||= RUBY_ENGINE.to_sym
44
35
  end
45
36
 
46
37
  def os
47
- @os ||= (
48
- host_os = RbConfig::CONFIG['host_os']
49
- case host_os
50
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
51
- :windows
52
- when /darwin|mac os/
53
- :macosx
54
- when /linux/
55
- :linux
56
- when /solaris|bsd/
57
- :unix
58
- else
59
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
60
- end
61
- )
38
+ host_os = RbConfig::CONFIG['host_os']
39
+ @os ||= case host_os
40
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
41
+ :windows
42
+ when /darwin|mac os/
43
+ :macosx
44
+ when /linux/
45
+ :linux
46
+ when /solaris|bsd/
47
+ :unix
48
+ else
49
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
50
+ end
62
51
  end
63
52
 
64
53
  def ci
@@ -66,37 +55,29 @@ module Selenium
66
55
  :travis
67
56
  elsif ENV['JENKINS']
68
57
  :jenkins
58
+ elsif ENV['APPVEYOR']
59
+ :appveyor
69
60
  end
70
61
  end
71
62
 
72
63
  def bitsize
73
- @bitsize ||= (
74
- if defined?(FFI::Platform::ADDRESS_SIZE)
75
- FFI::Platform::ADDRESS_SIZE
76
- elsif defined?(FFI)
77
- FFI.type_size(:pointer) == 4 ? 32 : 64
78
- elsif jruby?
79
- Integer(ENV_JAVA['sun.arch.data.model'])
80
- else
81
- 1.size == 4 ? 32 : 64
82
- end
83
- )
64
+ @bitsize ||= if defined?(FFI::Platform::ADDRESS_SIZE)
65
+ FFI::Platform::ADDRESS_SIZE
66
+ elsif defined?(FFI)
67
+ FFI.type_size(:pointer) == 4 ? 32 : 64
68
+ elsif jruby?
69
+ Integer(ENV_JAVA['sun.arch.data.model'])
70
+ else
71
+ 1.size == 4 ? 32 : 64
72
+ end
84
73
  end
85
74
 
86
75
  def jruby?
87
76
  engine == :jruby
88
77
  end
89
78
 
90
- def ironruby?
91
- engine == :ironruby
92
- end
93
-
94
- def ruby187?
95
- !!(RUBY_VERSION =~ /^1\.8\.7/)
96
- end
97
-
98
- def ruby19?
99
- !!(RUBY_VERSION =~ /^1\.9/)
79
+ def ruby_version
80
+ RUBY_VERSION
100
81
  end
101
82
 
102
83
  def windows?
@@ -111,68 +92,78 @@ module Selenium
111
92
  os == :linux
112
93
  end
113
94
 
95
+ def wsl?
96
+ return false unless linux?
97
+
98
+ File.read('/proc/version').include?('Microsoft')
99
+ end
100
+
114
101
  def cygwin?
115
- !!(RUBY_PLATFORM =~ /cygwin/)
102
+ RUBY_PLATFORM =~ /cygwin/
103
+ !Regexp.last_match.nil?
116
104
  end
117
105
 
118
106
  def null_device
119
- @null_device ||= (
120
- if defined?(File::NULL)
121
- File::NULL
122
- else
123
- Platform.windows? ? 'NUL' : '/dev/null'
124
- end
125
- )
107
+ File::NULL
126
108
  end
127
109
 
128
110
  def wrap_in_quotes_if_necessary(str)
129
- windows? && !cygwin? ? %{"#{str}"} : str
111
+ windows? && !cygwin? ? %("#{str}") : str
130
112
  end
131
113
 
132
- def cygwin_path(path, opts = {})
114
+ def cygwin_path(path, **opts)
133
115
  flags = []
134
- opts.each { |k,v| flags << "--#{k}" if v }
116
+ opts.each { |k, v| flags << "--#{k}" if v }
135
117
 
136
118
  `cygpath #{flags.join ' '} "#{path}"`.strip
137
119
  end
138
120
 
121
+ def unix_path(path)
122
+ path.tr(File::ALT_SEPARATOR, File::SEPARATOR)
123
+ end
124
+
125
+ def windows_path(path)
126
+ path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
127
+ end
128
+
139
129
  def make_writable(file)
140
- File.chmod 0766, file
130
+ File.chmod 0o766, file
141
131
  end
142
132
 
143
133
  def assert_file(path)
144
- unless File.file? path
145
- raise Error::WebDriverError, "not a file: #{path.inspect}"
146
- end
134
+ return if File.file? path
135
+
136
+ raise Error::WebDriverError, "not a file: #{path.inspect}"
147
137
  end
148
138
 
149
139
  def assert_executable(path)
150
140
  assert_file(path)
151
141
 
152
- unless File.executable? path
153
- raise Error::WebDriverError, "not executable: #{path.inspect}"
154
- end
142
+ return if File.executable? path
143
+
144
+ raise Error::WebDriverError, "not executable: #{path.inspect}"
155
145
  end
156
146
 
157
- def exit_hook(&blk)
147
+ def exit_hook
158
148
  pid = Process.pid
159
149
 
160
- at_exit do
161
- yield if Process.pid == pid
162
- end
150
+ at_exit { yield if Process.pid == pid }
163
151
  end
164
152
 
165
153
  def find_binary(*binary_names)
166
154
  paths = ENV['PATH'].split(File::PATH_SEPARATOR)
167
- binary_names.map! { |n| "#{n}.exe" } if windows?
155
+
156
+ if windows?
157
+ binary_names.map! { |n| "#{n}.exe" }
158
+ binary_names.dup.each { |n| binary_names << n.gsub('exe', 'bat') }
159
+ end
168
160
 
169
161
  binary_names.each do |binary_name|
170
162
  paths.each do |path|
171
163
  full_path = File.join(path, binary_name)
172
- full_path.tr!('\\', '/') if windows?
173
- exe = Dir.glob(full_path).first
174
- next unless exe
175
- return exe if File.executable?(exe)
164
+ full_path = unix_path(full_path) if windows?
165
+ exe = Dir.glob(full_path).find { |f| File.executable?(f) }
166
+ return exe if exe
176
167
  end
177
168
  end
178
169
 
@@ -181,8 +172,9 @@ module Selenium
181
172
 
182
173
  def find_in_program_files(*binary_names)
183
174
  paths = [
184
- ENV['PROGRAMFILES'] || "\\Program Files",
185
- ENV['ProgramFiles(x86)'] || "\\Program Files (x86)"
175
+ ENV['PROGRAMFILES'] || '\\Program Files',
176
+ ENV['ProgramFiles(x86)'] || '\\Program Files (x86)',
177
+ ENV['ProgramW6432'] || '\\Program Files'
186
178
  ]
187
179
 
188
180
  paths.each do |root|
@@ -196,13 +188,11 @@ module Selenium
196
188
  end
197
189
 
198
190
  def localhost
199
- info = Socket.getaddrinfo "localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM
191
+ info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM
200
192
 
201
- if info.empty?
202
- raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
203
- end
193
+ return info[0][3] unless info.empty?
204
194
 
205
- info[0][3]
195
+ raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
206
196
  end
207
197
 
208
198
  def ip
@@ -222,27 +212,11 @@ module Selenium
222
212
  end
223
213
 
224
214
  def interfaces
225
- interfaces = Socket.getaddrinfo("localhost", 8080).map { |e| e[3] }
226
- interfaces += ["0.0.0.0", Platform.ip]
215
+ interfaces = Socket.getaddrinfo('localhost', 8080).map { |e| e[3] }
216
+ interfaces += ['0.0.0.0', Platform.ip]
227
217
 
228
218
  interfaces.compact.uniq
229
219
  end
230
-
231
220
  end # Platform
232
221
  end # WebDriver
233
222
  end # Selenium
234
-
235
- if __FILE__ == $0
236
- p :engine => Selenium::WebDriver::Platform.engine,
237
- :os => Selenium::WebDriver::Platform.os,
238
- :ruby187? => Selenium::WebDriver::Platform.ruby187?,
239
- :ruby19? => Selenium::WebDriver::Platform.ruby19?,
240
- :jruby? => Selenium::WebDriver::Platform.jruby?,
241
- :windows? => Selenium::WebDriver::Platform.windows?,
242
- :home => Selenium::WebDriver::Platform.home,
243
- :bitsize => Selenium::WebDriver::Platform.bitsize,
244
- :localhost => Selenium::WebDriver::Platform.localhost,
245
- :ip => Selenium::WebDriver::Platform.ip,
246
- :interfaces => Selenium::WebDriver::Platform.interfaces,
247
- :null_device => Selenium::WebDriver::Platform.null_device
248
- end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -25,28 +25,17 @@ module Selenium
25
25
  port
26
26
  end
27
27
 
28
- def self.random
29
- # TODO: Avoid this
30
- #
31
- # (a) should pick a port that's guaranteed to be free on all interfaces
32
- # (b) should pick a random port outside the ephemeral port range
33
- #
34
- server = TCPServer.new(Platform.localhost, 0)
35
- port = server.addr[1]
36
- server.close
37
-
38
- port
39
- end
40
-
41
- IGNORED_ERRORS = [Errno::EADDRNOTAVAIL]
42
- IGNORED_ERRORS << Errno::EBADF if Platform.cygwin?
28
+ IGNORED_ERRORS = [Errno::EADDRNOTAVAIL, Errno::EAFNOSUPPORT].tap { |arr|
29
+ arr << Errno::EBADF if Platform.cygwin?
30
+ arr << Errno::EACCES if Platform.windows?
31
+ }.freeze
43
32
 
44
33
  def self.free?(port)
45
34
  Platform.interfaces.each do |host|
46
35
  begin
47
36
  TCPServer.new(host, port).close
48
37
  rescue *IGNORED_ERRORS => ex
49
- $stderr.puts "port prober could not bind to #{host}:#{port} (#{ex.message})" if $DEBUG
38
+ WebDriver.logger.debug("port prober could not bind to #{host}:#{port} (#{ex.message})")
50
39
  # ignored - some machines appear unable to bind to some of their interfaces
51
40
  end
52
41
  end
@@ -55,7 +44,6 @@ module Selenium
55
44
  rescue SocketError, Errno::EADDRINUSE
56
45
  false
57
46
  end
58
-
59
47
  end # PortProber
60
48
  end # WebDriver
61
49
  end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -19,7 +19,6 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
-
23
22
  #
24
23
  # @api private
25
24
  #
@@ -28,27 +27,26 @@ module Selenium
28
27
  #
29
28
 
30
29
  module ProfileHelper
31
-
32
30
  def self.included(base)
33
31
  base.extend ClassMethods
34
32
  end
35
33
 
36
- def as_json(opts = nil)
37
- {'zip' => Zipper.zip(layout_on_disk)}
34
+ def as_json(*)
35
+ {"zip" => Zipper.zip(layout_on_disk)}
38
36
  end
39
37
 
40
- def to_json(*args)
38
+ def to_json(*)
41
39
  JSON.generate as_json
42
40
  end
43
41
 
44
42
  private
45
43
 
46
44
  def create_tmp_copy(directory)
47
- tmp_directory = Dir.mktmpdir("webdriver-rb-profilecopy")
45
+ tmp_directory = Dir.mktmpdir('webdriver-rb-profilecopy')
48
46
 
49
47
  # TODO: must be a better way..
50
48
  FileUtils.rm_rf tmp_directory
51
- FileUtils.mkdir_p File.dirname(tmp_directory), :mode => 0700
49
+ FileUtils.mkdir_p File.dirname(tmp_directory), mode: 0o700
52
50
  FileUtils.cp_r directory, tmp_directory
53
51
 
54
52
  tmp_directory
@@ -72,7 +70,7 @@ module Selenium
72
70
  tmp_dir = Dir.mktmpdir
73
71
  begin
74
72
  zip_path = File.join(tmp_dir, "webdriver-profile-duplicate-#{json.hash}.zip")
75
- File.open(zip_path, "wb") { |zip_file| zip_file << Base64.decode64(data) }
73
+ File.open(zip_path, 'wb') { |zip_file| zip_file << Base64.decode64(data) }
76
74
 
77
75
  new Zipper.unzip(zip_path)
78
76
  ensure
@@ -80,7 +78,6 @@ module Selenium
80
78
  end
81
79
  end
82
80
  end # ClassMethods
83
-
84
81
  end # ProfileHelper
85
82
  end # WebDriver
86
83
  end # Selenium