selenium-webdriver 2.45.0 → 3.142.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +795 -3
  3. data/Gemfile +2 -0
  4. data/{COPYING → LICENSE} +1 -3
  5. data/README.md +13 -9
  6. data/lib/selenium/server.rb +93 -71
  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/atoms.rb +37 -0
  10. data/lib/selenium/webdriver/chrome/bridge.rb +47 -99
  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 +40 -20
  14. data/lib/selenium/webdriver/chrome/service.rb +46 -62
  15. data/lib/selenium/webdriver/chrome.rb +34 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +69 -56
  17. data/lib/selenium/webdriver/common/alert.rb +25 -8
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +35 -20
  19. data/lib/selenium/webdriver/common/driver.rb +90 -63
  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_debugger.rb +42 -0
  23. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +26 -11
  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 +58 -0
  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 +23 -6
  28. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +19 -2
  29. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +24 -7
  30. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +19 -3
  31. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +23 -7
  32. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +26 -5
  33. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +20 -6
  34. data/lib/selenium/webdriver/common/element.rb +79 -37
  35. data/lib/selenium/webdriver/common/error.rb +282 -106
  36. data/lib/selenium/webdriver/common/file_reaper.rb +23 -12
  37. data/lib/selenium/webdriver/common/html5/local_storage.rb +29 -12
  38. data/lib/selenium/webdriver/common/html5/session_storage.rb +29 -12
  39. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +29 -18
  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/common/interactions/interactions.rb +43 -0
  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/common/interactions/none_input.rb +36 -0
  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 +27 -12
  49. data/lib/selenium/webdriver/common/keys.rb +118 -81
  50. data/lib/selenium/webdriver/common/log_entry.rb +27 -8
  51. data/lib/selenium/webdriver/common/logger.rb +115 -0
  52. data/lib/selenium/webdriver/common/logs.rb +24 -7
  53. data/lib/selenium/webdriver/common/manager.rb +177 -0
  54. data/lib/selenium/webdriver/common/mouse.rb +29 -12
  55. data/lib/selenium/webdriver/common/navigation.rb +21 -4
  56. data/lib/selenium/webdriver/common/options.rb +43 -126
  57. data/lib/selenium/webdriver/common/platform.rb +101 -97
  58. data/lib/selenium/webdriver/common/port_prober.rb +24 -17
  59. data/lib/selenium/webdriver/common/profile_helper.rb +27 -11
  60. data/lib/selenium/webdriver/common/proxy.rb +86 -73
  61. data/lib/selenium/webdriver/common/search_context.rb +49 -33
  62. data/lib/selenium/webdriver/common/service.rb +219 -0
  63. data/lib/selenium/webdriver/common/socket_lock.rb +82 -0
  64. data/lib/selenium/webdriver/common/socket_poller.rb +47 -26
  65. data/lib/selenium/webdriver/common/target_locator.rb +35 -14
  66. data/lib/selenium/webdriver/common/timeouts.rb +23 -6
  67. data/lib/selenium/webdriver/common/touch_action_builder.rb +25 -11
  68. data/lib/selenium/webdriver/common/touch_screen.rb +42 -24
  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 +34 -14
  72. data/lib/selenium/webdriver/common/window.rb +75 -16
  73. data/lib/selenium/webdriver/common/zipper.rb +26 -11
  74. data/lib/selenium/webdriver/common.rb +40 -7
  75. data/lib/selenium/webdriver/edge/bridge.rb +76 -0
  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 +52 -0
  79. data/lib/selenium/webdriver/edge.rb +44 -0
  80. data/lib/selenium/webdriver/firefox/binary.rb +70 -48
  81. data/lib/selenium/webdriver/firefox/driver.rb +50 -0
  82. data/lib/selenium/webdriver/firefox/extension/prefs.json +14 -13
  83. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  84. data/lib/selenium/webdriver/firefox/extension.rb +50 -19
  85. data/lib/selenium/webdriver/firefox/launcher.rb +33 -28
  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 +66 -48
  91. data/lib/selenium/webdriver/firefox/profiles_ini.rb +28 -16
  92. data/lib/selenium/webdriver/firefox/service.rb +52 -0
  93. data/lib/selenium/webdriver/firefox/util.rb +19 -2
  94. data/lib/selenium/webdriver/firefox.rb +46 -10
  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 +32 -10
  99. data/lib/selenium/webdriver/remote/bridge.rb +117 -572
  100. data/lib/selenium/webdriver/remote/capabilities.rb +116 -99
  101. data/lib/selenium/webdriver/remote/driver.rb +51 -0
  102. data/lib/selenium/webdriver/remote/http/common.rb +54 -23
  103. data/lib/selenium/webdriver/remote/http/curb.rb +30 -12
  104. data/lib/selenium/webdriver/remote/http/default.rb +85 -42
  105. data/lib/selenium/webdriver/remote/http/persistent.rb +29 -7
  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 +68 -30
  109. data/lib/selenium/webdriver/remote/server_error.rb +22 -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 +27 -13
  114. data/lib/selenium/webdriver/safari/bridge.rb +38 -107
  115. data/lib/selenium/webdriver/safari/driver.rb +68 -0
  116. data/lib/selenium/webdriver/safari/options.rb +56 -75
  117. data/lib/selenium/webdriver/safari/service.rb +38 -0
  118. data/lib/selenium/webdriver/safari.rb +49 -31
  119. data/lib/selenium/webdriver/support/abstract_event_listener.rb +40 -6
  120. data/lib/selenium/webdriver/support/block_event_listener.rb +24 -7
  121. data/lib/selenium/webdriver/support/color.rb +82 -46
  122. data/lib/selenium/webdriver/support/escaper.rb +43 -0
  123. data/lib/selenium/webdriver/support/event_firing_bridge.rb +56 -39
  124. data/lib/selenium/webdriver/support/select.rb +66 -89
  125. data/lib/selenium/webdriver/support.rb +20 -0
  126. data/lib/selenium/webdriver/version.rb +24 -0
  127. data/lib/selenium/webdriver.rb +55 -25
  128. data/lib/selenium-webdriver.rb +19 -0
  129. data/selenium-webdriver.gemspec +42 -29
  130. metadata +331 -260
  131. data/Gemfile.lock +0 -48
  132. data/lib/selenium/client/base.rb +0 -132
  133. data/lib/selenium/client/driver.rb +0 -10
  134. data/lib/selenium/client/errors.rb +0 -9
  135. data/lib/selenium/client/extensions.rb +0 -118
  136. data/lib/selenium/client/idiomatic.rb +0 -488
  137. data/lib/selenium/client/javascript_expression_builder.rb +0 -116
  138. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -13
  139. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -13
  140. data/lib/selenium/client/legacy_driver.rb +0 -1720
  141. data/lib/selenium/client/protocol.rb +0 -104
  142. data/lib/selenium/client/selenium_helper.rb +0 -34
  143. data/lib/selenium/client.rb +0 -38
  144. data/lib/selenium/rake/server_task.rb +0 -157
  145. data/lib/selenium/webdriver/android/bridge.rb +0 -49
  146. data/lib/selenium/webdriver/android.rb +0 -9
  147. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -9
  148. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -42
  149. data/lib/selenium/webdriver/common/core_ext/string.rb +0 -5
  150. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +0 -17
  151. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +0 -39
  152. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  153. data/lib/selenium/webdriver/common/json_helper.rb +0 -34
  154. data/lib/selenium/webdriver/firefox/bridge.rb +0 -70
  155. data/lib/selenium/webdriver/firefox/socket_lock.rb +0 -61
  156. data/lib/selenium/webdriver/ie/bridge.rb +0 -69
  157. data/lib/selenium/webdriver/ie/server.rb +0 -90
  158. data/lib/selenium/webdriver/iphone/bridge.rb +0 -45
  159. data/lib/selenium/webdriver/iphone.rb +0 -9
  160. data/lib/selenium/webdriver/opera/bridge.rb +0 -112
  161. data/lib/selenium/webdriver/opera/service.rb +0 -49
  162. data/lib/selenium/webdriver/opera.rb +0 -24
  163. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -59
  164. data/lib/selenium/webdriver/phantomjs/service.rb +0 -90
  165. data/lib/selenium/webdriver/phantomjs.rb +0 -22
  166. data/lib/selenium/webdriver/remote/commands.rb +0 -192
  167. data/lib/selenium/webdriver/safari/browser.rb +0 -20
  168. data/lib/selenium/webdriver/safari/extensions.rb +0 -170
  169. data/lib/selenium/webdriver/safari/resources/SafariDriver.safariextz +0 -0
  170. data/lib/selenium/webdriver/safari/resources/client.js +0 -6903
  171. data/lib/selenium/webdriver/safari/server.rb +0 -145
  172. data/lib/selenium-client.rb +0 -2
