selenium-webdriver 3.142.7 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +432 -5
  3. data/Gemfile +3 -1
  4. data/LICENSE +1 -1
  5. data/NOTICE +2 -0
  6. data/README.md +4 -5
  7. data/lib/selenium/server.rb +75 -64
  8. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  9. data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
  10. data/lib/selenium/webdriver/atoms/isDisplayed.js +76 -78
  11. data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
  12. data/lib/selenium/webdriver/bidi/session.rb +38 -0
  13. data/lib/selenium/webdriver/bidi.rb +55 -0
  14. data/lib/selenium/webdriver/chrome/driver.rb +26 -83
  15. data/lib/selenium/webdriver/chrome/{bridge.rb → features.rb} +55 -12
  16. data/lib/selenium/webdriver/chrome/options.rb +138 -67
  17. data/lib/selenium/webdriver/chrome/profile.rb +6 -3
  18. data/lib/selenium/webdriver/chrome/service.rb +8 -15
  19. data/lib/selenium/webdriver/chrome.rb +5 -18
  20. data/lib/selenium/webdriver/common/action_builder.rb +171 -236
  21. data/lib/selenium/webdriver/common/driver.rb +76 -29
  22. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +43 -0
  23. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +51 -0
  24. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +89 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +10 -8
  26. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +87 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +38 -0
  28. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +44 -0
  29. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +43 -0
  30. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +38 -0
  31. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +5 -8
  32. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +144 -0
  33. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
  34. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +17 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +6 -27
  36. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +136 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -11
  38. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +77 -0
  39. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  40. data/lib/selenium/webdriver/common/element.rb +83 -23
  41. data/lib/selenium/webdriver/common/error.rb +32 -196
  42. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  43. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
  44. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  45. data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
  46. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  47. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  48. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  49. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +68 -78
  50. data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
  51. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  52. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  53. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  54. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  55. data/lib/selenium/webdriver/common/interactions/scroll.rb +57 -0
  56. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  57. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  58. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
  59. data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
  60. data/lib/selenium/webdriver/common/keys.rb +1 -0
  61. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  62. data/lib/selenium/webdriver/common/logger.rb +50 -15
  63. data/lib/selenium/webdriver/common/manager.rb +11 -38
  64. data/lib/selenium/webdriver/common/options.rb +147 -23
  65. data/lib/selenium/webdriver/common/platform.rb +10 -5
  66. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  67. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  68. data/lib/selenium/webdriver/common/proxy.rb +6 -3
  69. data/lib/selenium/webdriver/common/search_context.rb +7 -9
  70. data/lib/selenium/webdriver/common/service.rb +17 -125
  71. data/lib/selenium/webdriver/common/service_manager.rb +150 -0
  72. data/lib/selenium/webdriver/common/shadow_root.rb +87 -0
  73. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  74. data/lib/selenium/webdriver/common/socket_poller.rb +3 -3
  75. data/lib/selenium/webdriver/common/takes_screenshot.rb +66 -0
  76. data/lib/selenium/webdriver/common/target_locator.rb +32 -4
  77. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  78. data/lib/selenium/webdriver/common/wait.rb +1 -1
  79. data/lib/selenium/webdriver/common/websocket_connection.rb +149 -0
  80. data/lib/selenium/webdriver/common/window.rb +0 -4
  81. data/lib/selenium/webdriver/common/zipper.rb +3 -9
  82. data/lib/selenium/webdriver/common.rb +35 -18
  83. data/lib/selenium/webdriver/devtools/console_event.rb +38 -0
  84. data/lib/selenium/webdriver/devtools/exception_event.rb +36 -0
  85. data/lib/selenium/webdriver/devtools/mutation_event.rb +37 -0
  86. data/lib/selenium/webdriver/devtools/pinned_script.rb +59 -0
  87. data/lib/selenium/webdriver/devtools/request.rb +67 -0
  88. data/lib/selenium/webdriver/devtools/response.rb +66 -0
  89. data/lib/selenium/webdriver/devtools.rb +86 -0
  90. data/lib/selenium/webdriver/edge/driver.rb +7 -29
  91. data/lib/selenium/webdriver/edge/features.rb +45 -0
  92. data/lib/selenium/webdriver/edge/options.rb +11 -48
  93. data/lib/selenium/webdriver/edge/profile.rb +33 -0
  94. data/lib/selenium/webdriver/edge/service.rb +10 -26
  95. data/lib/selenium/webdriver/edge.rb +11 -14
  96. data/lib/selenium/webdriver/firefox/driver.rb +32 -19
  97. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  98. data/lib/selenium/webdriver/firefox/features.rb +63 -0
  99. data/lib/selenium/webdriver/firefox/options.rb +73 -50
  100. data/lib/selenium/webdriver/firefox/profile.rb +16 -70
  101. data/lib/selenium/webdriver/firefox/service.rb +5 -9
  102. data/lib/selenium/webdriver/firefox/util.rb +1 -1
  103. data/lib/selenium/webdriver/firefox.rb +17 -28
  104. data/lib/selenium/webdriver/ie/driver.rb +1 -47
  105. data/lib/selenium/webdriver/ie/options.rb +15 -46
  106. data/lib/selenium/webdriver/ie/service.rb +13 -15
  107. data/lib/selenium/webdriver/ie.rb +3 -16
  108. data/lib/selenium/webdriver/remote/bridge.rb +563 -86
  109. data/lib/selenium/webdriver/remote/capabilities.rb +159 -123
  110. data/lib/selenium/webdriver/remote/commands.rb +158 -0
  111. data/lib/selenium/webdriver/remote/driver.rb +22 -13
  112. data/lib/selenium/webdriver/remote/http/common.rb +0 -5
  113. data/lib/selenium/webdriver/remote/http/default.rb +22 -31
  114. data/lib/selenium/webdriver/remote/response.rb +18 -49
  115. data/lib/selenium/webdriver/remote.rb +15 -12
  116. data/lib/selenium/webdriver/safari/driver.rb +3 -31
  117. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +3 -3
  118. data/lib/selenium/webdriver/safari/options.rb +10 -29
  119. data/lib/selenium/webdriver/safari/service.rb +4 -8
  120. data/lib/selenium/webdriver/safari.rb +13 -19
  121. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  122. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +63 -0
  123. data/lib/selenium/webdriver/support/cdp_client_generator.rb +108 -0
  124. data/lib/selenium/webdriver/support/color.rb +9 -9
  125. data/lib/selenium/webdriver/support/event_firing_bridge.rb +4 -4
  126. data/lib/selenium/webdriver/support/guards/guard.rb +89 -0
  127. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +22 -19
  128. data/lib/selenium/webdriver/support/guards.rb +95 -0
  129. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  130. data/lib/selenium/webdriver/support/select.rb +3 -3
  131. data/lib/selenium/webdriver/support.rb +1 -0
  132. data/lib/selenium/webdriver/version.rb +1 -1
  133. data/lib/selenium/webdriver.rb +14 -13
  134. data/selenium-webdriver.gemspec +32 -13
  135. metadata +176 -69
  136. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  137. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  138. data/lib/selenium/webdriver/common/keyboard.rb +0 -70
  139. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  140. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  141. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  142. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  143. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  144. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  145. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  146. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  147. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  148. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  149. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  150. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  151. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  152. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
  153. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  154. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  155. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  156. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  157. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -20,7 +20,10 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  class Element
