1
- # encoding: utf-8
2
- #
3
1
# Licensed to the Software Freedom Conservancy (SFC) under one
4
2
# or more contributor license agreements. See the NOTICE file
5
3
# distributed with this work for additional information
20
18
module Selenium
21
19
module WebDriver
22
20
module Error
23
- class WebDriverError < StandardError ; end
24
21
25
22
#
26
- # Indicates that a command that should have executed properly cannot be supported for some
27
- # reason.
23
+ # Returns exception from code (Integer - OSS, String - W3C).
24
+ # @param [Integer, String, nil] code
28
25
#
29
26
30
- class UnsupportedOperationError < WebDriverError ; end
27
+ def self . for_code ( code )
28
+ case code
29
+ when nil , 0
30
+ nil
31
+ when Integer
32
+ ERRORS . fetch ( code )
33
+ when String
34
+ klass_name = code . split ( ' ' ) . map ( &:capitalize ) . join . sub ( /Error$/ , '' )
35
+ const_get ( "#{ klass_name } Error" )
36
+ end
37
+ rescue NameError
38
+ WebDriverError
39
+ end
40
+
41
+ class WebDriverError < StandardError ; end
31
42
32
43
class IndexOutOfBoundsError < WebDriverError ; end # 1
33
44
class NoCollectionError < WebDriverError ; end # 2
@@ -107,6 +118,7 @@ class NoSuchCollectionError < WebDriverError; end # 20
107
118
#
108
119
109
120
class TimeOutError < WebDriverError ; end # 21
121
+
110
122
class NullPointerError < WebDriverError ; end # 22
111
123
class NoSuchWindowError < WebDriverError ; end # 23
112
124
@@ -117,7 +129,7 @@ class NoSuchWindowError < WebDriverError; end # 23
117
129
class InvalidCookieDomainError < WebDriverError ; end # 24
118
130
119
131
#
120
- # A command to set a cookie’ s value could not be satisfied.
132
+ # A command to set a cookie' s value could not be satisfied.
121
133
#
122
134
123
135
class UnableToSetCookieError < WebDriverError ; end # 25
@@ -128,10 +140,17 @@ class UnableToSetCookieError < WebDriverError; end # 25
128
140
class UnhandledAlertError < WebDriverError ; end # 26
129
141
130
142
#
131
- # Indicates that a user has tried to access an alert when one is not present.
143
+ # An attempt was made to operate on a modal dialog when one was not open:
144
+ #
145
+ # * W3C dialect is NoSuchAlertError
146
+ # * OSS dialect is NoAlertPresentError
147
+ #
148
+ # We want to allow clients to rescue NoSuchAlertError as a superclass for
149
+ # dialect-agnostic implementation, so NoAlertPresentError should inherit from it.
132
150
#
133
151
134
- class NoAlertPresentError < WebDriverError ; end # 27
152
+ class NoSuchAlertError < WebDriverError ; end
153
+ class NoAlertPresentError < NoSuchAlertError ; end # 27
135
154
136
155
#
137
156
# A script did not complete before its timeout expired.
@@ -171,7 +190,7 @@ class InvalidSelectorError < WebDriverError; end # 32
171
190
class SessionNotCreatedError < WebDriverError ; end # 33
172
191
173
192
#
174
- # The target for mouse interaction is not in the browser’ s viewport and cannot be brought
193
+ # The target for mouse interaction is not in the browser' s viewport and cannot be brought
175
194
# into that viewport.
176
195
#
177
196
@@ -181,48 +200,42 @@ class MoveTargetOutOfBoundsError < WebDriverError; end # 34
181
200
# Indicates that the XPath selector is invalid
182
201
#
183
202
184
- class InvalidXpathSelectorError < WebDriverError ; end # 51
185
- class InvalidXpathSelectorReturnTyperError < WebDriverError ; end # 52
203
+ class InvalidXpathSelectorError < WebDriverError ; end
204
+ class InvalidXpathSelectorReturnTyperError < WebDriverError ; end
186
205
187
206
#
188
207
# A command could not be completed because the element is not pointer or keyboard
189
208
# interactable.
190
209
#
191
210
192
- class ElementNotInteractableError < WebDriverError ; end # 60
211
+ class ElementNotInteractableError < WebDriverError ; end
193
212
194
213
#
195
214
# The arguments passed to a command are either invalid or malformed.
196
215
#
197
216
198
- class InvalidArgumentError < WebDriverError ; end # 61
217
+ class InvalidArgumentError < WebDriverError ; end
199
218
200
219
#
201
220
# No cookie matching the given path name was found amongst the associated cookies of the
202
- # current browsing context’ s active document.
221
+ # current browsing context' s active document.
203
222
#
204
223
205
- class NoSuchCookieError < WebDriverError ; end # 62
224
+ class NoSuchCookieError < WebDriverError ; end
206
225
207
226
#
208
227
# A screen capture was made impossible.
209
228
#
210
229
211
- class UnableToCaptureScreenError < WebDriverError ; end # 63
230
+ class UnableToCaptureScreenError < WebDriverError ; end
212
231
213
232
#
214
233
# Occurs if the given session id is not in the list of active sessions, meaning the session
215
- # either does not exist or that it’ s not active.
234
+ # either does not exist or that it' s not active.
216
235
#
217
236
218
237
class InvalidSessionIdError < WebDriverError ; end
219
238
220
- #
221
- # An attempt was made to operate on a modal dialog when one was not open.
222
- #
223
-
224
- class NoSuchAlertError < WebDriverError ; end
225
-
226
239
#
227
240
# A modal dialog was open, blocking this operation.
228
241
#
@@ -242,26 +255,37 @@ class UnknownMethodError < WebDriverError; end
242
255
243
256
class ElementClickInterceptedError < WebDriverError ; end
244
257
245
- # aliased for backwards compatibility
246
- NoAlertPresentError = NoSuchAlertError
247
- ScriptTimeOutError = ScriptTimeoutError
258
+ #
259
+ # Indicates that a command that should have executed properly cannot be supported for some
260
+ # reason.
261
+ #
262
+
263
+ class UnsupportedOperationError < WebDriverError ; end
264
+
265
+ # Aliases for OSS dialect.
266
+ ScriptTimeoutError = ScriptTimeOutError
267
+ NoAlertOpenError = NoAlertPresentError
268
+
269
+ # Aliases for backwards compatibility.
248
270
ObsoleteElementError = StaleElementReferenceError
249
271
UnhandledError = UnknownError
250
272
UnexpectedJavascriptError = JavascriptError
251
- NoAlertOpenError = NoAlertPresentError
252
273
ElementNotDisplayedError = ElementNotVisibleError
253
274
275
+ #
254
276
# @api private
277
+ #
278
+
255
279
ERRORS = {
256
- 1 => IndexOutOfBoundsError ,
257
- 2 => NoCollectionError ,
258
- 3 => NoStringError ,
259
- 4 => NoStringLengthError ,
260
- 5 => NoStringWrapperError ,
261
- 6 => NoSuchDriverError ,
262
- 7 => NoSuchElementError ,
263
- 8 => NoSuchFrameError ,
264
- 9 => UnknownCommandError ,
280
+ 1 => IndexOutOfBoundsError ,
281
+ 2 => NoCollectionError ,
282
+ 3 => NoStringError ,
283
+ 4 => NoStringLengthError ,
284
+ 5 => NoStringWrapperError ,
285
+ 6 => NoSuchDriverError ,
286
+ 7 => NoSuchElementError ,
287
+ 8 => NoSuchFrameError ,
288
+ 9 => UnknownCommandError ,
265
289
10 => StaleElementReferenceError ,
266
290
11 => ElementNotVisibleError ,
267
291
12 => InvalidElementStateError ,
@@ -287,6 +311,8 @@ class ElementClickInterceptedError < WebDriverError; end
287
311
32 => InvalidSelectorError ,
288
312
33 => SessionNotCreatedError ,
289
313
34 => MoveTargetOutOfBoundsError ,
314
+ # The following are W3C-specific errors,
315
+ # they don't really need error codes, we just make them up!
290
316
51 => InvalidXpathSelectorError ,
291
317
52 => InvalidXpathSelectorReturnTyperError ,
292
318
60 => ElementNotInteractableError ,
@@ -295,17 +321,6 @@ class ElementClickInterceptedError < WebDriverError; end
295
321
63 => UnableToCaptureScreenError
296
322
} . freeze
297
323
298
- class << self
299
- def for_code ( code )
300
- return if [ nil , 0 ] . include? code
301
- return ERRORS . fetch ( code ) if code . is_a? Integer
302
-
303
- klass_name = code . split ( ' ' ) . map ( &:capitalize ) . join
304
- Error . const_get ( "#{ klass_name . gsub ( 'Error' , '' ) } Error" )
305
- rescue NameError
306
- WebDriverError
307
- end
308
- end
309
324
end # Error
310
325
end # WebDriver
311
- end # Selenium
326
+ end # Selenium
0 commit comments