selenium-webdriver 4.0.0.beta1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +89 -0
  3. data/Gemfile +3 -1
  4. data/NOTICE +2 -0
  5. data/lib/selenium/webdriver/atoms/findElements.js +77 -78
  6. data/lib/selenium/webdriver/atoms/getAttribute.js +64 -68
  7. data/lib/selenium/webdriver/atoms/isDisplayed.js +27 -27
  8. data/lib/selenium/webdriver/atoms/mutationListener.js +17 -0
  9. data/lib/selenium/webdriver/chrome/driver.rb +21 -18
  10. data/lib/selenium/webdriver/chrome/options.rb +1 -1
  11. data/lib/selenium/webdriver/chrome/profile.rb +5 -2
  12. data/lib/selenium/webdriver/chrome/service.rb +3 -1
  13. data/lib/selenium/webdriver/chrome.rb +1 -1
  14. data/lib/selenium/webdriver/common/driver.rb +23 -4
  15. data/lib/selenium/webdriver/{devtools/v87/schema.rb → common/driver_extensions/full_page_screenshot.rb} +16 -21
  16. data/lib/selenium/webdriver/{edge/bridge.rb → common/driver_extensions/has_cdp.rb} +12 -11
  17. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +6 -1
  18. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +1 -6
  19. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +4 -2
  20. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +67 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +77 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/prints_page.rb +28 -1
  23. data/lib/selenium/webdriver/common/element.rb +75 -17
  24. data/lib/selenium/webdriver/common/error.rb +12 -0
  25. data/lib/selenium/webdriver/common/interactions/interaction.rb +4 -1
  26. data/lib/selenium/webdriver/common/logger.rb +5 -2
  27. data/lib/selenium/webdriver/common/options.rb +62 -17
  28. data/lib/selenium/webdriver/common/proxy.rb +6 -3
  29. data/lib/selenium/webdriver/common/search_context.rb +4 -1
  30. data/lib/selenium/webdriver/common/service.rb +1 -0
  31. data/lib/selenium/webdriver/common/shadow_root.rb +87 -0
  32. data/lib/selenium/webdriver/common/socket_poller.rb +19 -30
  33. data/lib/selenium/webdriver/common/takes_screenshot.rb +9 -6
  34. data/lib/selenium/webdriver/common.rb +5 -0
  35. data/lib/selenium/webdriver/{firefox/bridge.rb → devtools/pinned_script.rb} +28 -16
  36. data/lib/selenium/webdriver/devtools/{v87/console.rb → request.rb} +32 -34
  37. data/lib/selenium/webdriver/devtools.rb +35 -25
  38. data/lib/selenium/webdriver/edge/driver.rb +2 -6
  39. data/lib/selenium/webdriver/edge/options.rb +0 -0
  40. data/lib/selenium/webdriver/edge/profile.rb +0 -0
  41. data/lib/selenium/webdriver/edge.rb +1 -1
  42. data/lib/selenium/webdriver/firefox/driver.rb +14 -13
  43. data/lib/selenium/webdriver/firefox/features.rb +6 -1
  44. data/lib/selenium/webdriver/firefox.rb +5 -1
  45. data/lib/selenium/webdriver/ie/driver.rb +1 -1
  46. data/lib/selenium/webdriver/ie/options.rb +3 -1
  47. data/lib/selenium/webdriver/ie/service.rb +4 -2
  48. data/lib/selenium/webdriver/remote/bridge.rb +65 -14
  49. data/lib/selenium/webdriver/remote/capabilities.rb +105 -52
  50. data/lib/selenium/webdriver/remote/commands.rb +5 -0
  51. data/lib/selenium/webdriver/remote/driver.rb +8 -4
  52. data/lib/selenium/webdriver/remote/http/common.rb +0 -5
  53. data/lib/selenium/webdriver/remote/http/default.rb +5 -3
  54. data/lib/selenium/webdriver/remote.rb +1 -1
  55. data/lib/selenium/webdriver/safari/driver.rb +3 -7
  56. data/lib/selenium/webdriver/safari.rb +1 -1
  57. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +63 -0
  58. data/lib/selenium/webdriver/support/cdp_client_generator.rb +108 -0
  59. data/lib/selenium/webdriver/support/event_firing_bridge.rb +2 -2
  60. data/lib/selenium/webdriver/support/guards/guard.rb +89 -0
  61. data/lib/selenium/webdriver/{devtools/v87/system_info.rb → support/guards/guard_condition.rb} +24 -24
  62. data/lib/selenium/webdriver/support/guards.rb +95 -0
  63. data/lib/selenium/webdriver/support/select.rb +2 -2
  64. data/lib/selenium/webdriver/version.rb +1 -1
  65. data/lib/selenium/webdriver.rb +0 -1
  66. data/selenium-webdriver.gemspec +21 -8
  67. metadata +62 -233
  68. data/lib/selenium/webdriver/chrome/bridge.rb +0 -66
  69. data/lib/selenium/webdriver/devtools/v85/accessibility.rb +0 -64
  70. data/lib/selenium/webdriver/devtools/v85/animation.rb +0 -100
  71. data/lib/selenium/webdriver/devtools/v85/application_cache.rb +0 -66
  72. data/lib/selenium/webdriver/devtools/v85/audits.rb +0 -63
  73. data/lib/selenium/webdriver/devtools/v85/background_service.rb +0 -69
  74. data/lib/selenium/webdriver/devtools/v85/browser.rb +0 -125
  75. data/lib/selenium/webdriver/devtools/v85/cache_storage.rb +0 -75
  76. data/lib/selenium/webdriver/devtools/v85/cast.rb +0 -72
  77. data/lib/selenium/webdriver/devtools/v85/console.rb +0 -59
  78. data/lib/selenium/webdriver/devtools/v85/css.rb +0 -167
  79. data/lib/selenium/webdriver/devtools/v85/database.rb +0 -66
  80. data/lib/selenium/webdriver/devtools/v85/debugger.rb +0 -231
  81. data/lib/selenium/webdriver/devtools/v85/device_orientation.rb +0 -55
  82. data/lib/selenium/webdriver/devtools/v85/dom.rb +0 -322
  83. data/lib/selenium/webdriver/devtools/v85/dom_debugger.rb +0 -95
  84. data/lib/selenium/webdriver/devtools/v85/dom_snapshot.rb +0 -67
  85. data/lib/selenium/webdriver/devtools/v85/dom_storage.rb +0 -81
  86. data/lib/selenium/webdriver/devtools/v85/emulation.rb +0 -182
  87. data/lib/selenium/webdriver/devtools/v85/fetch.rb +0 -99
  88. data/lib/selenium/webdriver/devtools/v85/headless_experimental.rb +0 -63
  89. data/lib/selenium/webdriver/devtools/v85/heap_profiler.rb +0 -109
  90. data/lib/selenium/webdriver/devtools/v85/indexed_db.rb +0 -102
  91. data/lib/selenium/webdriver/devtools/v85/input.rb +0 -143
  92. data/lib/selenium/webdriver/devtools/v85/inspector.rb +0 -57
  93. data/lib/selenium/webdriver/devtools/v85/io.rb +0 -61
  94. data/lib/selenium/webdriver/devtools/v85/layer_tree.rb +0 -97
  95. data/lib/selenium/webdriver/devtools/v85/log.rb +0 -68
  96. data/lib/selenium/webdriver/devtools/v85/media.rb +0 -59
  97. data/lib/selenium/webdriver/devtools/v85/memory.rb +0 -88
  98. data/lib/selenium/webdriver/devtools/v85/network.rb +0 -230
  99. data/lib/selenium/webdriver/devtools/v85/overlay.rb +0 -160
  100. data/lib/selenium/webdriver/devtools/v85/page.rb +0 -376
  101. data/lib/selenium/webdriver/devtools/v85/performance.rb +0 -65
  102. data/lib/selenium/webdriver/devtools/v85/profiler.rb +0 -113
  103. data/lib/selenium/webdriver/devtools/v85/runtime.rb +0 -196
  104. data/lib/selenium/webdriver/devtools/v85/schema.rb +0 -48
  105. data/lib/selenium/webdriver/devtools/v85/security.rb +0 -73
  106. data/lib/selenium/webdriver/devtools/v85/service_worker.rb +0 -118
  107. data/lib/selenium/webdriver/devtools/v85/storage.rb +0 -97
  108. data/lib/selenium/webdriver/devtools/v85/system_info.rb +0 -52
  109. data/lib/selenium/webdriver/devtools/v85/target.rb +0 -145
  110. data/lib/selenium/webdriver/devtools/v85/tethering.rb +0 -57
  111. data/lib/selenium/webdriver/devtools/v85/tracing.rb +0 -78
  112. data/lib/selenium/webdriver/devtools/v85/web_audio.rb +0 -72
  113. data/lib/selenium/webdriver/devtools/v85/web_authn.rb +0 -96
  114. data/lib/selenium/webdriver/devtools/v86/accessibility.rb +0 -64
  115. data/lib/selenium/webdriver/devtools/v86/animation.rb +0 -100
  116. data/lib/selenium/webdriver/devtools/v86/application_cache.rb +0 -66
  117. data/lib/selenium/webdriver/devtools/v86/audits.rb +0 -63
  118. data/lib/selenium/webdriver/devtools/v86/background_service.rb +0 -69
  119. data/lib/selenium/webdriver/devtools/v86/browser.rb +0 -125
  120. data/lib/selenium/webdriver/devtools/v86/cache_storage.rb +0 -75
  121. data/lib/selenium/webdriver/devtools/v86/cast.rb +0 -72
  122. data/lib/selenium/webdriver/devtools/v86/console.rb +0 -59
  123. data/lib/selenium/webdriver/devtools/v86/css.rb +0 -181
  124. data/lib/selenium/webdriver/devtools/v86/database.rb +0 -66
  125. data/lib/selenium/webdriver/devtools/v86/debugger.rb +0 -233
  126. data/lib/selenium/webdriver/devtools/v86/device_orientation.rb +0 -55
  127. data/lib/selenium/webdriver/devtools/v86/dom.rb +0 -329
  128. data/lib/selenium/webdriver/devtools/v86/dom_debugger.rb +0 -95
  129. data/lib/selenium/webdriver/devtools/v86/dom_snapshot.rb +0 -67
  130. data/lib/selenium/webdriver/devtools/v86/dom_storage.rb +0 -81
  131. data/lib/selenium/webdriver/devtools/v86/emulation.rb +0 -193
  132. data/lib/selenium/webdriver/devtools/v86/fetch.rb +0 -99
  133. data/lib/selenium/webdriver/devtools/v86/headless_experimental.rb +0 -63
  134. data/lib/selenium/webdriver/devtools/v86/heap_profiler.rb +0 -109
  135. data/lib/selenium/webdriver/devtools/v86/indexed_db.rb +0 -102
  136. data/lib/selenium/webdriver/devtools/v86/input.rb +0 -143
  137. data/lib/selenium/webdriver/devtools/v86/inspector.rb +0 -57
  138. data/lib/selenium/webdriver/devtools/v86/io.rb +0 -61
  139. data/lib/selenium/webdriver/devtools/v86/layer_tree.rb +0 -97
  140. data/lib/selenium/webdriver/devtools/v86/log.rb +0 -68
  141. data/lib/selenium/webdriver/devtools/v86/media.rb +0 -59
  142. data/lib/selenium/webdriver/devtools/v86/memory.rb +0 -88
  143. data/lib/selenium/webdriver/devtools/v86/network.rb +0 -235
  144. data/lib/selenium/webdriver/devtools/v86/overlay.rb +0 -183
  145. data/lib/selenium/webdriver/devtools/v86/page.rb +0 -376
  146. data/lib/selenium/webdriver/devtools/v86/performance.rb +0 -65
  147. data/lib/selenium/webdriver/devtools/v86/profiler.rb +0 -113
  148. data/lib/selenium/webdriver/devtools/v86/runtime.rb +0 -196
  149. data/lib/selenium/webdriver/devtools/v86/schema.rb +0 -48
  150. data/lib/selenium/webdriver/devtools/v86/security.rb +0 -73
  151. data/lib/selenium/webdriver/devtools/v86/service_worker.rb +0 -118
  152. data/lib/selenium/webdriver/devtools/v86/storage.rb +0 -97
  153. data/lib/selenium/webdriver/devtools/v86/system_info.rb +0 -52
  154. data/lib/selenium/webdriver/devtools/v86/target.rb +0 -145
  155. data/lib/selenium/webdriver/devtools/v86/tethering.rb +0 -57
  156. data/lib/selenium/webdriver/devtools/v86/tracing.rb +0 -78
  157. data/lib/selenium/webdriver/devtools/v86/web_audio.rb +0 -72
  158. data/lib/selenium/webdriver/devtools/v86/web_authn.rb +0 -102
  159. data/lib/selenium/webdriver/devtools/v87/accessibility.rb +0 -73
  160. data/lib/selenium/webdriver/devtools/v87/animation.rb +0 -100
  161. data/lib/selenium/webdriver/devtools/v87/application_cache.rb +0 -66
  162. data/lib/selenium/webdriver/devtools/v87/audits.rb +0 -63
  163. data/lib/selenium/webdriver/devtools/v87/background_service.rb +0 -69
  164. data/lib/selenium/webdriver/devtools/v87/browser.rb +0 -125
  165. data/lib/selenium/webdriver/devtools/v87/cache_storage.rb +0 -75
  166. data/lib/selenium/webdriver/devtools/v87/cast.rb +0 -72
  167. data/lib/selenium/webdriver/devtools/v87/css.rb +0 -181
  168. data/lib/selenium/webdriver/devtools/v87/database.rb +0 -66
  169. data/lib/selenium/webdriver/devtools/v87/debugger.rb +0 -233
  170. data/lib/selenium/webdriver/devtools/v87/device_orientation.rb +0 -55
  171. data/lib/selenium/webdriver/devtools/v87/dom.rb +0 -329
  172. data/lib/selenium/webdriver/devtools/v87/dom_debugger.rb +0 -95
  173. data/lib/selenium/webdriver/devtools/v87/dom_snapshot.rb +0 -67
  174. data/lib/selenium/webdriver/devtools/v87/dom_storage.rb +0 -81
  175. data/lib/selenium/webdriver/devtools/v87/emulation.rb +0 -193
  176. data/lib/selenium/webdriver/devtools/v87/fetch.rb +0 -99
  177. data/lib/selenium/webdriver/devtools/v87/headless_experimental.rb +0 -63
  178. data/lib/selenium/webdriver/devtools/v87/heap_profiler.rb +0 -109
  179. data/lib/selenium/webdriver/devtools/v87/indexed_db.rb +0 -102
  180. data/lib/selenium/webdriver/devtools/v87/input.rb +0 -143
  181. data/lib/selenium/webdriver/devtools/v87/inspector.rb +0 -57
  182. data/lib/selenium/webdriver/devtools/v87/io.rb +0 -61
  183. data/lib/selenium/webdriver/devtools/v87/layer_tree.rb +0 -97
  184. data/lib/selenium/webdriver/devtools/v87/log.rb +0 -68
  185. data/lib/selenium/webdriver/devtools/v87/media.rb +0 -59
  186. data/lib/selenium/webdriver/devtools/v87/memory.rb +0 -88
  187. data/lib/selenium/webdriver/devtools/v87/network.rb +0 -247
  188. data/lib/selenium/webdriver/devtools/v87/overlay.rb +0 -183
  189. data/lib/selenium/webdriver/devtools/v87/page.rb +0 -376
  190. data/lib/selenium/webdriver/devtools/v87/performance.rb +0 -65
  191. data/lib/selenium/webdriver/devtools/v87/profiler.rb +0 -125
  192. data/lib/selenium/webdriver/devtools/v87/runtime.rb +0 -196
  193. data/lib/selenium/webdriver/devtools/v87/security.rb +0 -73
  194. data/lib/selenium/webdriver/devtools/v87/service_worker.rb +0 -118
  195. data/lib/selenium/webdriver/devtools/v87/storage.rb +0 -97
  196. data/lib/selenium/webdriver/devtools/v87/target.rb +0 -145
  197. data/lib/selenium/webdriver/devtools/v87/tethering.rb +0 -57
  198. data/lib/selenium/webdriver/devtools/v87/tracing.rb +0 -78
  199. data/lib/selenium/webdriver/devtools/v87/web_audio.rb +0 -72
  200. data/lib/selenium/webdriver/devtools/v87/web_authn.rb +0 -102
  201. data/lib/selenium/webdriver/devtools/v88/accessibility.rb +0 -73
  202. data/lib/selenium/webdriver/devtools/v88/animation.rb +0 -100
  203. data/lib/selenium/webdriver/devtools/v88/application_cache.rb +0 -66
  204. data/lib/selenium/webdriver/devtools/v88/audits.rb +0 -63
  205. data/lib/selenium/webdriver/devtools/v88/background_service.rb +0 -69
  206. data/lib/selenium/webdriver/devtools/v88/browser.rb +0 -130
  207. data/lib/selenium/webdriver/devtools/v88/cache_storage.rb +0 -75
  208. data/lib/selenium/webdriver/devtools/v88/cast.rb +0 -72
  209. data/lib/selenium/webdriver/devtools/v88/console.rb +0 -59
  210. data/lib/selenium/webdriver/devtools/v88/css.rb +0 -181
  211. data/lib/selenium/webdriver/devtools/v88/database.rb +0 -66
  212. data/lib/selenium/webdriver/devtools/v88/debugger.rb +0 -233
  213. data/lib/selenium/webdriver/devtools/v88/device_orientation.rb +0 -55
  214. data/lib/selenium/webdriver/devtools/v88/dom.rb +0 -329
  215. data/lib/selenium/webdriver/devtools/v88/dom_debugger.rb +0 -95
  216. data/lib/selenium/webdriver/devtools/v88/dom_snapshot.rb +0 -67
  217. data/lib/selenium/webdriver/devtools/v88/dom_storage.rb +0 -81
  218. data/lib/selenium/webdriver/devtools/v88/emulation.rb +0 -198
  219. data/lib/selenium/webdriver/devtools/v88/fetch.rb +0 -99
  220. data/lib/selenium/webdriver/devtools/v88/headless_experimental.rb +0 -63
  221. data/lib/selenium/webdriver/devtools/v88/heap_profiler.rb +0 -109
  222. data/lib/selenium/webdriver/devtools/v88/indexed_db.rb +0 -102
  223. data/lib/selenium/webdriver/devtools/v88/input.rb +0 -148
  224. data/lib/selenium/webdriver/devtools/v88/inspector.rb +0 -57
  225. data/lib/selenium/webdriver/devtools/v88/io.rb +0 -61
  226. data/lib/selenium/webdriver/devtools/v88/layer_tree.rb +0 -97
  227. data/lib/selenium/webdriver/devtools/v88/log.rb +0 -68
  228. data/lib/selenium/webdriver/devtools/v88/media.rb +0 -59
  229. data/lib/selenium/webdriver/devtools/v88/memory.rb +0 -88
  230. data/lib/selenium/webdriver/devtools/v88/network.rb +0 -247
  231. data/lib/selenium/webdriver/devtools/v88/overlay.rb +0 -183
  232. data/lib/selenium/webdriver/devtools/v88/page.rb +0 -376
  233. data/lib/selenium/webdriver/devtools/v88/performance.rb +0 -65
  234. data/lib/selenium/webdriver/devtools/v88/profiler.rb +0 -125
  235. data/lib/selenium/webdriver/devtools/v88/runtime.rb +0 -197
  236. data/lib/selenium/webdriver/devtools/v88/schema.rb +0 -48
  237. data/lib/selenium/webdriver/devtools/v88/security.rb +0 -73
  238. data/lib/selenium/webdriver/devtools/v88/service_worker.rb +0 -118
  239. data/lib/selenium/webdriver/devtools/v88/storage.rb +0 -103
  240. data/lib/selenium/webdriver/devtools/v88/system_info.rb +0 -52
  241. data/lib/selenium/webdriver/devtools/v88/target.rb +0 -145
  242. data/lib/selenium/webdriver/devtools/v88/tethering.rb +0 -57
  243. data/lib/selenium/webdriver/devtools/v88/tracing.rb +0 -79
  244. data/lib/selenium/webdriver/devtools/v88/web_audio.rb +0 -72
  245. data/lib/selenium/webdriver/devtools/v88/web_authn.rb +0 -102
  246. data/lib/selenium/webdriver/safari/bridge.rb +0 -51
  247. data/selenium_server_deploy.jar +0 -0
