Skip to content

Commit 75d235f

Browse files
committed
Remove OSS dialect errors
As a part of initiative to remove OSS dialect and support only W3C, all the errors not compliant to specification were removed. It seems like server/grid passes through all the errors from drivers without altering them (with the only exception of custom error when trying to upload multiple files to server using POST /se/file - it's handled just fine by Ruby bindings).
1 parent 45ba014 commit 75d235f

File tree

6 files changed

+46
-315
lines changed

6 files changed

+46
-315
lines changed

rb/lib/selenium/webdriver/common/error.rb

Lines changed: 27 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -19,191 +19,122 @@
1919

2020
module Selenium
2121
module WebDriver
22-
module Error # rubocop:disable Metrics/ModuleLength
22+
module Error
2323

2424
#
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
2727
#
2828

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
4035
WebDriverError
4136
end
4237

4338
class WebDriverError < StandardError; end
4439

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-
5240
#
5341
# An element could not be located on the page using the given search parameters.
5442
#
5543

56-
class NoSuchElementError < WebDriverError; end # 7
44+
class NoSuchElementError < WebDriverError; end
5745

5846
#
5947
# A command to switch to a frame could not be satisfied because the frame could not be found.
6048
#
6149

62-
class NoSuchFrameError < WebDriverError; end # 8
50+
class NoSuchFrameError < WebDriverError; end
6351

6452
#
6553
# A command could not be executed because the remote end is not aware of it.
6654
#
6755

68-
class UnknownCommandError < WebDriverError; end # 9
56+
class UnknownCommandError < WebDriverError; end
6957

7058
#
7159
# A command failed because the referenced element is no longer attached to the DOM.
7260
#
7361

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
8263

8364
#
8465
# The target element is in an invalid state, rendering it impossible to interact with, for
8566
# example if you click a disabled element.
8667
#
8768

88-
class InvalidElementStateError < WebDriverError; end # 12
69+
class InvalidElementStateError < WebDriverError; end
8970

9071
#
9172
# An unknown error occurred in the remote end while processing the command.
9273
#
9374

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
10376

10477
#
10578
# An error occurred while executing JavaScript supplied by the user.
10679
#
10780

108-
class JavascriptError < WebDriverError; end # 17
109-
class NoScriptResultError < WebDriverError; end # 18
81+
class JavascriptError < WebDriverError; end
11082

11183
#
112-
# An error occurred while searching for an element by XPath.
84+
# An operation did not complete before its timeout expired.
11385
#
11486

115-
class XPathLookupError < WebDriverError; end # 19
116-
class NoSuchCollectionError < WebDriverError; end # 20
87+
class TimeoutError < WebDriverError; end
11788

11889
#
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.
12092
#
12193

122-
class TimeOutError < WebDriverError; end # 21
123-
124-
class NullPointerError < WebDriverError; end # 22
125-
class NoSuchWindowError < WebDriverError; end # 23
94+
class NoSuchWindowError < WebDriverError; end
12695

12796
#
12897
# An illegal attempt was made to set a cookie under a different domain than the current page.
12998
#
13099

131-
class InvalidCookieDomainError < WebDriverError; end # 24
100+
class InvalidCookieDomainError < WebDriverError; end
132101

133102
#
134103
# A command to set a cookie's value could not be satisfied.
135104
#
136105

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
143107

144108
#
145109
# An attempt was made to operate on a modal dialog when one was not open:
146110
#
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-
#
153111

154112
class NoSuchAlertError < WebDriverError; end
155-
class NoAlertPresentError < NoSuchAlertError; end # 27
156113

157114
#
158115
# A script did not complete before its timeout expired.
159116
#
160117

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
181119

182120
#
183121
# Argument was an invalid selector.
184122
#
185123

186-
class InvalidSelectorError < WebDriverError; end # 32
124+
class InvalidSelectorError < WebDriverError; end
187125

188126
#
189127
# A new session could not be created.
190128
#
191129

192-
class SessionNotCreatedError < WebDriverError; end # 33
130+
class SessionNotCreatedError < WebDriverError; end
193131

194132
#
195133
# The target for mouse interaction is not in the browser's viewport and cannot be brought
196134
# into that viewport.
197135
#
198136

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
207138

208139
#
209140
# A command could not be completed because the element is not pointer or keyboard
@@ -271,113 +202,6 @@ class ElementClickInterceptedError < WebDriverError; end
271202

272203
class UnsupportedOperationError < WebDriverError; end
273204

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-
381205
end # Error
382206
end # WebDriver
383207
end # Selenium

0 commit comments

Comments
 (0)