23
+ ELEMENT_KEY = 'element-6066-11e4-a52e-4f735466cecf'
24
+
23
25
  include SearchContext
26
+ include TakesScreenshot
24
27
 
25
28
  #
26
29
  # Creates a new Element
@@ -43,7 +46,7 @@ module Selenium
43
46
  alias_method :eql?, :==
44
47
 
45
48
  def hash
46
- @id.hash ^ @bridge.hash
49
+ [@id, @bridge].hash
47
50
  end
48
51
 
49
52
  #
@@ -89,13 +92,18 @@ module Selenium
89
92
  end
90
93
 
91
94
  #
92
- # Get the value of a the given attribute of the element. Will return the current value, even if
93
- # this has been modified after the page has been loaded. More exactly, this method will return
94
- # the value of the given attribute, unless that attribute is not present, in which case the
95
- # value of the property with the same name is returned. If neither value is set, nil is
96
- # returned. The "style" attribute is converted as best can be to a text representation with a
97
- # trailing semi-colon. The following are deemed to be "boolean" attributes, and will
98
- # 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":
99
107
  #
100
108
  # async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
101
109
  # defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
@@ -103,29 +111,73 @@ module Selenium
103
111
  # nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
104
112
  # selected, spellcheck, truespeed, willvalidate
105
113
  #