@@ -65,37 +65,26 @@ module Selenium
65
65
  arr << Errno::EALREADY if Platform.wsl?
66
66
  }.freeze
67
67
 
68
- if Platform.jruby?
69
- # we use a plain TCPSocket here since JRuby has issues closing socket
70
- # see https://github.com/jruby/jruby/issues/5709
71
- def listening?
72
- TCPSocket.new(@host, @port).close
73
- true
74
- rescue *NOT_CONNECTED_ERRORS
75
- false
76
- end
77
- else
78
- def listening?
79
- addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
80
- sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
81
- sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
82
-
83
- begin
84
- sock.connect_nonblock sockaddr
85
- rescue Errno::EINPROGRESS
86
- retry if socket_writable?(sock) && conn_completed?(sock)
87
- raise Errno::ECONNREFUSED
88
- rescue *CONNECTED_ERRORS
89
- # yay!
90
- end
91
-
92
- sock.close
93
- true
94
- rescue *NOT_CONNECTED_ERRORS
95
- sock&.close
96
- WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
97
- false
68
+ def listening?
69
+ addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
70
+ sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
71
+ sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
72
+
73
+ begin
74
+ sock.connect_nonblock sockaddr
75
+ rescue Errno::EINPROGRESS
76
+ retry if socket_writable?(sock) && conn_completed?(sock)
77
+ raise Errno::ECONNREFUSED
78
+ rescue *CONNECTED_ERRORS
79
+ # yay!
98
80
  end