@@ -1,13 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
-
4
22
  #
5
23
  # @api private
6
24
  # @see ActionBuilder
7
25
  #
8
26
 
9
27
  class Mouse
10
-
11
28
  def initialize(bridge)
12
29
  @bridge = bridge
13
30
  end
@@ -19,22 +36,22 @@ module Selenium
19
36
 
20
37
  def double_click(element = nil)
21
38
  move_if_needed element
22
- @bridge.doubleClick
39
+ @bridge.double_click
23
40
  end
24
41
 
25
42
  def context_click(element = nil)
26
43
  move_if_needed element
27
- @bridge.contextClick
44
+ @bridge.context_click
28
45
  end
29
46
 
30
47
  def down(element = nil)
31
48
  move_if_needed element
32
- @bridge.mouseDown
49
+ @bridge.mouse_down
33
50
  end
34
51
 
35
52
  def up(element = nil)
36
53
  move_if_needed element
37
- @bridge.mouseUp
54
+ @bridge.mouse_up
38
55
  end
39
56
 
40
57
  #
@@ -49,11 +66,11 @@ module Selenium
49
66
  def move_to(element, right_by = nil, down_by = nil)
50
67
  assert_element element
51
68
 
52
- @bridge.mouseMoveTo element.ref, right_by, down_by
69
+ @bridge.mouse_move_to element.ref, right_by, down_by
53
70
  end
