selenium-webdriver 3.142.7 → 4.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +685 -5
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/NOTICE +2 -0
  6. data/README.md +4 -5
  7. data/bin/linux/selenium-manager +0 -0
  8. data/bin/macos/selenium-manager +0 -0
  9. data/bin/windows/selenium-manager.exe +0 -0
  10. data/lib/selenium/server.rb +93 -90
  11. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +77 -78
  14. data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
  15. data/lib/selenium/webdriver/atoms.rb +5 -3
  16. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  17. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  18. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  19. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  20. data/lib/selenium/webdriver/bidi/log/filter_by.rb +40 -0
  21. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  22. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  23. data/lib/selenium/webdriver/bidi/log_inspector.rb +143 -0
  24. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  25. data/lib/selenium/webdriver/bidi/session.rb +51 -0
  26. data/lib/selenium/webdriver/{common/keyboard.rb → bidi.rb} +21 -35
  27. data/lib/selenium/webdriver/chrome/driver.rb +9 -86
  28. data/lib/selenium/webdriver/chrome/features.rb +48 -0
  29. data/lib/selenium/webdriver/chrome/options.rb +9 -158
  30. data/lib/selenium/webdriver/chrome/profile.rb +3 -80
  31. data/lib/selenium/webdriver/chrome/service.rb +7 -29
  32. data/lib/selenium/webdriver/chrome.rb +5 -20
  33. data/lib/selenium/webdriver/chromium/driver.rb +60 -0
  34. data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +48 -17
  35. data/lib/selenium/webdriver/chromium/options.rb +243 -0
  36. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  37. data/lib/selenium/webdriver/chromium.rb +29 -0
  38. data/lib/selenium/webdriver/common/action_builder.rb +126 -238
  39. data/lib/selenium/webdriver/common/child_process.rb +124 -0
  40. data/lib/selenium/webdriver/common/driver.rb +82 -43
  41. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/{has_location.rb → full_page_screenshot.rb} +13 -11
  43. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +49 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +87 -0
  46. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +9 -9
  47. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +86 -0
  48. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +36 -0
  49. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +42 -0
  50. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +41 -0
  52. data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
  53. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +36 -0
  54. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  55. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
  56. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +16 -1
  57. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +69 -0
  58. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -13
  59. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +75 -0
  60. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  61. data/lib/selenium/webdriver/common/driver_finder.rb +45 -0
  62. data/lib/selenium/webdriver/common/element.rb +89 -29
  63. data/lib/selenium/webdriver/common/error.rb +53 -194
  64. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  65. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  66. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
  67. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  68. data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
  69. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  70. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  71. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  72. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +71 -82
  73. data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
  74. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  75. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  76. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  77. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  78. data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
  79. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  80. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  81. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
  82. data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
  83. data/lib/selenium/webdriver/common/keys.rb +1 -0
  84. data/lib/selenium/webdriver/common/local_driver.rb +46 -0
  85. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  86. data/lib/selenium/webdriver/common/logger.rb +119 -19
  87. data/lib/selenium/webdriver/common/manager.rb +11 -38
  88. data/lib/selenium/webdriver/common/options.rb +154 -23
  89. data/lib/selenium/webdriver/common/platform.rb +15 -52
  90. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  91. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  92. data/lib/selenium/webdriver/common/proxy.rb +8 -5
  93. data/lib/selenium/webdriver/common/search_context.rb +7 -9
  94. data/lib/selenium/webdriver/common/selenium_manager.rb +140 -0
  95. data/lib/selenium/webdriver/common/service.rb +26 -143
  96. data/lib/selenium/webdriver/common/service_manager.rb +144 -0
  97. data/lib/selenium/webdriver/common/shadow_root.rb +86 -0
  98. data/lib/selenium/webdriver/common/socket_lock.rb +4 -4
  99. data/lib/selenium/webdriver/common/socket_poller.rb +4 -4
  100. data/lib/selenium/webdriver/common/takes_screenshot.rb +65 -0
  101. data/lib/selenium/webdriver/common/target_locator.rb +31 -4
  102. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  103. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
  104. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
  105. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
  106. data/lib/selenium/webdriver/common/wait.rb +1 -1
  107. data/lib/selenium/webdriver/common/websocket_connection.rb +164 -0
  108. data/lib/selenium/webdriver/common/window.rb +6 -10
  109. data/lib/selenium/webdriver/common/zipper.rb +4 -10
  110. data/lib/selenium/webdriver/common.rb +43 -20
  111. data/lib/selenium/webdriver/devtools/console_event.rb +36 -0
  112. data/lib/selenium/webdriver/devtools/exception_event.rb +34 -0
  113. data/lib/selenium/webdriver/devtools/mutation_event.rb +35 -0
  114. data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
  115. data/lib/selenium/webdriver/devtools/pinned_script.rb +57 -0
  116. data/lib/selenium/webdriver/devtools/request.rb +65 -0
  117. data/lib/selenium/webdriver/devtools/response.rb +64 -0
  118. data/lib/selenium/webdriver/devtools.rb +96 -0
  119. data/lib/selenium/webdriver/edge/driver.rb +11 -27
  120. data/lib/selenium/webdriver/edge/features.rb +48 -0
  121. data/lib/selenium/webdriver/edge/options.rb +18 -43
  122. data/lib/selenium/webdriver/edge/profile.rb +33 -0
  123. data/lib/selenium/webdriver/edge/service.rb +8 -23
  124. data/lib/selenium/webdriver/edge.rb +11 -16
  125. data/lib/selenium/webdriver/firefox/driver.rb +38 -19
  126. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  127. data/lib/selenium/webdriver/firefox/features.rb +70 -0
  128. data/lib/selenium/webdriver/firefox/options.rb +73 -61
  129. data/lib/selenium/webdriver/firefox/profile.rb +20 -72
  130. data/lib/selenium/webdriver/firefox/service.rb +3 -25
  131. data/lib/selenium/webdriver/firefox/util.rb +1 -1
  132. data/lib/selenium/webdriver/firefox.rb +17 -28
  133. data/lib/selenium/webdriver/ie/driver.rb +5 -45
  134. data/lib/selenium/webdriver/ie/features.rb +34 -0
  135. data/lib/selenium/webdriver/ie/options.rb +14 -44
  136. data/lib/selenium/webdriver/ie/service.rb +3 -27
  137. data/lib/selenium/webdriver/ie.rb +4 -16
  138. data/lib/selenium/webdriver/remote/bridge/commands.rb +164 -0
  139. data/lib/selenium/webdriver/remote/bridge.rb +574 -88
  140. data/lib/selenium/webdriver/remote/capabilities.rb +144 -158
  141. data/lib/selenium/webdriver/remote/driver.rb +45 -14
  142. data/lib/selenium/webdriver/remote/features.rb +75 -0
  143. data/lib/selenium/webdriver/remote/http/common.rb +3 -8
  144. data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
  145. data/lib/selenium/webdriver/remote/http/default.rb +24 -33
  146. data/lib/selenium/webdriver/remote/response.rb +17 -49
  147. data/lib/selenium/webdriver/remote/server_error.rb +1 -1
  148. data/lib/selenium/webdriver/remote.rb +15 -12
  149. data/lib/selenium/webdriver/safari/driver.rb +7 -29
  150. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +7 -5
  151. data/lib/selenium/webdriver/safari/options.rb +12 -27
  152. data/lib/selenium/webdriver/safari/service.rb +13 -11
  153. data/lib/selenium/webdriver/safari.rb +14 -20
  154. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  155. data/lib/selenium/webdriver/support/color.rb +24 -24
  156. data/lib/selenium/webdriver/support/event_firing_bridge.rb +5 -5
  157. data/lib/selenium/webdriver/support/guards/guard.rb +90 -0
  158. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +21 -20
  159. data/lib/selenium/webdriver/support/guards.rb +95 -0
  160. data/lib/selenium/webdriver/support/relative_locator.rb +50 -0
  161. data/lib/selenium/webdriver/support/select.rb +6 -4
  162. data/lib/selenium/webdriver/support.rb +1 -0
  163. data/lib/selenium/webdriver/version.rb +1 -1
  164. data/lib/selenium/webdriver.rb +19 -17
  165. data/selenium-webdriver.gemspec +36 -18
  166. metadata +161 -91
  167. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  168. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +0 -58
  169. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  170. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  171. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  172. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  173. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  174. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  175. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  176. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  177. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  178. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  179. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  180. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  181. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  182. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  183. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
  184. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  185. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  186. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  187. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  188. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -30,6 +30,7 @@ module Selenium