106
- # Finally, the following commonly mis-capitalized attribute/property names are evaluated as
107
- # expected:
114
+ # Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
108
115
  #
109
- # 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.
110
118
  #
111
119
  # @param [String] name attribute name
112
120
  # @return [String, nil] attribute value
113
121
  #
122
+ # @see #dom_attribute
123
+ # @see #property
124
+ #
114
125
 
115
126
  def attribute(name)
116
127
  bridge.element_attribute self, name
117
128
  end
118
129
 
119
130
  #
120
- # Get the value of a the given property with the same name of the element. If the value is not
121
- # 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.
122
154
  #
123
155
  # @param [String] name property name
124
156
  # @return [String, nil] property value
125
157
  #
126
158
 
127
159
  def property(name)
128
- 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
129
181
  end
130
182
 
131
183
  #
@@ -265,6 +317,16 @@ module Selenium
265
317
  bridge.element_size @id
266
318
  end
267
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
+
268
330
  #-------------------------------- sugar --------------------------------
269
331
 
270
332
  #
@@ -284,14 +346,13 @@ module Selenium
284
346
  #
285
347
  alias_method :[], :attribute
286
348
 
287
- #
288
- # for SearchContext and execute_script
289
349
  #
290
350
  # @api private
351
+ # @see SearchContext
291
352
  #
292
353
 
293
354
  def ref
294
- @id
355
+ [:element, @id]
295
356
  end
296
357
 
297
358
  #
@@ -312,12 +373,7 @@ module Selenium
312
373
  #
313
374
 
314
375
  def as_json(*)
315
- key = if bridge.dialect == :w3c
316
- 'element-6066-11e4-a52e-4f735466cecf'
317
- else
318
- 'ELEMENT'
319
- end
320
- @id.is_a?(Hash) ? @id : {key => @id}
376
+ @id.is_a?(Hash) ? @id : {ELEMENT_KEY => @id}
321
377
  end
322
378
 
323
379
  private
@@ -330,6 +386,10 @@ module Selenium
330
386
 
331
387
  tn == 'option' || (tn == 'input' && %w[radio checkbox].include?(type))
332
388
  end
389
+
390
+ def screenshot
391
+ bridge.element_screenshot(@id)
392
+ end
333
393
  end # Element
334
394
  end # WebDriver
335
395
  end # Selenium
@@ -19,191 +19,134 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- module Error # rubocop:disable Metrics/ModuleLength
22
+ module Error
23
23
 
24
24
  #
25
- # Returns exception from code (Integer - OSS, String - W3C).
26
- # @param [Integer, String, nil] code
25
+ # Returns exception from its string representation.
26
+ # @param [String, nil] error
27
27
  #
28
28
 
29
- def self.for_code(code)
30
- case code
31
- when nil, 0
32
- nil
33
- when Integer
34
- Object.const_get(ERRORS.fetch(code).to_s)
35
- when String
36
- klass_name = code.split(' ').map(&:capitalize).join.sub(/Error$/, '')
37
- const_get("#{klass_name}Error", false)
38
- end
39
- rescue KeyError, NameError
29
+ def self.for_error(error)
30
+ return if error.nil?
31
+
32
+ klass_name = error.split.map(&:capitalize).join.sub(/Error$/, '')
33
+ const_get("#{klass_name}Error", false)
34
+ rescue NameError
40
35
  WebDriverError