54
71
 
55
72
  def move_by(right_by, down_by)
56
- @bridge.mouseMoveTo nil, Integer(right_by), Integer(down_by)
73
+ @bridge.mouse_move_to nil, Integer(right_by), Integer(down_by)
57
74
  end
58
75
 
59
76
  private
@@ -63,10 +80,10 @@ module Selenium
63
80
  end
64
81
 
65
82
  def assert_element(element)
66
- unless element.kind_of? Element
67
- raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
68
- end
83
+ return if element.is_a? Element
84
+
85
+ raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
69
86
  end
70
87
  end # Mouse
71
88
  end # WebDriver
72
- end # Selenium
89
+ end # Selenium
@@ -1,7 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
22
  class Navigation
4
-
5
23
  def initialize(bridge)
6
24
  @bridge = bridge
7
25
  end
@@ -19,7 +37,7 @@ module Selenium
19
37
  #
20
38
 
21
39
  def back
22
- @bridge.goBack
40
+ @bridge.go_back
23
41
  end
24
42
 
25
43
  #
@@ -27,7 +45,7 @@ module Selenium
27
45
  #
28
46
 
29
47
  def forward
30
- @bridge.goForward
48
+ @bridge.go_forward
31
49
  end
32
50
 
33
51
  #
@@ -37,7 +55,6 @@ module Selenium
37
55
  def refresh
38
56
  @bridge.refresh
39
57
  end
40
-
41
58
  end # Navigation
42
59
  end # WebDriver
43
60
  end # Selenium
