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
@@ -21,8 +21,35 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module PrintsPage
24
+ #
25
+ # Save a page as a PDF to the given path
26
+ #
27
+ # @example Save Printed Page
28
+ # driver.save_print_page('../printed_page.pdf')
29
+ #
30
+ # @param [String] path to where the pdf should be saved
31
+ #
32
+ # @api public
33
+ #
34
+
35
+ def save_print_page(path, **options)
36
+ File.open(path, 'wb') do |file|
37
+ content = Base64.decode64 print_page(options)
38
+ file << content
39
+ end
40
+ end
41
+
42
+ #
43
+ # Return a Base64 encoded Print Page as a string
44
+ #
45
+ # @see https://w3c.github.io/webdriver/#print-page
46
+ #
47
+ # @api public
48
+ #
49
+
24
50
  def print_page(**options)
25
- options[:page_ranges] &&= Array(options[:page_ranges])
51
+ options[:pageRanges] = Array(options.delete(:page_ranges)) || []
52
+ options[:shrinkToFit] = options.delete(:shrink_to_fit) { true }
26
53
 
27
54
  @bridge.print_page(options)
28
55
  end
@@ -92,13 +92,18 @@ module Selenium
92
92
  end
93
93
 
94
94
  #
95
- # Get the value of a the given attribute of the element. Will return the current value, even if
96
- # this has been modified after the page has been loaded. More exactly, this method will return
97
- # the value of the given attribute, unless that attribute is not present, in which case the
98
- # value of the property with the same name is returned. If neither value is set, nil is
99
- # returned. The "style" attribute is converted as best can be to a text representation with a
100
- # trailing semi-colon. The following are deemed to be "boolean" attributes, and will
101
- # return either "true" or "false":
95
+ # This method attempts to provide the most likely desired current value for the attribute
96
+ # of the element, even when that desired value is actually a JavaScript property.
97
+ # It is implemented with a custom JavaScript atom. To obtain the exact value of the attribute or property,
98
+ # use #dom_attribute or #property methods respectively.
99
+ #
100
+ # More exactly, this method will return the value of the property with the given name,
101
+ # if it exists. If it does not, then the value of the attribute with the given name is returned.
102
+ # If neither exists, null is returned.
103
+ #
104
+ # The "style" attribute is converted as best can be to a text representation with a trailing semi-colon.
105
+ #
106
+ # The following are deemed to be "boolean" attributes, and will return either "true" or "false":
102
107
  #
103
108
  # async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
104
109
  # defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
@@ -106,29 +111,73 @@ module Selenium
106
111
  # nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
107
112
  # selected, spellcheck, truespeed, willvalidate
108
113
  #
109
- # Finally, the following commonly mis-capitalized attribute/property names are evaluated as
110
- # expected:
114
+ # Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
111
115
  #
112
- # class, readonly
116
+ # When the value of "class" is requested, the "className" property is returned.
117
+ # When the value of "readonly" is requested, the "readOnly" property is returned.
113
118
  #
114
119
  # @param [String] name attribute name
115
120
  # @return [String, nil] attribute value
116
121
  #
122
+ # @see #dom_attribute
123
+ # @see #property
124
+ #
117
125
 
118
126
  def attribute(name)
119
127
  bridge.element_attribute self, name
120
128
  end
121
129
 
122
130
  #
123
- # Get the value of a the given property with the same name of the element. If the value is not
124
- # set, nil is returned.
131
+ # Gets the value of a declared HTML attribute of this element.
132
+ #
133
+ # As opposed to the #attribute method, this method
134
+ # only returns attributes declared in the element's HTML markup.
135
+ #
136
+ # If the attribute is not set, nil is returned.
137
+ #
138
+ # @param [String] name attribute name
139
+ # @return [String, nil] attribute value
140
+ #
141
+ # @see #attribute
142
+ # @see #property
143
+ #
144
+
145
+ def dom_attribute(name)
146
+ bridge.element_dom_attribute @id, name
147
+ end
148
+
149
+ #
150
+ # Gets the value of a JavaScript property of this element
151
+ # This will return the current value,
152
+ # even if this has been modified after the page has been loaded.
153
+ # If the value is not set, nil is returned.
125
154
  #