81
+
82
+ sock.close
83
+ true
84
+ rescue *NOT_CONNECTED_ERRORS
85
+ sock&.close
86
+ WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
87
+ false
99
88
  end
100
89
 
101
90
  def socket_writable?(sock)
@@ -24,38 +24,41 @@ module Selenium
24
24
  #
25
25
  module TakesScreenshot
26
26
  #
27
- # Save a PNG screenshot to the given path
27
+ # Save a PNG screenshot of the viewport to the given path
28
28
  #
29
29
  # @api public
30
30
  #
31
31
 
32
- def save_screenshot(png_path)
32
+ def save_screenshot(png_path, full_page: false)
33
33
  extension = File.extname(png_path).downcase
34
34
  if extension != '.png'
35
35
  WebDriver.logger.warn "name used for saved screenshot does not match file type. "\
36
36
  "It should end with .png extension",
37
37
  id: :screenshot
38
38
  end
39
- File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
39
+ File.open(png_path, 'wb') { |f| f << screenshot_as(:png, full_page: full_page) }
40
40
  end
41
41
 
42
42
  #
43
43
  # Return a PNG screenshot in the given format as a string
44
44
  #
45
45
  # @param [:base64, :png] format
46
+ # @param [Boolean] full_page allows taking full page screenshots if supported
46
47
  # @return String screenshot