30
30
 
31
31
  class Driver
32
32
  include SearchContext
33
+ include TakesScreenshot
33
34
 
34
35
  class << self
35
36
  #
@@ -43,19 +44,17 @@ module Selenium
43
44
  def for(browser, opts = {})
44
45
  case browser
45
46
  when :chrome
46
- Chrome::Driver.new(opts)
47
+ Chrome::Driver.new(**opts)
47
48
  when :internet_explorer, :ie
48
- IE::Driver.new(opts)
49
+ IE::Driver.new(**opts)
49
50
  when :safari
50
- Safari::Driver.new(opts)
51
- when :phantomjs
52
- PhantomJS::Driver.new(opts)
51
+ Safari::Driver.new(**opts)
53
52
  when :firefox, :ff
54
- Firefox::Driver.new(opts)
55
- when :edge
56
- Edge::Driver.new(opts)
53
+ Firefox::Driver.new(**opts)
54
+ when :edge, :microsoftedge, :msedge
55
+ Edge::Driver.new(**opts)
57
56
  when :remote
58
- Remote::Driver.new(opts)
57
+ Remote::Driver.new(**opts)
59
58
  else
60
59
  raise ArgumentError, "unknown driver: #{browser.inspect}"
61
60
  end
@@ -69,13 +68,27 @@ module Selenium
69
68
  # @api private