@@ -1,136 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
- class Options
4
-
5
- #
6
- # @api private
7
- #
8
-
9
- def initialize(bridge)
10
- @bridge = bridge
11
- end
12
-
13
- #
14
- # Add a cookie to the browser
15
- #
16
- # @param [Hash] opts the options to create a cookie with.
17
- # @option opts [String] :name A name
18
- # @option opts [String] :value A value
19
- # @option opts [String] :path ('/') A path
20
- # @option opts [String] :secure (false) A boolean
21
- # @option opts [Time,DateTime,Numeric,nil] :expires (nil) Expiry date, either as a Time, DateTime, or seconds since epoch.
22
- #
23
- # @raise [ArgumentError] if :name or :value is not specified
24
- #
25
-
26
- def add_cookie(opts = {})
27
- raise ArgumentError, "name is required" unless opts[:name]
28
- raise ArgumentError, "value is required" unless opts[:value]
29
-
30
- opts[:path] ||= "/"
31
- opts[:secure] ||= false
32
-
33
- if obj = opts.delete(:expires)
34
- opts[:expiry] = seconds_from(obj)
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
35
38
  end
36
39
 
40
+ def convert_json_key(key)
41
+ key = camel_case(key) if key.is_a?(Symbol)
42
+ return key if key.is_a?(String)
37
43
 
38
- @bridge.addCookie opts
39
- end
40
-
41
- #
42
- # Get the cookie with the given name
43
- #
44
- # @param [String] name the name of the cookie
45
- # @return [Hash, nil] the cookie, or nil if it wasn't found.
46
- #
47
-
48
- def cookie_named(name)
49
- all_cookies.find { |c| c[:name] == name }
50
- end
51
-
52
- #
53
- # Delete the cookie with the given name
54
- #
55
- # @param [String] name the name of the cookie to delete
56
- #
57
-
58
- def delete_cookie(name)
59
- @bridge.deleteCookie name
60
- end
61
-
62
- #
63
- # Delete all cookies
64
- #
65
-
66
- def delete_all_cookies
67
- @bridge.deleteAllCookies
68
- end
69
-
70
- #
71
- # Get all cookies
72
- #
73
- # @return [Array<Hash>] list of cookies
74
- #
75
-
76
- def all_cookies
77
- @bridge.getAllCookies.map do |cookie|
78
- {
79
- :name => cookie["name"],
80
- :value => cookie["value"],
81
- :path => cookie["path"],
82
- :domain => cookie["domain"] && strip_port(cookie["domain"]),
83
- :expires => cookie["expiry"] && datetime_at(cookie['expiry']),
84
- :secure => cookie["secure"]
85
- }
44
+ raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}"
86
45
  end
87
- end
88
-
89
- def timeouts
90
- @timeouts ||= Timeouts.new(@bridge)
91
- end
92
-
93
- #
94
- # @api beta This API may be changed or removed in a future release.
95
- #
96
-
97
- def logs
98
- @logs ||= Logs.new(@bridge)
99
- end
100
-
101
- #
102
- # @api beta This API may be changed or removed in a future release.
103
- #
104
46
 
105
- def window
106
- @window ||= Window.new(@bridge)
107
- end
108
-
109
- private
110
-
111
- SECONDS_PER_DAY = 86_400.0
112
-
113
- def datetime_at(int)
114
- DateTime.civil(1970) + (int / SECONDS_PER_DAY)
115
- end
116
-
117
- def seconds_from(obj)
118
- case obj
119
- when Time
120
- obj.to_f
121
- when DateTime
122
- (obj - DateTime.civil(1970)) * SECONDS_PER_DAY
123
- when Numeric
124
- obj
125
- else
126
- 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 }
127
49
  end
128
- end
129
-
130
- def strip_port(str)
131
- str.split(":", 2).first
132
- end
133
-
134
- end # Options
50
+ end # Options
51
+ end # Common
135
52
  end # WebDriver
136
53
  end # Selenium
@@ -1,75 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  require 'rbconfig'
2
21
  require 'socket'
3
22
 
4
23
  module Selenium
5
24
  module WebDriver
6
-
7
25
  # @api private
8
26
  module Platform
9
-
10
27
  module_function
11
28
 
12
29
  def home
13
- # jruby has an issue with ENV['HOME'] on Windows
14
- @home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
30
+ @home ||= Dir.home
15
31
  end
16
32
 
17
33
  def engine
18
- @engine ||= (
19
- if defined? RUBY_ENGINE
20
- RUBY_ENGINE.to_sym
21
- else
22
- :ruby
23
- end
24
- )
34
+ @engine ||= RUBY_ENGINE.to_sym
25
35
  end