126
155
  # @param [String] name property name
127
156
  # @return [String, nil] property value
128
157
  #
129
158
 
130
159
  def property(name)
131
- bridge.element_property self, name
160
+ bridge.element_property @id, name
161
+ end
162
+
163
+ #
164
+ # Gets the computed WAI-ARIA role of element
165
+ #
166
+ # @return [String]
167
+ #
168
+
169
+ def aria_role
170
+ bridge.element_aria_role @id
171
+ end
172
+
173
+ #
174
+ # Gets the computed WAI-ARIA label of element.
175
+ #
176
+ # @return [String]
177
+ #
178
+
179
+ def accessible_name
180
+ bridge.element_aria_label @id
132
181
  end
133
182
 
134
183
  #
@@ -268,6 +317,16 @@ module Selenium
268
317
  bridge.element_size @id
269
318
  end
270
319
 
320
+ #
321
+ # Returns the shadow root of an element.
322
+ #
323
+ # @return [WebDriver::ShadowRoot]
324
+ #
325
+
326
+ def shadow_root
327
+ bridge.shadow_root @id
328
+ end
329
+
271
330
  #-------------------------------- sugar --------------------------------
272
331
 
273
332
  #
@@ -287,14 +346,13 @@ module Selenium
287
346
  #
288
347
  alias_method :[], :attribute
289
348
 
290
- #
291
- # for SearchContext and execute_script
292
349
  #
293
350
  # @api private
351
+ # @see SearchContext
294
352
  #
295
353
 
296
354
  def ref
297
- @id
355
+ [:element, @id]
298
356
  end
299
357
 
300
358
  #
@@ -330,7 +388,7 @@ module Selenium
330
388
  end
331
389
 
332
390
  def screenshot
333
- bridge.element_screenshot(self)
391
+ bridge.element_screenshot(@id)
334
392
  end
335
393
  end # Element
336
394
  end # WebDriver
@@ -61,6 +61,12 @@ module Selenium
61
61
 
62
62
  class StaleElementReferenceError < WebDriverError; end
63
63
 
64
+ #
65
+ # A command failed because the referenced shadow root is no longer attached to the DOM.
66
+ #
67
+
68
+ class DetachedShadowRootError < WebDriverError; end
69
+
64
70
  #
65
71
  # The target element is in an invalid state, rendering it impossible to interact with, for
66
72
  # example if you click a disabled element.
@@ -93,6 +99,12 @@ module Selenium
93
99
 
94
100
  class NoSuchWindowError < WebDriverError; end
95
101
 
102
+ #
103
+ # The element does not have a shadow root.
104
+ #
105
+
106
+ class NoSuchShadowRootError < WebDriverError; end
107
+
96
108
  #
97
109
  # An illegal attempt was made to set a cookie under a different domain than the current page.
98
110
  #
@@ -26,7 +26,10 @@ module Selenium
26
26
  attr_reader :source
27
27
 
28
28
  def initialize(source)
29
- raise TypeError, "#{source.type} is not a valid input type" unless Interactions::SOURCE_TYPES.include? source.type
29
+ unless Interactions::SOURCE_TYPES.include? source.type
30
+ raise TypeError,
31
+ "#{source.type} is not a valid input type"
32
+ end
30
33
 
31
34
  @source = source
32
35
  end
@@ -108,10 +108,11 @@ module Selenium
108
108
  #
109
109
  # @param [String] old
110
110
  # @param [String, nil] new
111
- # @param [Symbol, Array<Sybmol>] id
111
+ # @param [Symbol, Array<Symbol>] id
112
+ # @param [String] reference
112
113
  # @yield appends additional message to end of provided template
113
114
  #
114
- def deprecate(old, new = nil, id: [], &block)
115
+ def deprecate(old, new = nil, id: [], reference: '', &block)
115
116
  id = Array(id)
116
117
  return if @ignored.include?(:deprecations) || (@ignored & id).any?
117
118
 
@@ -123,6 +124,8 @@ module Selenium
123
124
  else
124
125
  ' and will be removed in a future release.'
125
126
  end
127
+ message << " See explanation for this deprecation: #{reference}." unless reference.empty?
128
+
126
129
  warn message, &block
127
130
  end
128
131
 