41
36
  end
42
37
 
43
38
  class WebDriverError < StandardError; end
44
39
 
45
- class IndexOutOfBoundsError < WebDriverError; end # 1
46
- class NoCollectionError < WebDriverError; end # 2
47
- class NoStringError < WebDriverError; end # 3
48
- class NoStringLengthError < WebDriverError; end # 4
49
- class NoStringWrapperError < WebDriverError; end # 5
50
- class NoSuchDriverError < WebDriverError; end # 6
51
-
52
40
  #
53
41
  # An element could not be located on the page using the given search parameters.
54
42
  #
55
43
 
56
- class NoSuchElementError < WebDriverError; end # 7
44
+ class NoSuchElementError < WebDriverError; end
57
45
 
58
46
  #
59
47
  # A command to switch to a frame could not be satisfied because the frame could not be found.
60
48
  #
61
49
 
62
- class NoSuchFrameError < WebDriverError; end # 8
50
+ class NoSuchFrameError < WebDriverError; end
63
51
 
64
52
  #
65
53
  # A command could not be executed because the remote end is not aware of it.
66
54
  #
67
55
 
68
- class UnknownCommandError < WebDriverError; end # 9
56
+ class UnknownCommandError < WebDriverError; end
69
57
 
70
58
  #
71
59
  # A command failed because the referenced element is no longer attached to the DOM.
72
60
  #
73
61
 
74
- class StaleElementReferenceError < WebDriverError; end # 10
62
+ class StaleElementReferenceError < WebDriverError; end
75
63
 
76
64
  #
77
- # Raised to indicate that although an element is present on the DOM, it is not visible, and
78
- # so is not able to be interacted with.
65
+ # A command failed because the referenced shadow root is no longer attached to the DOM.
79
66
  #
80
67
 
81
- class ElementNotVisibleError < WebDriverError; end # 11
68
+ class DetachedShadowRootError < WebDriverError; end
82
69
 
83
70
  #
84
71
  # The target element is in an invalid state, rendering it impossible to interact with, for
85
72
  # example if you click a disabled element.
86
73
  #
87
74
 
88
- class InvalidElementStateError < WebDriverError; end # 12
75
+ class InvalidElementStateError < WebDriverError; end
89
76
 
90
77
  #
91
78
  # An unknown error occurred in the remote end while processing the command.
92
79
  #
93
80
 
94
- class UnknownError < WebDriverError; end # 13
95
- class ExpectedError < WebDriverError; end # 14
81
+ class UnknownError < WebDriverError; end
96
82
 
97
83
  #
98
- # An attempt was made to select an element that cannot be selected.
84
+ # An error occurred while executing JavaScript supplied by the user.
99
85
  #
100
86
 
101
- class ElementNotSelectableError < WebDriverError; end # 15
102
- class NoSuchDocumentError < WebDriverError; end # 16
87
+ class JavascriptError < WebDriverError; end
103
88
 
104
89
  #
105
- # An error occurred while executing JavaScript supplied by the user.
90
+ # An operation did not complete before its timeout expired.
106
91
  #
107
92
 
108
- class JavascriptError < WebDriverError; end # 17
109
- class NoScriptResultError < WebDriverError; end # 18
93
+ class TimeoutError < WebDriverError; end
110
94
 
111
95
  #
112
- # An error occurred while searching for an element by XPath.
96
+ # A command to switch to a window could not be satisfied because
97
+ # the window could not be found.
113
98
  #
114
99
 
115
- class XPathLookupError < WebDriverError; end # 19
116
- class NoSuchCollectionError < WebDriverError; end # 20
100
+ class NoSuchWindowError < WebDriverError; end
117
101
 
118
102
  #
119
- # An operation did not complete before its timeout expired.
103
+ # The element does not have a shadow root.
120
104
  #
121
105
 
