|
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 |
75 |
| - |
76 |
| - # |
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. |
79 |
| - # |
80 |
| - |
81 |
| - class ElementNotVisibleError < WebDriverError; end # 11 |
| 62 | + class StaleElementReferenceError < WebDriverError; end |
82 | 63 |
|
83 | 64 | #
|
84 | 65 | # The target element is in an invalid state, rendering it impossible to interact with, for
|
85 | 66 | # example if you click a disabled element.
|
86 | 67 | #
|
87 | 68 |
|
88 |
| - class InvalidElementStateError < WebDriverError; end # 12 |
| 69 | + class InvalidElementStateError < WebDriverError; end |
89 | 70 |
|
90 | 71 | #
|
91 | 72 | # An unknown error occurred in the remote end while processing the command.
|
92 | 73 | #
|
93 | 74 |
|
94 |
| - class UnknownError < WebDriverError; end # 13 |
95 |
| - class ExpectedError < WebDriverError; end # 14 |
96 |
| - |
97 |
| - # |
98 |
| - # An attempt was made to select an element that cannot be selected. |
99 |
| - # |
100 |
| - |
101 |
| - class ElementNotSelectableError < WebDriverError; end # 15 |
102 |
| - class NoSuchDocumentError < WebDriverError; end # 16 |
| 75 | + class UnknownError < WebDriverError; end |
103 | 76 |
|
104 | 77 | #
|
105 | 78 | # An error occurred while executing JavaScript supplied by the user.
|
106 | 79 | #
|
107 | 80 |
|
108 |
| - class JavascriptError < WebDriverError; end # 17 |
109 |
| - class NoScriptResultError < WebDriverError; end # 18 |
| 81 | + class JavascriptError < WebDriverError; end |
110 | 82 |
|
111 | 83 | #
|
112 |
| - # An error occurred while searching for an element by XPath. |
| 84 | + # An operation did not complete before its timeout expired. |
113 | 85 | #
|
114 | 86 |
|
115 |
| - class XPathLookupError < WebDriverError; end # 19 |
116 |
| - class NoSuchCollectionError < WebDriverError; end # 20 |
| 87 | + class TimeoutError < WebDriverError; end |
117 | 88 |
|
118 | 89 | #
|
119 |
| - # An operation did not complete before its timeout expired. |
| 90 | + # A command to switch to a window could not be satisfied because |
| 91 | + # the window could not be found. |
120 | 92 | #
|
121 | 93 |
|
122 |
| - class TimeOutError < WebDriverError; end # 21 |
123 |
| - |
124 |
| - class NullPointerError < WebDriverError; end # 22 |
125 |
| - class NoSuchWindowError < WebDriverError; end # 23 |
| 94 | + class NoSuchWindowError < WebDriverError; end |
126 | 95 |
|
127 | 96 | #
|
128 | 97 | # An illegal attempt was made to set a cookie under a different domain than the current page.
|
129 | 98 | #
|
130 | 99 |
|
131 |
| - class InvalidCookieDomainError < WebDriverError; end # 24 |
| 100 | + class InvalidCookieDomainError < WebDriverError; end |
132 | 101 |
|
133 | 102 | #
|
134 | 103 | # A command to set a cookie's value could not be satisfied.
|
135 | 104 | #
|
136 | 105 |
|
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 |
| 106 | + class UnableToSetCookieError < WebDriverError; end |
143 | 107 |
|
144 | 108 | #
|
145 | 109 | # An attempt was made to operate on a modal dialog when one was not open:
|
146 | 110 | #
|
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 | 111 |
|
154 | 112 | class NoSuchAlertError < WebDriverError; end
|
155 |
| - class NoAlertPresentError < NoSuchAlertError; end # 27 |
156 | 113 |
|
157 | 114 | #
|
158 | 115 | # A script did not complete before its timeout expired.
|
159 | 116 | #
|
160 | 117 |
|
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 |
| 118 | + class ScriptTimeoutError < WebDriverError; end |
181 | 119 |
|
182 | 120 | #
|
183 | 121 | # Argument was an invalid selector.
|
184 | 122 | #
|
185 | 123 |
|
186 |
| - class InvalidSelectorError < WebDriverError; end # 32 |
| 124 | + class InvalidSelectorError < WebDriverError; end |
187 | 125 |
|
188 | 126 | #
|
189 | 127 | # A new session could not be created.
|
190 | 128 | #
|
191 | 129 |
|
192 |
| - class SessionNotCreatedError < WebDriverError; end # 33 |
| 130 | + class SessionNotCreatedError < WebDriverError; end |
193 | 131 |
|
194 | 132 | #
|
195 | 133 | # The target for mouse interaction is not in the browser's viewport and cannot be brought
|
196 | 134 | # into that viewport.
|
197 | 135 | #
|
198 | 136 |
|
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 |
| 137 | + class MoveTargetOutOfBoundsError < WebDriverError; end |
207 | 138 |
|
208 | 139 | #
|
209 | 140 | # A command could not be completed because the element is not pointer or keyboard
|
@@ -271,113 +202,6 @@ class ElementClickInterceptedError < WebDriverError; end
|
271 | 202 |
|
272 | 203 | class UnsupportedOperationError < WebDriverError; end
|
273 | 204 |
|
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 | 205 | end # Error
|
382 | 206 | end # WebDriver
|
383 | 207 | end # Selenium
|
0 commit comments