47
48
  #
48
49
  # @api public
49
50
 
50
- def screenshot_as(format)
51
+ def screenshot_as(format, full_page: false)
51
52
  case format
52
53
  when :base64
53
- screenshot
54
+ full_page ? full_screenshot : screenshot
54
55
  when :png
55
- screenshot.unpack1('m')
56
+ screenshot_as(:base64, full_page: full_page).unpack1('m')
56
57
  else
57
58
  raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
58
59
  end
60
+ rescue NameError
61
+ raise Error::UnsupportedOperationError, "Full Page Screenshots are not supported for #{inspect}"
59
62
  end
60
63
 
61
64
  end # TakesScreenshot
@@ -57,18 +57,23 @@ require 'selenium/webdriver/common/driver_extensions/has_session_id'
57
57
  require 'selenium/webdriver/common/driver_extensions/has_remote_status'
58
58
  require 'selenium/webdriver/common/driver_extensions/has_network_conditions'
59
59
  require 'selenium/webdriver/common/driver_extensions/has_network_connection'
60
+ require 'selenium/webdriver/common/driver_extensions/has_network_interception'
60
61
  require 'selenium/webdriver/common/driver_extensions/has_permissions'
61
62
  require 'selenium/webdriver/common/driver_extensions/has_debugger'