122
- class TimeOutError < WebDriverError; end # 21
123
-
124
- class NullPointerError < WebDriverError; end # 22
125
- class NoSuchWindowError < WebDriverError; end # 23
106
+ class NoSuchShadowRootError < WebDriverError; end
126
107
 
127
108
  #
128
109
  # An illegal attempt was made to set a cookie under a different domain than the current page.
129
110
  #
130
111
 
131
- class InvalidCookieDomainError < WebDriverError; end # 24
112
+ class InvalidCookieDomainError < WebDriverError; end
132
113
 
133
114
  #
134
115
  # A command to set a cookie's value could not be satisfied.
135
116
  #
136
117
 
137
- class UnableToSetCookieError < WebDriverError; end # 25
138
-
139
- #
140
- # Raised when an alert dialog is present that has not been dealt with.
141
- #
142
- class UnhandledAlertError < WebDriverError; end # 26
118
+ class UnableToSetCookieError < WebDriverError; end
143
119
 
144
120
  #
145
121
  # An attempt was made to operate on a modal dialog when one was not open:
146
122
  #
147
- # * W3C dialect is NoSuchAlertError
148
- # * OSS dialect is NoAlertPresentError
149
- #
150
- # We want to allow clients to rescue NoSuchAlertError as a superclass for
151
- # dialect-agnostic implementation, so NoAlertPresentError should inherit from it.
152
- #
153
123
 
154
124
  class NoSuchAlertError < WebDriverError; end
155
- class NoAlertPresentError < NoSuchAlertError; end # 27
156
125
 
157
126
  #
158
127
  # A script did not complete before its timeout expired.
159
128
  #
160
129
 
161
- class ScriptTimeOutError < WebDriverError; end # 28
162
-
163
- #
164
- # The coordinates provided to an interactions operation are invalid.
165
- #
166
-
167
- class InvalidElementCoordinatesError < WebDriverError; end # 29
168
-
169
- #
170
- # Indicates that IME support is not available. This exception is rasied for every IME-related
171
- # method call if IME support is not available on the machine.
172
- #
173
-
174
- class IMENotAvailableError < WebDriverError; end # 30
175
-
176
- #
177
- # Indicates that activating an IME engine has failed.
178
- #
179
-
180
- class IMEEngineActivationFailedError < WebDriverError; end # 31
130
+ class ScriptTimeoutError < WebDriverError; end
181
131
 
182
132
  #
183
133
  # Argument was an invalid selector.
184
134
  #
185
135
 
186
- class InvalidSelectorError < WebDriverError; end # 32
136
+ class InvalidSelectorError < WebDriverError; end
187
137
 
188
138
  #
189
139
  # A new session could not be created.
190
140
  #
191
141
 
192
- class SessionNotCreatedError < WebDriverError; end # 33
142
+ class SessionNotCreatedError < WebDriverError; end
193
143
 
194
144
  #
195
145
  # The target for mouse interaction is not in the browser's viewport and cannot be brought
196
146
  # into that viewport.
197
147
  #
198
148
 
199
- class MoveTargetOutOfBoundsError < WebDriverError; end # 34
200
-
201
- #
202
- # Indicates that the XPath selector is invalid
203
- #
204
-
205
- class InvalidXpathSelectorError < WebDriverError; end
206
- class InvalidXpathSelectorReturnTyperError < WebDriverError; end
149
+ class MoveTargetOutOfBoundsError < WebDriverError; end
207
150
 
208
151
  #
209
152
  # A command could not be completed because the element is not pointer or keyboard
@@ -271,113 +214,6 @@ module Selenium
271
214
 
272
215
  class UnsupportedOperationError < WebDriverError; end
273
216
 