70
69
  #
71
70
 
72
- def initialize(bridge, listener: nil)
73
- @bridge = bridge
74
- @bridge = Support::EventFiringBridge.new(bridge, listener) if listener
71
+ def initialize(bridge: nil, listener: nil, **opts)
72
+ @devtools = nil
73
+ @bidi = nil
74
+ bridge ||= create_bridge(**opts)
75
+ add_extensions(bridge.browser)
76
+ @bridge = listener ? Support::EventFiringBridge.new(bridge, listener) : bridge
75
77
  end
76
78
 
77
79
  def inspect
78
- format '#<%<class>s:0x%<hash>x browser=%<browser>s>', class: self.class, hash: hash * 2, browser: bridge.browser.inspect
80
+ format '#<%<class>s:0x%<hash>x browser=%<browser>s>', class: self.class, hash: hash * 2,
81
+ browser: bridge.browser.inspect
82
+ end
83
+
84
+ #
85
+ # information about whether a remote end is in a state in which it can create new sessions,
86
+ # and may include additional meta information.
87
+ #
88
+ # @return [Hash]
89
+ #
90
+ def status
91
+ @bridge.status
79
92
  end
80
93
 
81
94
  #
@@ -106,20 +119,12 @@ module Selenium
106
119
  end
107
120
 
108
121
  #
109
- # @return [ActionBuilder, W3CActionBuilder]
110
- # @see ActionBuilder, W3CActionBuilder
122
+ # @return [ActionBuilder]
123
+ # @see ActionBuilder
111
124
  #
112
125
 
113
- def action
114
- bridge.action
115
- end
116
-
117
- def mouse
118
- bridge.mouse
119
- end
120
-
121
- def keyboard
122
- bridge.keyboard
126
+ def action(**opts)
127
+ bridge.action(**opts)
123
128
  end
124
129
 
125
130
  #
@@ -166,6 +171,10 @@ module Selenium
166
171
 
167
172
  def quit
168
173
  bridge.quit
174
+ ensure
175
+ @service_manager&.stop
176
+ @devtools&.close
177
+ @bidi&.close
169
178
  end
170
179
 
171
180
  #
@@ -173,7 +182,10 @@ module Selenium
173
182
  #
174
183
 
175
184
  def close
176
- bridge.close
185
+ # If no top-level browsing contexts are open after calling close,
186
+ # it indicates that the WebDriver session is closed.
187
+ # If the WebDriver session is closed, the BiDi session also needs to be closed.
188
+ bridge.close.tap { |handles| @bidi&.close if handles&.empty? }
177
189
  end
178
190
 
179
191
  #
@@ -232,25 +244,34 @@ module Selenium
232
244
  bridge.execute_async_script(script, *args)
233
245
  end
234
246
 