62
63
  require 'selenium/webdriver/common/driver_extensions/prints_page'
63
64
  require 'selenium/webdriver/common/driver_extensions/uploads_files'
65
+ require 'selenium/webdriver/common/driver_extensions/full_page_screenshot'
64
66
  require 'selenium/webdriver/common/driver_extensions/has_addons'
65
67
  require 'selenium/webdriver/common/driver_extensions/has_devtools'
66
68
  require 'selenium/webdriver/common/driver_extensions/has_authentication'
67
69
  require 'selenium/webdriver/common/driver_extensions/has_logs'
68
70
  require 'selenium/webdriver/common/driver_extensions/has_log_events'
71
+ require 'selenium/webdriver/common/driver_extensions/has_pinned_scripts'
72
+ require 'selenium/webdriver/common/driver_extensions/has_cdp'
69
73
  require 'selenium/webdriver/common/keys'
70
74
  require 'selenium/webdriver/common/profile_helper'
71
75
  require 'selenium/webdriver/common/options'
72
76
  require 'selenium/webdriver/common/takes_screenshot'
73
77
  require 'selenium/webdriver/common/driver'
74
78
  require 'selenium/webdriver/common/element'
79
+ require 'selenium/webdriver/common/shadow_root'
@@ -19,29 +19,41 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- module Firefox
23
- class Bridge < WebDriver::Remote::Bridge
22
+ class DevTools
23
+ class PinnedScript
24
24
 