274
- # Aliases for OSS dialect.
275
- ScriptTimeoutError = Class.new(ScriptTimeOutError)
276
- TimeoutError = Class.new(TimeOutError)
277
- NoAlertOpenError = Class.new(NoAlertPresentError)
278
-
279
- # Aliases for backwards compatibility.
280
- ObsoleteElementError = Class.new(StaleElementReferenceError)
281
- UnhandledError = Class.new(UnknownError)
282
- UnexpectedJavascriptError = Class.new(JavascriptError)
283
- ElementNotDisplayedError = Class.new(ElementNotVisibleError)
284
-
285
- #
286
- # @api private
287
- #
288
-
289
- ERRORS = {
290
- 1 => IndexOutOfBoundsError,
291
- 2 => NoCollectionError,
292
- 3 => NoStringError,
293
- 4 => NoStringLengthError,
294
- 5 => NoStringWrapperError,
295
- 6 => NoSuchDriverError,
296
- 7 => NoSuchElementError,
297
- 8 => NoSuchFrameError,
298
- 9 => UnknownCommandError,
299
- 10 => StaleElementReferenceError,
300
- 11 => ElementNotVisibleError,
301
- 12 => InvalidElementStateError,
302
- 13 => UnknownError,
303
- 14 => ExpectedError,
304
- 15 => ElementNotSelectableError,
305
- 16 => NoSuchDocumentError,
306
- 17 => JavascriptError,
307
- 18 => NoScriptResultError,
308
- 19 => XPathLookupError,
309
- 20 => NoSuchCollectionError,
310
- 21 => TimeOutError,
311
- 22 => NullPointerError,
312
- 23 => NoSuchWindowError,
313
- 24 => InvalidCookieDomainError,
314
- 25 => UnableToSetCookieError,
315
- 26 => UnhandledAlertError,
316
- 27 => NoAlertPresentError,
317
- 28 => ScriptTimeOutError,
318
- 29 => InvalidElementCoordinatesError,
319
- 30 => IMENotAvailableError,
320
- 31 => IMEEngineActivationFailedError,
321
- 32 => InvalidSelectorError,
322
- 33 => SessionNotCreatedError,
323
- 34 => MoveTargetOutOfBoundsError,
324
- # The following are W3C-specific errors,
325
- # they don't really need error codes, we just make them up!
326
- 51 => InvalidXpathSelectorError,
327
- 52 => InvalidXpathSelectorReturnTyperError,
328
- 60 => ElementNotInteractableError,
329
- 61 => InvalidArgumentError,
330
- 62 => NoSuchCookieError,
331
- 63 => UnableToCaptureScreenError
332
- }.freeze
333
-
334
- DEPRECATED_ERRORS = {
335
- IndexOutOfBoundsError: nil,
336
- NoCollectionError: nil,
337
- NoStringError: nil,
338
- NoStringLengthError: nil,
339
- NoStringWrapperError: nil,
340
- NoSuchDriverError: nil,
341
- ElementNotVisibleError: ElementNotInteractableError,
342
- InvalidElementStateError: ElementNotInteractableError,
343
- ElementNotSelectableError: ElementNotInteractableError,
344
- ExpectedError: nil,
345
- NoSuchDocumentError: nil,
346
- NoScriptResultError: nil,
347
- XPathLookupError: InvalidSelectorError,
348
- NoSuchCollectionError: nil,
349
- UnhandledAlertError: UnexpectedAlertOpenError,
350
- NoAlertPresentError: NoSuchAlertError,
351
- NoAlertOpenError: NoSuchAlertError,
352
- ScriptTimeOutError: ScriptTimeoutError,
353
- InvalidElementCoordinatesError: nil,
354
- IMENotAvailableError: nil,
355
- IMEEngineActivationFailedError: nil,
356
- InvalidXpathSelectorError: InvalidSelectorError,
357
- InvalidXpathSelectorReturnTyperError: InvalidSelectorError,
358
- TimeOutError: TimeoutError,
359
- ObsoleteElementError: StaleElementReferenceError,
360
- UnhandledError: UnknownError,
361
- UnexpectedJavascriptError: JavascriptError,
362
- ElementNotDisplayedError: ElementNotInteractableError
363
- }.freeze
364
-
365
- DEPRECATED_ERRORS.keys.each do |oss_error|
366
- remove_const oss_error
367
- end
368
-
369
- def self.const_missing(const_name)
370
- super unless DEPRECATED_ERRORS.key?(const_name)
371
- if DEPRECATED_ERRORS[const_name]
372
- WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}",
373
- "#{DEPRECATED_ERRORS[const_name]} (ensure the driver supports W3C WebDriver specification)")
374
- DEPRECATED_ERRORS[const_name]
375
- else
376
- WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}")
377
- WebDriverError
378
- end
379
- end
380
-
381
217
  end # Error