@@ -23,16 +23,42 @@ module Selenium
23
23
  W3C_OPTIONS = %i[browser_name browser_version platform_name accept_insecure_certs page_load_strategy proxy
24
24
  set_window_rect timeouts unhandled_prompt_behavior strict_file_interactability].freeze
25
25
 
26
- def self.set_capabilities
27
- (W3C_OPTIONS + self::CAPABILITIES.keys).each do |key|
28
- next if method_defined? key
26
+ class << self
27
+ attr_reader :driver_path
29
28
 
30
- define_method key do
31
- @options[key]
32
- end
29
+ def chrome(**opts)
30
+ Chrome::Options.new(**opts)
31
+ end
32
+
33
+ def firefox(**opts)
34
+ Firefox::Options.new(**opts)
35
+ end
36
+
37
+ def ie(**opts)
38
+ IE::Options.new(**opts)
39
+ end
40
+ alias_method :internet_explorer, :ie
41
+
42
+ def edge(**opts)
43
+ Edge::Options.new(**opts)
44
+ end
45
+ alias_method :microsoftedge, :edge
46
+
47
+ def safari(**opts)
48
+ Safari::Options.new(**opts)
49
+ end
50
+
51
+ def set_capabilities
52
+ (W3C_OPTIONS + self::CAPABILITIES.keys).each do |key|
53
+ next if method_defined? key
33
54
 
34
- define_method "#{key}=" do |value|
35
- @options[key] = value
55
+ define_method key do
56
+ @options[key]
57
+ end
58
+
59
+ define_method "#{key}=" do |value|
60
+ @options[key] = value
61
+ end
36
62
  end
37
63
  end
38
64
  end
@@ -68,6 +94,14 @@ module Selenium
68
94
  @options[name] = value
69
95
  end
70
96
 
97
+ def ==(other)
98
+ return false unless other.is_a? self.class
99
+
100
+ as_json == other.as_json
101
+ end
102
+
103
+ alias_method :eql?, :==
104
+
71
105
  #
72
106
  # @api private
73
107
  #
@@ -75,12 +109,11 @@ module Selenium
75
109
  def as_json(*)
76
110
  options = @options.dup
77
111
 
78
- w3c_options = options.select { |key, _val| W3C_OPTIONS.include?(key) }
79
- options.delete_if { |key, _val| W3C_OPTIONS.include?(key) }
112
+ w3c_options = process_w3c_options(options)
80
113
 
81
114
  self.class::CAPABILITIES.each do |capability_alias, capability_name|
82
115
  capability_value = options.delete(capability_alias)
83
- options[capability_name] = capability_value unless capability_value.nil?
116
+ options[capability_name] = capability_value if !capability_value.nil? && !options.key?(capability_name)
84
117
  end
85
118
  browser_options = defined?(self.class::KEY) ? {self.class::KEY => options} : options
86
119
 
@@ -90,6 +123,13 @@ module Selenium
90
123
 
91
124
  private
92
125
 
126
+ def process_w3c_options(options)
127
+ w3c_options = options.select { |key, _val| W3C_OPTIONS.include?(key) }
128
+ w3c_options[:unhandled_prompt_behavior] &&= w3c_options[:unhandled_prompt_behavior]&.to_s&.tr('_', ' ')
129
+ options.delete_if { |key, _val| W3C_OPTIONS.include?(key) }
130
+ w3c_options
131
+ end
132
+
93
133
  def process_browser_options(_browser_options)
94
134
  nil
95
135
  end
@@ -100,12 +140,7 @@ module Selenium
100
140
 
101
141
  def generate_as_json(value, camelize_keys: true)
102
142
  if value.is_a?(Hash)
103
- value.each_with_object({}) do |(key, val), hash|
104
- next if val.respond_to?(:empty?) && val.empty?
105
-
106
- key = convert_json_key(key, camelize: camelize_keys)
107
- hash[key] = generate_as_json(val, camelize_keys: camelize?(key))
108
- end
143
+ process_json_hash(value, camelize_keys)
109
144
  elsif value.respond_to?(:as_json)
110
145
  value.as_json
111
146
  elsif value.is_a?(Array)
@@ -117,6 +152,16 @@ module Selenium
117
152
  end