26
36
 
27
37
  def os
28
- @os ||= (
29
- host_os = RbConfig::CONFIG['host_os']
30
- case host_os
31
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
32
- :windows
33
- when /darwin|mac os/
34
- :macosx
35
- when /linux/
36
- :linux
37
- when /solaris|bsd/
38
- :unix
39
- else
40
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
41
- end
42
- )
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
51
+ end
52
+
53
+ def ci
54
+ if ENV['TRAVIS']
55
+ :travis
56
+ elsif ENV['JENKINS']
57
+ :jenkins
58
+ elsif ENV['APPVEYOR']
59
+ :appveyor
60
+ end
43
61
  end
44
62
 
45
63
  def bitsize
46
- @bitsize ||= (
47
- if defined?(FFI::Platform::ADDRESS_SIZE)
48
- FFI::Platform::ADDRESS_SIZE
49
- elsif defined?(FFI)
50
- FFI.type_size(:pointer) == 4 ? 32 : 64
51
- elsif jruby?
52
- Integer(ENV_JAVA['sun.arch.data.model'])
53
- else
54
- 1.size == 4 ? 32 : 64
55
- end
56
- )
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
57
73
  end
58
74
 
59
75
  def jruby?
60
76
  engine == :jruby
61
77
  end
62
78
 
63
- def ironruby?
64
- engine == :ironruby
65
- end
66
-
67
- def ruby187?
68
- !!(RUBY_VERSION =~ /^1\.8\.7/)
69
- end
70
-
71
- def ruby19?
72
- !!(RUBY_VERSION =~ /^1\.9/)
79
+ def ruby_version
80
+ RUBY_VERSION
73
81
  end
74
82
 
75
83
  def windows?
@@ -84,65 +92,78 @@ module Selenium
84
92
  os == :linux
85
93
  end
86
94
 
95
+ def wsl?
96
+ return false unless linux?
97
+
98
+ File.read('/proc/version').include?('Microsoft')
99
+ end
100
+
87
101
  def cygwin?
88
- !!(RUBY_PLATFORM =~ /cygwin/)
102
+ RUBY_PLATFORM =~ /cygwin/
103
+ !Regexp.last_match.nil?
89
104
  end
90
105
 
91
106
  def null_device
92
- @null_device ||= (
93
- if defined?(File::NULL)
94
- File::NULL
95
- else
96
- Platform.windows? ? 'NUL' : '/dev/null'
97
- end
98
- )
107
+ File::NULL
99
108
  end
100
109
 
101
110
  def wrap_in_quotes_if_necessary(str)
102
- windows? && !cygwin? ? %{"#{str}"} : str
111
+ windows? && !cygwin? ? %("#{str}") : str
103
112
  end
104
113
 
105
- def cygwin_path(path, opts = {})
114
+ def cygwin_path(path, **opts)
106
115
  flags = []
107
- opts.each { |k,v| flags << "--#{k}" if v }
116
+ opts.each { |k, v| flags << "--#{k}" if v }
108
117
 
109
118
  `cygpath #{flags.join ' '} "#{path}"`.strip
110
119
  end
111
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
+
112
129
  def make_writable(file)
113
- File.chmod 0766, file
130
+ File.chmod 0o766, file
114
131
  end
115
132
 
116
133
  def assert_file(path)
117
- unless File.file? path
118
- raise Error::WebDriverError, "not a file: #{path.inspect}"
119
- end
134
+ return if File.file? path
135
+
136
+ raise Error::WebDriverError, "not a file: #{path.inspect}"
120
137
  end
121
138
 
122
139
  def assert_executable(path)
123
140
  assert_file(path)
124
141
 
125
- unless File.executable? path
126
- raise Error::WebDriverError, "not executable: #{path.inspect}"
127
- end
142
+ return if File.executable? path
143
+
144
+ raise Error::WebDriverError, "not executable: #{path.inspect}"
128
145
  end
129
146
 
130
- def exit_hook(&blk)
147
+ def exit_hook
131
148
  pid = Process.pid
132
149
 