382
218
  end # WebDriver
383
219
  end # Selenium
@@ -22,8 +22,15 @@ require 'securerandom'
22
22
  module Selenium
23
23
  module WebDriver
24
24
  module Interactions
25
+ #
26
+ # Superclass for the input device sources
27
+ # Manages Array of Interaction instances for the device
28
+ #
29
+ # @api private
30
+ #
31
+
25
32
  class InputDevice
26
- attr_reader :name, :actions
33
+ attr_reader :name, :actions, :type
27
34
 
28
35
  def initialize(name = nil)
29
36
  @name = name || SecureRandom.uuid
@@ -44,9 +51,8 @@ module Selenium
44
51
  add_action(Pause.new(self, duration))
45
52
  end
46
53
 
47
- def no_actions? # Determine if only pauses are present
48
- actions = @actions.reject { |action| action.type == Interaction::PAUSE }
49
- actions.empty?
54
+ def encode
55
+ {type: type, id: name, actions: @actions.map(&:encode)} unless @actions.empty?
50
56
  end
51
57
  end # InputDevice
52
58
  end # Interactions
@@ -20,34 +20,24 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Interactions
23
- class Interaction
24
- PAUSE = :pause
23
+ #
24
+ # Superclass for classes defining actions
25
+ # Do not initialize directly, only use subclass
26
+ #
27
+ # @api private
28
+ #
25
29
 
26
- attr_reader :source
30
+ class Interaction
31
+ attr_reader :type
27
32
 
28
33
  def initialize(source)
29
- raise TypeError, "#{source.type} is not a valid input type" unless Interactions::SOURCE_TYPES.include? source.type
30
-
31
- @source = source
34
+ assert_source(source)
32
35
  end
33
- end
34
36
 
35
- class Pause < Interaction
36
- def initialize(source, duration = nil)
37
- super(source)
38
- @duration = duration
37
+ def assert_source(_source)
38
+ raise NotImplementedError, 'subclass responsibility'
39
39
  end
40
-
41
- def type
42
- PAUSE
43
- end
44
-
45
- def encode
46
- output = {type: type}
47
- output[:duration] = (@duration * 1000).to_i if @duration
48
- output
49
- end
50
- end # Interaction
40
+ end
51
41
  end # Interactions
52
42
  end # WebDriver
53
43
  end # Selenium
@@ -23,20 +23,40 @@ module Selenium
23
23
  KEY = :key
24
24
  POINTER = :pointer
25
25
  NONE = :none
26
- SOURCE_TYPES = [KEY, POINTER, NONE].freeze
26
+ WHEEL = :wheel
27
+
28
+ #
29
+ # Class methods for initializing known Input devices
30
+ #
27
31
 
28
32
  class << self
29
- def key(name)
33
+ def key(name = nil)
30
34
  KeyInput.new(name)
31
35
  end
32
36
 
33
- def pointer(kind, **kwargs)
34
- PointerInput.new(kind, **kwargs)
37
+ def pointer(kind = :mouse, name: nil)
38
+ PointerInput.new(kind, name: name)
39
+ end
40
+
41
+ def mouse(name: nil)
42
+ pointer(name: name)
43
+ end
44
+
45
+ def pen(name: nil)
46
+ pointer(:pen, name: name)
47
+ end
48
+
49
+ def touch(name: nil)
50
+ pointer(:touch, name: name)
35
51
  end
36
52
 
37
53
  def none(name = nil)
38
54
  NoneInput.new(name)
39
55
  end
56
+
57
+ def wheel(name = nil)
58
+ WheelInput.new(name)
59
+ end
40
60
  end
41
61
  end # Interactions
42
62
  end # WebDriver