118
153
  end
119
154
 
155
+ def process_json_hash(value, camelize_keys)
156
+ value.each_with_object({}) do |(key, val), hash|
157
+ next if val.respond_to?(:empty?) && val.empty?
158
+
159
+ camelize = camelize_keys ? camelize?(key) : false
160
+ key = convert_json_key(key, camelize: camelize)
161
+ hash[key] = generate_as_json(val, camelize_keys: camelize)
162
+ end
163
+ end
164
+
120
165
  def convert_json_key(key, camelize: true)
121
166
  key = key.to_s if key.is_a?(Symbol)
122
167
  key = camel_case(key) if camelize
@@ -127,7 +127,10 @@ module Selenium
127
127
  end
128
128
 
129
129
  def type=(type)
130
- raise ArgumentError, "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}" unless TYPES.key? type
130
+ unless TYPES.key? type
131
+ raise ArgumentError,
132
+ "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
133
+ end
131
134
 
132
135
  if defined?(@type) && type != @type
133
136
  raise ArgumentError, "incompatible proxy type #{type.inspect} (already set to #{@type.inspect})"
@@ -138,10 +141,10 @@ module Selenium
138
141
 
139
142
  def as_json(*)
140
143
  json_result = {
141
- 'proxyType' => TYPES[type],
144
+ 'proxyType' => TYPES[type].downcase,
142
145
  'ftpProxy' => ftp,
143
146
  'httpProxy' => http,
144
- 'noProxy' => no_proxy,
147
+ 'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(', ') : no_proxy,
145
148
  'proxyAutoconfigUrl' => pac,
146
149
  'sslProxy' => ssl,
147
150
  'autodetect' => auto_detect,
@@ -93,7 +93,10 @@ module Selenium
93
93
  when 1
94
94
  arg = args.first
95
95
 
96
- raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift" unless arg.respond_to?(:shift)
96
+ unless arg.respond_to?(:shift)
97
+ raise ArgumentError,
98
+ "expected #{arg.inspect}:#{arg.class} to respond to #shift"
99
+ end
97
100
 
98
101
  # this will be a single-entry hash, so use #shift over #first or #[]
99
102
  arr = arg.dup.shift
@@ -44,6 +44,7 @@ module Selenium
44
44
  def edge(**opts)
45
45
  Edge::Service.new(**opts)
46
46
  end
47
+ alias_method :microsoftedge, :edge
47
48
 
48
49
  def safari(**opts)
49
50
  Safari::Service.new(**opts)
@@ -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
+ class ShadowRoot
23
+ ROOT_KEY = 'shadow-6066-11e4-a52e-4f735466cecf'
24
+
25
+ include SearchContext
26
+
27
+ #
28
+ # Creates a new shadow root
29
+ #
30
+ # @api private
31
+ #
32
+
33
+ def initialize(bridge, id)
34
+ @bridge = bridge
35
+ @id = id
36
+ end
37
+
38
+ def inspect
39
+ format '#<%<class>s:0x%<hash>x id=%<id>s>', class: self.class, hash: hash * 2, id: @id.inspect
40
+ end
41
+
42
+ def ==(other)
43
+ other.is_a?(self.class) && ref == other.ref
44
+ end
45
+ alias_method :eql?, :==
46
+
47
+ def hash
48
+ @id.hash ^ @bridge.hash
49
+ end
50
+
51
+ #
52
+ # @api private
53
+ # @see SearchContext
54
+ #
55
+
56
+ def ref
57
+ [:shadow_root, @id]
58
+ end
59
+
60
+ #
61
+ # Convert to a ShadowRoot JSON Object for transmission over the wire.
62
+ # @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#basic-terms-and-concepts
63
+ #
64
+ # @api private
65
+ #
66
+
67
+ def to_json(*)
68
+ JSON.generate as_json
69
+ end
70
+
71
+ #
72
+ # For Rails 3 - http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/
73
+ #
74
+ # @api private
75
+ #
76
+
77
+ def as_json(*)
78
+ {ROOT_KEY => @id}
79
+ end
80
+
81
+ private
82
+
83
+ attr_reader :bridge
84
+
85
+ end # ShadowRoot
86
+ end # WebDriver
87
+ end # Selenium