133
- at_exit do
134
- yield if Process.pid == pid
135
- end
150
+ at_exit { yield if Process.pid == pid }
136
151
  end
137
152
 
138
153
  def find_binary(*binary_names)
139
154
  paths = ENV['PATH'].split(File::PATH_SEPARATOR)
140
- 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
141
160
 
142
161
  binary_names.each do |binary_name|
143
162
  paths.each do |path|
144
- exe = File.join(path, binary_name)
145
- return exe if File.executable?(exe)
163
+ full_path = File.join(path, binary_name)
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
146
167
  end
147
168
  end
148
169
 
@@ -151,8 +172,9 @@ module Selenium
151
172
 
152
173
  def find_in_program_files(*binary_names)
153
174
  paths = [
154
- ENV['PROGRAMFILES'] || "\\Program Files",
155
- ENV['ProgramFiles(x86)'] || "\\Program Files (x86)"
175
+ ENV['PROGRAMFILES'] || '\\Program Files',
176
+ ENV['ProgramFiles(x86)'] || '\\Program Files (x86)',
177
+ ENV['ProgramW6432'] || '\\Program Files'
156
178
  ]
157
179
 
158
180
  paths.each do |root|
@@ -166,13 +188,11 @@ module Selenium
166
188
  end
167
189
 
168
190
  def localhost
169
- info = Socket.getaddrinfo "localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM
191
+ info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM
170
192
 
171
- if info.empty?
172
- raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
173
- end
193
+ return info[0][3] unless info.empty?
174
194
 
175
- info[0][3]
195
+ raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
176
196
  end
177
197
 
178
198
  def ip
@@ -192,27 +212,11 @@ module Selenium
192
212
  end
193
213
 
194
214
  def interfaces
195
- interfaces = Socket.getaddrinfo("localhost", 8080).map { |e| e[3] }
196
- 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]
197
217
 
198
218
  interfaces.compact.uniq
199
219
  end
200
-
201
220
  end # Platform
202
221
  end # WebDriver
203
222
  end # Selenium
204
-
205
- if __FILE__ == $0
206
- p :engine => Selenium::WebDriver::Platform.engine,
207
- :os => Selenium::WebDriver::Platform.os,
208
- :ruby187? => Selenium::WebDriver::Platform.ruby187?,
209
- :ruby19? => Selenium::WebDriver::Platform.ruby19?,
210
- :jruby? => Selenium::WebDriver::Platform.jruby?,
211
- :windows? => Selenium::WebDriver::Platform.windows?,
212
- :home => Selenium::WebDriver::Platform.home,
213
- :bitsize => Selenium::WebDriver::Platform.bitsize,
214
- :localhost => Selenium::WebDriver::Platform.localhost,
215
- :ip => Selenium::WebDriver::Platform.ip,
216
- :interfaces => Selenium::WebDriver::Platform.interfaces,
217
- :null_device => Selenium::WebDriver::Platform.null_device
218
- end
@@ -1,3 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
22
  class PortProber
@@ -6,28 +25,17 @@ module Selenium
6
25
  port
7
26
  end
8
27
 
9
- def self.random
10
- # TODO: Avoid this
11
- #
12
- # (a) should pick a port that's guaranteed to be free on all interfaces
13
- # (b) should pick a random port outside the ephemeral port range
14
- #
15
- server = TCPServer.new(Platform.localhost, 0)
16
- port = server.addr[1]
17
- server.close
18
-
19
- port
20
- end
21
-
22
- IGNORED_ERRORS = [Errno::EADDRNOTAVAIL]
23
- 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
24
32
 
25
33
  def self.free?(port)
26
34
  Platform.interfaces.each do |host|
27
35
  begin
28
36
  TCPServer.new(host, port).close
29
37
  rescue *IGNORED_ERRORS => ex
30
- $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})")
31
39
  # ignored - some machines appear unable to bind to some of their interfaces
32
40
  end
33
41
  end
@@ -36,7 +44,6 @@ module Selenium
36
44
  rescue SocketError, Errno::EADDRINUSE
37
45
  false
38
46
  end
39
-
40
47
  end # PortProber
41
48
  end # WebDriver
42
49
  end # Selenium