25
- COMMANDS = {
26
- install_addon: [:post, 'session/:session_id/moz/addon/install'],
27
- uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall']
28
- }.freeze
25
+ attr_accessor :key, :devtools_identifier, :script
29
26
 
30
- def commands(command)
31
- COMMANDS[command] || super
27
+ def initialize(script)
28
+ @key = SecureRandom.alphanumeric
29
+ @script = script
32
30
  end
33
31
 
34
- def install_addon(path, temporary)
35
- payload = {path: path}
36
- payload[:temporary] = temporary unless temporary.nil?
37
- execute :install_addon, {}, payload
32
+ #
33
+ # @api private
34
+ #
35
+
36
+ def callable
37
+ "function __webdriver_#{key}(arguments) { #{script} }"
38
38
  end
39
39
 
40
- def uninstall_addon(id)
41
- execute :uninstall_addon, {}, {id: id}
40
+ #
41
+ # @api private
42
+ #
43
+
44
+ def to_json(*)
45
+ %{"return __webdriver_#{key}(arguments)"}
46
+ end
47
+
48
+ #
49
+ # @api private
50
+ #
51
+
52
+ def remove
53
+ "__webdriver_#{key} = undefined"
42
54
  end
43
55
 
44
- end # Bridge
45
- end # Firefox
56
+ end # PinnedScript
57
+ end # DevTools
46
58
  end # WebDriver