247
+ #
248
+ # @return [VirtualAuthenticator]
249
+ # @see VirtualAuthenticator
250
+ #
251
+
252
+ def add_virtual_authenticator(options)
253
+ bridge.add_virtual_authenticator(options)
254
+ end
255
+
235
256
  #-------------------------------- sugar --------------------------------
236
257
 
237
258
  #
238
259
  # driver.first(id: 'foo')
239
260
  #
240
261
 
241
- alias_method :first, :find_element
262
+ alias first find_element
242
263
 
243
264
  #
244
265
  # driver.all(class: 'bar') #=> [#<WebDriver::Element:0x1011c3b88, ...]
245
266
  #
246
267
 
247
- alias_method :all, :find_elements
268
+ alias all find_elements
248
269
 
249
270
  #
250
271
  # driver.script('function() { ... };')
251
272
  #
252
273
 
253
- alias_method :script, :execute_script
274
+ alias script execute_script
254
275
 
255
276
  # Get the first element matching the given selector. If given a
256
277
  # String or Symbol, it will be used as the id of the element.
@@ -271,7 +292,7 @@ module Selenium
271
292
  end
272
293
 
273
294
  def browser
274
- bridge.browser
295
+ bridge&.browser
275
296
  end
276
297
 
277
298
  def capabilities
@@ -283,25 +304,43 @@ module Selenium
283
304
  # @see SearchContext
284
305
  #
285
306
 
286
- def ref; end
307
+ def ref
308
+ [:driver, nil]
309
+ end
287
310
 
288
311
  private
289
312
 
290
313
  attr_reader :bridge
291
314
 
292
- def service_url(opts)
293
- @service = opts.delete(:service)
294
- %i[driver_opts driver_path port].each do |key|
295
- next unless opts.key? key
296
-
297
- WebDriver.logger.deprecate(":#{key}", ':service with an instance of Selenium::WebDriver::Service')
315
+ def create_bridge(caps:, url:, http_client: nil)
316
+ Remote::Bridge.new(http_client: http_client, url: url).tap do |bridge|
317
+ bridge.create_session(caps)
298
318
  end
299
- @service ||= Service.send(browser,
300
- args: opts.delete(:driver_opts),
301
- path: opts.delete(:driver_path),
302
- port: opts.delete(:port))
303
- @service.start
304
- @service.uri
319
+ end
320
+
321
+ def service_url(service)
322
+ @service_manager = service.launch
323
+ @service_manager.uri
324
+ end
325
+
326
+ def screenshot
327
+ bridge.screenshot
328
+ end
329
+
330
+ def add_extensions(browser)
331
+ extensions = case browser
332
+ when :chrome, :msedge
333
+ Chromium::Driver::EXTENSIONS
334
+ when :firefox
335
+ Firefox::Driver::EXTENSIONS
336
+ when :safari, :safari_technology_preview
337
+ Safari::Driver::EXTENSIONS
338
+ when :ie, :internet_explorer
339
+ IE::Driver::EXTENSIONS
340
+ else
341
+ []
342
+ end
343
+ extensions.each { |extension| extend extension }
305
344
  end
306
345
  end # Driver
307
346
  end # WebDriver
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module DownloadsFiles
24
-
25
24
  #
26
25
  # Sets download path for Chromium.
27
26
  #
@@ -38,7 +37,6 @@ module Selenium
38
37
  }
39
38
  @bridge.send_command(params)
40
39
  end
41
-
42
40
  end # DownloadsFiles
43
41
  end # DriverExtensions
44
42
  end # WebDriver
@@ -20,21 +20,23 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
- module HasLocation
24
- def location
25
- @bridge.location
26
- end
27
-
28
- def location=(loc)
29
- raise TypeError, "expected #{Location}, got #{loc.inspect}:#{loc.class}" unless loc.is_a?(Location)
23
+ module FullPageScreenshot
24
+ #
25
+ # Save a PNG screenshot of the full page to the given path
26
+ #
27
+ # @api public
28
+ #
30
29
 
31
- @bridge.set_location loc.latitude, loc.longitude, loc.altitude
30
+ def save_full_page_screenshot(path)
31
+ save_screenshot(path, full_page: true)
32
32
  end
33
33
 