47
59
  end # Selenium
@@ -17,43 +17,41 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
- # This file is automatically generated. Any changes will be lost!
21
20
  module Selenium
22
21
  module WebDriver
23
22
  class DevTools
24
- def console
25
- @console ||= V87::Console.new(self)
26
- end
27
-
28
- module V87
29
- class Console
30
- EVENTS = {
31
- message_added: 'messageAdded'
32
- }.freeze
33
-
34
- def initialize(devtools)
35
- @devtools = devtools
36
- end
37
-
38
- def on(event, &block)
39
- event = EVENTS[event] if event.is_a?(Symbol)
40
- @devtools.callbacks["Console.#{event}"] << block
41
- end
42
-
43
- def clear_messages
44
- @devtools.send_cmd('Console.clearMessages')
45
- end
46
-
47
- def disable
48
- @devtools.send_cmd('Console.disable')
49
- end
50
-
51
- def enable
52
- @devtools.send_cmd('Console.enable')
53
- end
54
-
55
- end # V87
56
- end # Console
23
+ class Request
24
+
25
+ attr_reader :url, :method, :headers
26
+
27
+ def initialize(devtools:, id:, url:, method:, headers:)
28
+ @devtools = devtools
29
+ @id = id
30
+ @url = url
31
+ @method = method
32
+ @headers = headers
33
+ end
34
+
35
+ def continue
36
+ @devtools.fetch.continue_request(request_id: @id)
37
+ end
38
+
39
+ def respond(code: 200, headers: {}, body: '')
40
+ @devtools.fetch.fulfill_request(
41
+ request_id: @id,
42
+ body: Base64.strict_encode64(body),
43
+ response_code: code,
44
+ response_headers: headers.map do |k, v|
45
+ {name: k, value: v}
46
+ end
47
+ )
48
+ end
49
+
50
+ def inspect
51
+ %(#<#{self.class.name} @method="#{method}" @url="#{url}")
52
+ end
53
+
54
+ end # Request
57
55
  end # DevTools
58
56
  end # WebDriver
59
57
  end # Selenium
@@ -23,19 +23,17 @@ module Selenium
23
23
  autoload :ConsoleEvent, 'selenium/webdriver/devtools/console_event'
24
24
  autoload :ExceptionEvent, 'selenium/webdriver/devtools/exception_event'
25
25
  autoload :MutationEvent, 'selenium/webdriver/devtools/mutation_event'
26
+ autoload :PinnedScript, 'selenium/webdriver/devtools/pinned_script'
27
+ autoload :Request, 'selenium/webdriver/devtools/request'
26
28
 
27
- SUPPORTED_VERSIONS = [85, 86, 87, 88].freeze
28
-
29
- def initialize(url:, version:)
29
+ def initialize(url:)
30
30
  @messages = []
31
- @uri = URI("http://#{url}")
31
+ @session_id = nil
32
+ @url = url
32
33
 
33
- load_devtools_version(version)
34
34
  process_handshake
35
35
  attach_socket_listener
36
-
37
- target.attach_to_target(target_id: page_target['id'])
38
- target.set_auto_attach(auto_attach: true, wait_for_debugger_on_start: false)
36
+ start_session
39
37
  end
40
38
 
41
39
  def callbacks
@@ -44,7 +42,9 @@ module Selenium
44
42
 
45
43
  def send_cmd(method, **params)
46
44
  id = next_id
47
- data = JSON.generate(id: id, method: method, params: params.reject { |_, v| v.nil? })
45
+ data = {id: id, method: method, params: params.reject { |_, v| v.nil? }}
46
+ data[:sessionId] = @session_id if @session_id
47
+ data = JSON.generate(data)
48
48
  WebDriver.logger.debug "DevTools -> #{data}"
49
49
 
50
50
  out_frame = WebSocket::Frame::Outgoing::Client.new(version: ws.version, data: data, type: 'text')
@@ -59,16 +59,26 @@ module Selenium
59
59
  message
60
60
  end
61
61
 
62
- private
62
+ def method_missing(method, *_args)
63
+ desired_class = "Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}"
64
+ return unless Object.const_defined?(desired_class)
63
65
 
64
- def load_devtools_version(version)
65
- closest_version = SUPPORTED_VERSIONS.min_by { |v| (version - v).abs }
66
- WebDriver.logger.info("Loading DevTools::V#{closest_version} for #{version}.")
67
- Dir["#{__dir__}/devtools/v#{closest_version}/*"].sort.each do |f|
68
- require f
66
+ self.class.class_eval do
67
+ define_method(method) do
68
+ Object.const_get(desired_class).new(self)
69
+ end
69
70
  end
71
+
72
+ send(method)
73
+ end
74
+
75
+ def respond_to_missing?(method, *_args)
76
+ desired_class = "Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}"
77
+ Object.const_defined?(desired_class)
70
78
  end
71
79
 
80
+ private
81
+
72
82
  def process_handshake
73
83
  socket.print(ws.to_s)
74
84
  ws << socket.readpartial(1024)
@@ -89,7 +99,8 @@ module Selenium
89
99
  next unless message['method']
90
100
 
91
101
  callbacks[message['method']].each do |callback|
92
- Thread.new { callback.call(message['params']) }
102
+ params = message['params'] # take in current thread!
103
+ Thread.new { callback.call(params) }
93
104
  end
94
105
  end
95
106
  end
@@ -97,6 +108,13 @@ module Selenium
97
108
  socket_listener.abort_on_exception = true
98
109
  end
99
110
 
111
+ def start_session
112
+ targets = target.get_targets.dig('result', 'targetInfos')
113
+ page_target = targets.find { |target| target['type'] == 'page' }
114
+ session = target.attach_to_target(target_id: page_target['targetId'], flatten: true)
115
+ @session_id = session.dig('result', 'sessionId')
116
+ end
117
+
100
118
  def incoming_frame
101
119
  @incoming_frame ||= WebSocket::Frame::Incoming::Client.new(version: ws.version)
102
120
  end
@@ -110,15 +128,7 @@ module Selenium
110
128
  end
111
129
 
112
130
  def ws
113
- @ws ||= WebSocket::Handshake::Client.new(url: page_target['webSocketDebuggerUrl'])
114
- end
115
-
116
- def page_target
117
- @page_target ||= begin
118
- response = Net::HTTP.get(@uri.hostname, '/json/list', @uri.port)
119
- targets = JSON.parse(response)
120
- targets.find { |target| target['type'] == 'page' }
121
- end
131
+ @ws ||= WebSocket::Handshake::Client.new(url: @url)
122
132
  end
123
133
 
124
134
  def next_id
@@ -33,14 +33,10 @@ module Selenium
33
33
  :edge
34
34
  end
35
35
 
36
- def bridge_class
37
- Bridge
38
- end
39
-
40
36
  private
41
37
 
42
- def debugger_address
43
- capabilities['ms:edgeOptions']['debuggerAddress']
38
+ def devtools_address
39
+ "http://#{capabilities['ms:edgeOptions']['debuggerAddress']}"
44
40
  end
45
41
  end # Driver
46
42
  end # Edge
File without changes
File without changes
@@ -22,7 +22,7 @@ require 'net/http'
22
22
  module Selenium
23
23
  module WebDriver
24
24
  module Edge
25
- autoload :Bridge, 'selenium/webdriver/edge/bridge'
25
+ autoload :Features, 'selenium/webdriver/edge/features'
26
26
  autoload :Driver, 'selenium/webdriver/edge/driver'
27
27
  autoload :Profile, 'selenium/webdriver/edge/profile'
28
28
  autoload :Options, 'selenium/webdriver/edge/options'
@@ -27,28 +27,29 @@ module Selenium
27
27
  #
28
28
 
29
29
  class Driver < WebDriver::Driver
30
- include DriverExtensions::HasAddons
31
- include DriverExtensions::HasDevTools
32
- include DriverExtensions::HasLogEvents
33
- include DriverExtensions::HasWebStorage
34
- include DriverExtensions::PrintsPage
30
+ EXTENSIONS = [DriverExtensions::HasAddons,
31
+ DriverExtensions::FullPageScreenshot,
32
+ DriverExtensions::HasDevTools,
33
+ DriverExtensions::HasLogEvents,
34
+ DriverExtensions::HasNetworkInterception,
35
+ DriverExtensions::HasWebStorage,
36
+ DriverExtensions::PrintsPage].freeze
35
37
 
36
38
  def browser
37
39
  :firefox
38
40
  end
39
41
 
40
- def bridge_class
41
- Bridge
42
- end
43
-
44
42
  private
45
43
 
46
- def devtools_version
47
- 85
44
+ def devtools_url
45
+ uri = URI("http://#{capabilities['moz:debuggerAddress']}")
46
+ response = Net::HTTP.get(uri.hostname, '/json/version', uri.port)
47
+
48
+ JSON.parse(response)['webSocketDebuggerUrl']
48
49
  end
49
50
 
50
- def debugger_address
51
- capabilities['moz:debuggerAddress']
51
+ def devtools_version
52
+ Firefox::DEVTOOLS_VERSION
52
53
  end
53
54
  end # Driver
54
55
  end # Firefox