34
- def set_location(lat, lon, alt)
35
- self.location = Location.new(Float(lat), Float(lon), Float(alt))
34
+ private
35
+
36
+ def full_screenshot
37
+ @bridge.full_screenshot
36
38
  end
37
- end # HasLocation
39
+ end # FullPageScreenshot
38
40
  end # DriverExtensions
39
41
  end # WebDriver
40
42
  end # Selenium
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module HasAddons
24
-
25
24
  #
26
25
  # Installs addon.
27
26
  #
@@ -43,7 +42,6 @@ module Selenium
43
42
  def uninstall_addon(id)
44
43
  @bridge.uninstall_addon(id)
45
44
  end
46
-
47
45
  end # HasAddons
48
46
  end # DriverExtensions
49
47
  end # WebDriver
@@ -0,0 +1,49 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasApplePermissions
24
+ #
25
+ # Returns permissions.
26
+ #
27
+ # @return [Hash]
28
+ #
29
+
30
+ def permissions
31
+ @bridge.permissions
32
+ end
33
+
34
+ #
35
+ # Sets permissions.
36
+ #
37
+ # @example
38
+ # driver.permissions = {'getUserMedia' => true}
39
+ #
40
+ # @param [Hash<Symbol, Boolean>] permissions
41
+ #
42
+
43
+ def permissions=(permissions)
44
+ @bridge.permissions = permissions
45
+ end
46
+ end # HasPermissions
47
+ end # DriverExtensions
48
+ end # WebDriver
49
+ end # Selenium
@@ -0,0 +1,87 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasAuthentication
24
+ #
25
+ # Registers basic authentication handler which is automatically
26
+ # used whenever browser gets an authentication required response.
27
+ # This currently relies on DevTools so is only supported in
28
+ # Chromium browsers.
29
+ #
30
+ # @example Authenticate any request
31
+ # driver.register(username: 'admin', password: '123456')
32
+ #
33
+ # @example Authenticate based on URL
34
+ # driver.register(username: 'admin1', password: '123456', uri: /mysite1\.com/)
35
+ # driver.register(username: 'admin2', password: '123456', uri: /mysite2\.com/)
36
+ #
37
+ # @param [String] username
38
+ # @param [String] password
39
+ # @param [Regexp] uri to associate the credentials with
40
+ #
41
+
42
+ def register(username:, password:, uri: //)
43
+ auth_handlers << {username: username, password: password, uri: uri}
44
+
45
+ devtools.network.set_cache_disabled(cache_disabled: true)
46
+ devtools.fetch.on(:auth_required) do |params|
47
+ authenticate(params['requestId'], params.dig('request', 'url'))
48
+ end
49
+ devtools.fetch.on(:request_paused) do |params|
50
+ devtools.fetch.continue_request(request_id: params['requestId'])
51
+ end
52
+ devtools.fetch.enable(handle_auth_requests: true)
53
+ end
54
+
55
+ private
56
+
57
+ def auth_handlers
58
+ @auth_handlers ||= []
59
+ end
60
+
61
+ def authenticate(request_id, url)
62
+ credentials = auth_handlers.find do |handler|
63
+ url.match?(handler[:uri])
64
+ end
65
+
66
+ if credentials
67
+ devtools.fetch.continue_with_auth(
68
+ request_id: request_id,
69
+ auth_challenge_response: {
70
+ response: 'ProvideCredentials',
71
+ username: credentials[:username],
72
+ password: credentials[:password]
73
+ }
74
+ )
75
+ else
76
+ devtools.fetch.continue_with_auth(
77
+ request_id: request_id,
78
+ auth_challenge_response: {
79
+ response: 'CancelAuth'
80
+ }
81
+ )
82
+ end
83
+ end
84
+ end # HasAuthentication
85
+ end # DriverExtensions
86
+ end # WebDriver
87
+ end # Selenium
@@ -20,17 +20,17 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
- module HasTouchScreen
24
- def touch
25
- TouchActionBuilder.new Mouse.new(@bridge), Keyboard.new(@bridge), touch_screen
26
- end
27
-
28
- private
23
+ module HasBiDi
24
+ #
25
+ # Retrieves WebDriver BiDi connection.
26
+ #
27
+ # @return [BiDi]
28
+ #
29
29
 
30
- def touch_screen
31
- TouchScreen.new @bridge
30
+ def bidi
31
+ @bidi ||= Selenium::WebDriver::BiDi.new(url: capabilities[:web_socket_url])
32
32
  end
33
- end # HasTouchScreen
33
+ end # HasBiDi
34
34
  end # DriverExtensions
35
35
  end # WebDriver
36
36
  end # Selenium
@@ -0,0 +1,86 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasCasting
24
+ #
25
+ # What devices ("sinks") are available to be cast to.
26
+ #
27
+ # @return [Array] list of sinks available for casting with id and name values
28
+ #
29
+
30
+ def cast_sinks
31
+ @bridge.cast_sinks
32
+ end
33
+
34
+ #
35
+ # Sets a specific sink, using its name, as a Cast session receiver target.
36
+ #
37
+ # @param [String] name the sink to use as the target
38
+ #
39
+
40
+ def cast_sink_to_use=(name)
41
+ @bridge.cast_sink_to_use = name
42
+ end
43
+
44
+ #
45
+ # Starts a tab mirroring session on a specific receiver target.
46
+ #
47
+ # @param [String] name the sink to use as the target
48
+ #
49
+
50
+ def start_cast_tab_mirroring(name)
51
+ @bridge.start_cast_tab_mirroring(name)
52
+ end
53
+
54
+ #
55
+ # Starts a tab mirroring session on a specific receiver target.
56
+ #
57
+ # @param [String] name the sink to use as the target
58
+ #
59
+
60
+ def start_cast_desktop_mirroring(name)
61
+ @bridge.start_cast_desktop_mirroring(name)
62
+ end
63
+
64
+ #
65
+ # Gets error messages when there is any issue in a Cast session.
66
+ #
67
+ # @return [String] the error message
68
+ #
69
+
70
+ def cast_issue_message
71
+ @bridge.cast_issue_message
72
+ end
73
+
74
+ #
75
+ # Stops the existing Cast session on a specific receiver target.
76
+ #
77
+ # @param [String] name the sink to stop the Cast session
78
+ #
79
+
80
+ def stop_casting(name)
81
+ @bridge.stop_casting(name)
82
+ end
83
+ end # HasCasting
84
+ end # DriverExtensions
85
+ end # WebDriver
86
+ end # Selenium
@@ -0,0 +1,36 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasCDP
24
+ #
25
+ # Returns network conditions.
26
+ #
27
+ # @return [Hash]
28
+ #
29
+
30
+ def execute_cdp(cmd, **params)
31
+ @bridge.send_command(cmd: cmd, params: params)
32
+ end
33
+ end # HasCDP
34
+ end # DriverExtensions
35
+ end # WebDriver
36
+ end # Selenium
@@ -0,0 +1,42 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasContext
24
+ #
25
+ # Sets the context that Selenium commands are running in using
26
+ # a `with` statement. The state of the context on the server is
27
+ # saved before entering the block, and restored upon exiting it.
28
+ #
29
+ # @param [String] value which context gets set (either 'chrome' or 'content')
30
+ #
31
+
32
+ def context=(value)
33
+ @bridge.context = value
34
+ end
35
+
36
+ def context
37
+ @bridge.context
38
+ end
39
+ end # HasContext
40
+ end # DriverExtensions
41
+ end # WebDriver
42
+ end # Selenium
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module HasDebugger
24
-
25
24
  #
26
25
  # Attaches debugger to session.
27
26
  #
@@ -35,7 +34,6 @@ module Selenium
35
34
  def attach_debugger
36
35
  @bridge.attach_debugger
37
36
  end
38
-
39
37
  end # HasDebugger
40
38
  end # DriverExtensions
41
39
  end # WebDriver
@@ -0,0 +1,41 @@
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
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasDevTools
24
+ #
25
+ # Retrieves connection to DevTools.
26
+ #
27
+ # @return [DevTools]
28
+ #
29
+
30
+ def devtools
31
+ @devtools ||= begin
32
+ require 'selenium/devtools'
33
+ Selenium::DevTools.version ||= devtools_version
34
+ Selenium::DevTools.load_version
35
+ Selenium::WebDriver::DevTools.new(url: devtools_url)
36
+ end
37
+ end
38
+ end # HasDevTools
39
+ end # DriverExtensions
40
+ end # WebDriver
41
+ end # Selenium