selenium-webdriver 3.142.6 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +369 -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 +69 -63
  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/chrome/driver.rb +26 -70
  13. data/lib/selenium/webdriver/chrome/{bridge.rb → features.rb} +50 -12
  14. data/lib/selenium/webdriver/chrome/options.rb +128 -53
  15. data/lib/selenium/webdriver/chrome/profile.rb +8 -5
  16. data/lib/selenium/webdriver/chrome/service.rb +8 -15
  17. data/lib/selenium/webdriver/chrome.rb +10 -9
  18. data/lib/selenium/webdriver/common/action_builder.rb +97 -249
  19. data/lib/selenium/webdriver/common/driver.rb +112 -23
  20. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +43 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +51 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +89 -0
  23. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +77 -0
  24. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_cdp.rb} +10 -8
  25. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +45 -0
  26. data/lib/selenium/webdriver/{firefox/util.rb → common/driver_extensions/has_devtools.rb} +16 -19
  27. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +38 -0
  28. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +5 -8
  29. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +144 -0
  30. data/lib/selenium/webdriver/common/driver_extensions/has_logs.rb +30 -0
  31. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +17 -0
  32. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +6 -27
  33. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +136 -0
  34. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -11
  35. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +77 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +1 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  38. data/lib/selenium/webdriver/common/element.rb +82 -22
  39. data/lib/selenium/webdriver/common/error.rb +32 -196
  40. data/lib/selenium/webdriver/common/interactions/interaction.rb +4 -1
  41. data/lib/selenium/webdriver/common/interactions/key_actions.rb +5 -5
  42. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +13 -13
  43. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  44. data/lib/selenium/webdriver/common/logger.rb +50 -15
  45. data/lib/selenium/webdriver/common/manager.rb +15 -15
  46. data/lib/selenium/webdriver/common/options.rb +184 -0
  47. data/lib/selenium/webdriver/common/platform.rb +6 -1
  48. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  49. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  50. data/lib/selenium/webdriver/common/proxy.rb +6 -3
  51. data/lib/selenium/webdriver/common/search_context.rb +7 -3
  52. data/lib/selenium/webdriver/common/service.rb +17 -125
  53. data/lib/selenium/webdriver/common/service_manager.rb +151 -0
  54. data/lib/selenium/webdriver/common/shadow_root.rb +87 -0
  55. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  56. data/lib/selenium/webdriver/common/socket_poller.rb +2 -2
  57. data/lib/selenium/webdriver/common/takes_screenshot.rb +66 -0
  58. data/lib/selenium/webdriver/common/target_locator.rb +32 -4
  59. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  60. data/lib/selenium/webdriver/common/wait.rb +1 -1
  61. data/lib/selenium/webdriver/common/window.rb +0 -4
  62. data/lib/selenium/webdriver/common/zipper.rb +3 -9
  63. data/lib/selenium/webdriver/common.rb +24 -17
  64. data/lib/selenium/webdriver/devtools/console_event.rb +38 -0
  65. data/lib/selenium/webdriver/devtools/exception_event.rb +36 -0
  66. data/lib/selenium/webdriver/devtools/mutation_event.rb +37 -0
  67. data/lib/selenium/webdriver/devtools/pinned_script.rb +59 -0
  68. data/lib/selenium/webdriver/devtools/request.rb +67 -0
  69. data/lib/selenium/webdriver/devtools/response.rb +66 -0
  70. data/lib/selenium/webdriver/devtools.rb +193 -0
  71. data/lib/selenium/webdriver/edge/driver.rb +7 -29
  72. data/lib/selenium/webdriver/edge/features.rb +44 -0
  73. data/lib/selenium/webdriver/edge/options.rb +11 -48
  74. data/lib/selenium/webdriver/{common/w3c_manager.rb → edge/profile.rb} +7 -19
  75. data/lib/selenium/webdriver/edge/service.rb +10 -26
  76. data/lib/selenium/webdriver/edge.rb +11 -14
  77. data/lib/selenium/webdriver/firefox/driver.rb +31 -19
  78. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  79. data/lib/selenium/webdriver/firefox/features.rb +66 -0
  80. data/lib/selenium/webdriver/firefox/options.rb +71 -50
  81. data/lib/selenium/webdriver/firefox/profile.rb +21 -71
  82. data/lib/selenium/webdriver/firefox/service.rb +5 -9
  83. data/lib/selenium/webdriver/firefox.rb +22 -20
  84. data/lib/selenium/webdriver/ie/driver.rb +1 -47
  85. data/lib/selenium/webdriver/ie/options.rb +15 -46
  86. data/lib/selenium/webdriver/ie/service.rb +13 -15
  87. data/lib/selenium/webdriver/ie.rb +8 -7
  88. data/lib/selenium/webdriver/remote/bridge.rb +561 -86
  89. data/lib/selenium/webdriver/remote/capabilities.rb +159 -123
  90. data/lib/selenium/webdriver/remote/commands.rb +163 -0
  91. data/lib/selenium/webdriver/remote/driver.rb +22 -12
  92. data/lib/selenium/webdriver/remote/http/common.rb +0 -5
  93. data/lib/selenium/webdriver/remote/http/default.rb +17 -20
  94. data/lib/selenium/webdriver/remote/http/persistent.rb +11 -6
  95. data/lib/selenium/webdriver/remote/response.rb +16 -47
  96. data/lib/selenium/webdriver/remote.rb +15 -12
  97. data/lib/selenium/webdriver/safari/driver.rb +3 -31
  98. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +3 -3
  99. data/lib/selenium/webdriver/safari/options.rb +10 -29
  100. data/lib/selenium/webdriver/safari/service.rb +4 -8
  101. data/lib/selenium/webdriver/safari.rb +17 -9
  102. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  103. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +63 -0
  104. data/lib/selenium/webdriver/support/cdp_client_generator.rb +108 -0
  105. data/lib/selenium/webdriver/support/color.rb +2 -2
  106. data/lib/selenium/webdriver/support/event_firing_bridge.rb +4 -4
  107. data/lib/selenium/webdriver/support/guards/guard.rb +89 -0
  108. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +22 -19
  109. data/lib/selenium/webdriver/support/guards.rb +95 -0
  110. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  111. data/lib/selenium/webdriver/support/select.rb +3 -3
  112. data/lib/selenium/webdriver/support.rb +1 -0
  113. data/lib/selenium/webdriver/version.rb +1 -1
  114. data/lib/selenium/webdriver.rb +13 -13
  115. data/selenium-webdriver.gemspec +28 -12
  116. metadata +129 -69
  117. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  118. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  119. data/lib/selenium/webdriver/common/keyboard.rb +0 -70
  120. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  121. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  122. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  123. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  124. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  125. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  126. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  127. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  128. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  129. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  130. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  131. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  132. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  133. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  134. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  135. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  136. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  137. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -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
@@ -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
@@ -22,7 +22,7 @@ module Selenium
22
22
  module KeyActions
23
23
  #
24
24
  # Performs a key press. Does not release the key - subsequent interactions may assume it's kept pressed.
25
- # Note that the key is never released implicitly - either W3CActionBuilder#key_up(key) or W3CActionBuilder#release_actions
25
+ # Note that the key is never released implicitly - either ActionBuilder#key_up(key) or ActionBuilder#release_actions
26
26
  # must be called to release the key.
27
27
  #
28
28
  # @example Press a key
@@ -41,7 +41,7 @@ module Selenium
41
41
  # @param [Element] element An optional element to move to first
42
42
  # @param [Symbol, String] key The key to press
43
43
  # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
44
- # @return [W3CActionBuilder] A self reference
44
+ # @return [ActionBuilder] A self reference
45
45
  #
46
46
 
47
47
  def key_down(*args, device: nil)
@@ -68,7 +68,7 @@ module Selenium
68
68
  # @param [Element] element An optional element to move to first
69
69
  # @param [Symbol, String] key The key to release
70
70
  # @param [Symbol, String] device Optional name of the KeyInput device to release the key on
71
- # @return [W3CActionBuilder] A self reference
71
+ # @return [ActionBuilder] A self reference
72
72
  #
73
73
 
74
74
  def key_up(*args, device: nil)
@@ -98,7 +98,7 @@ module Selenium
98
98
  # @param [Element] element An optional element to move to first
99
99
  # @param [Array, Symbol, String] keys The key(s) to press and release
100
100
  # @param [Symbol, String] device Optional name of the KeyInput device to press and release the keys on
101
- # @return [W3CActionBuilder] A self reference
101
+ # @return [ActionBuilder] A self reference
102
102
  #
103
103
 
104
104
  def send_keys(*args, device: nil)
@@ -130,7 +130,7 @@ module Selenium
130
130
  # @option args [Symbol, String] key The key to perform the action with
131
131
  # @param [Symbol] action The name of the key action to perform
132
132
  # @param [Symbol, String] device optional name of the KeyInput device to press the key on
133
- # @return [W3CActionBuilder] A self reference
133
+ # @return [ActionBuilder] A self reference
134
134
  #
135
135
 
136
136
  def key_action(*args, action: nil, device: nil)
@@ -42,7 +42,7 @@ module Selenium
42
42
  # @param [Selenium::WebDriver::Interactions::PointerPress::BUTTONS] button the button to press.
43
43
  # @param [Symbol || String] device optional name of the PointerInput device with the button
44
44
  # that will be pressed
45
- # @return [W3CActionBuilder] A self reference.
45
+ # @return [ActionBuilder] A self reference.
46
46
  #
47
47
 
48
48
  def pointer_down(button, device: nil)
@@ -59,7 +59,7 @@ module Selenium
59
59
  # @param [Selenium::WebDriver::Interactions::PointerPress::BUTTONS] button the button to release.
60
60
  # @param [Symbol || String] device optional name of the PointerInput device with the button that will
61
61
  # be released
62
- # @return [W3CActionBuilder] A self reference.
62
+ # @return [ActionBuilder] A self reference.
63
63
  #
64
64
 
65
65
  def pointer_up(button, device: nil)
@@ -71,7 +71,7 @@ module Selenium
71
71
  # view and its location is calculated using getBoundingClientRect. Then the
72
72
  # mouse is moved to optional offset coordinates from the element.
73
73
  #
74
- # This is adapted to be backward compatible from non-W3C actions. W3C calculates offset from the center point
74
+ # This is adapted to be backward compatible from non- actions. calculates offset from the center point
75
75
  # of the element
76
76
  #
77
77
  # Note that when using offsets, both coordinates need to be passed.
@@ -92,7 +92,7 @@ module Selenium
92
92
  # @param [Integer] down_by Optional offset from the top-left corner. A negative value means
93
93
  # coordinates above the element.
94
94
  # @param [Symbol || String] device optional name of the PointerInput device to move.
95
- # @return [W3CActionBuilder] A self reference.
95
+ # @return [ActionBuilder] A self reference.
96
96
  #
97
97
 
98
98
  def move_to(element, right_by = nil, down_by = nil, device: nil)
@@ -129,7 +129,7 @@ module Selenium
129
129
  # @param [Integer] right_by horizontal offset. A negative value means moving the mouse left.
130
130
  # @param [Integer] down_by vertical offset. A negative value means moving the mouse up.
131
131
  # @param [Symbol || String] device optional name of the PointerInput device to move
132
- # @return [W3CActionBuilder] A self reference.
132
+ # @return [ActionBuilder] A self reference.
133
133
  # @raise [MoveTargetOutOfBoundsError] if the provided offset is outside the document's boundaries.
134
134
  #
135
135
 
@@ -156,7 +156,7 @@ module Selenium
156
156
  # @param [Integer] x horizontal position. Equivalent to a css 'left' value.
157
157
  # @param [Integer] y vertical position. Equivalent to a css 'top' value.
158
158
  # @param [Symbol || String] device optional name of the PointerInput device to move
159
- # @return [W3CActionBuilder] A self reference.
159
+ # @return [ActionBuilder] A self reference.
160
160
  # @raise [MoveTargetOutOfBoundsError] if the provided x or y value is outside the document's boundaries.
161
161
  #
162
162
 
@@ -183,7 +183,7 @@ module Selenium
183
183
  #
184
184
  # @param [Selenium::WebDriver::Element] element the element to move to and click.
185
185
  # @param [Symbol || String] device optional name of the PointerInput device to click with
186
- # @return [W3CActionBuilder] A self reference.
186
+ # @return [ActionBuilder] A self reference.
187
187
  #
188
188
 
189
189
  def click_and_hold(element = nil, device: nil)
@@ -202,7 +202,7 @@ module Selenium
202
202
  #
203
203
  # @param [Symbol || String] device optional name of the PointerInput device with the button
204
204
  # that will be released
205
- # @return [W3CActionBuilder] A self reference.
205
+ # @return [ActionBuilder] A self reference.
206
206
  #
207
207
 
208
208
  def release(device: nil)
@@ -229,7 +229,7 @@ module Selenium
229
229
  # @param [Selenium::WebDriver::Element] element An optional element to click.
230
230
  # @param [Symbol || String] device optional name of the PointerInput device with the button
231
231
  # that will be clicked
232
- # @return [W3CActionBuilder] A self reference.
232
+ # @return [ActionBuilder] A self reference.
233
233
  #
234
234
 
235
235
  def click(element = nil, device: nil)
@@ -258,7 +258,7 @@ module Selenium
258
258
  # @param [Selenium::WebDriver::Element] element An optional element to move to.
259
259
  # @param [Symbol || String] device optional name of the PointerInput device with the button
260
260
  # that will be double-clicked
261
- # @return [W3CActionBuilder] A self reference.
261
+ # @return [ActionBuilder] A self reference.
262
262
  #
263
263
 
264
264
  def double_click(element = nil, device: nil)
@@ -286,7 +286,7 @@ module Selenium
286
286
  # @param [Selenium::WebDriver::Element] element An element to context click.
287
287
  # @param [Symbol || String] device optional name of the PointerInput device with the button
288
288
  # that will be context-clicked
289
- # @return [W3CActionBuilder] A self reference.
289
+ # @return [ActionBuilder] A self reference.
290
290
  #
291
291
 
292
292
  def context_click(element = nil, device: nil)
@@ -312,7 +312,7 @@ module Selenium
312
312
  # mouse at.
313
313
  # @param [Symbol || String] device optional name of the PointerInput device with the button
314
314
  # that will perform the drag and drop
315
- # @return [W3CActionBuilder] A self reference.
315
+ # @return [ActionBuilder] A self reference.
316
316
  #
317
317
 
318
318
  def drag_and_drop(source, target, device: nil)
@@ -336,7 +336,7 @@ module Selenium
336
336
  # @param [Integer] down_by vertical move offset.
337
337
  # @param [Symbol || String] device optional name of the PointerInput device with the button
338
338
  # that will perform the drag and drop
339
- # @return [W3CActionBuilder] A self reference.
339
+ # @return [ActionBuilder] A self reference.
340
340
  #
341
341
 
342
342
  def drag_and_drop_by(source, right_by, down_by, device: nil)
@@ -30,14 +30,14 @@ module Selenium
30
30
 
31
31
  def as_json(*)
32
32
  {
33
- 'level' => level,
34
33
  'timestamp' => timestamp,
34
+ 'level' => level,
35
35
  'message' => message
36
36
  }
37
37
  end
38
38
 
39
39
  def to_s
40
- "#{level} #{time}: #{message}"
40
+ "#{time} #{level}: #{message}"
41
41
  end
42
42
 
43
43
  def time
@@ -40,13 +40,17 @@ module Selenium
40
40
  :close,
41
41
  :debug, :debug?,
42
42
  :info, :info?,
43
- :warn, :warn?,
43
+ :warn?,
44
44
  :error, :error?,
45
45
  :fatal, :fatal?,
46
46
  :level, :level=
47
47
 
48
- def initialize
49
- @logger = create_logger($stdout)
48
+ #
49
+ # @param [String] progname Allow child projects to use Selenium's Logger pattern
50
+ #
51
+ def initialize(progname = 'Selenium')
52
+ @logger = create_logger(progname)
53
+ @ignored = []
50
54
  end
51
55
 
52
56
  #
@@ -73,28 +77,63 @@ module Selenium
73
77
  @logger.instance_variable_get(:@logdev).dev
74
78
  end
75
79
 
80
+ #
81
+ # Will not log the provided ID.
82
+ #
83
+ # @param [Array, Symbol] id
84
+ #
85
+ def ignore(id)
86
+ Array(id).each { |ignore| @ignored << ignore }
87
+ end
88
+
89
+ #
90
+ # Overrides default #warn to skip ignored messages by provided id
91
+ #
92
+ # @param [String] message
93
+ # @param [Symbol, Array<Sybmol>] id
94
+ # @yield see #deprecate
95
+ #
96
+ def warn(message, id: [])
97
+ id = Array(id)
98
+ return if (@ignored & id).any?
99
+
100
+ msg = id.empty? ? message : "[#{id.map(&:inspect).join(', ')}] #{message} "
101
+ msg += " #{yield}" if block_given?
102
+
103
+ @logger.warn { msg }
104
+ end
105
+
76
106
  #
77
107
  # Marks code as deprecated with/without replacement.
78
108
  #
79
109
  # @param [String] old
80
110
  # @param [String, nil] new
111
+ # @param [Symbol, Array<Symbol>] id
112
+ # @param [String] reference
113
+ # @yield appends additional message to end of provided template
81
114
  #
82
- def deprecate(old, new = nil)
83
- message = +"[DEPRECATION] #{old} is deprecated"
115
+ def deprecate(old, new = nil, id: [], reference: '', &block)
116
+ id = Array(id)
117
+ return if @ignored.include?(:deprecations) || (@ignored & id).any?
118
+
119
+ ids = id.empty? ? '' : "[#{id.map(&:inspect).join(', ')}] "
120
+
121
+ message = +"[DEPRECATION] #{ids}#{old} is deprecated"
84
122
  message << if new
85
123
  ". Use #{new} instead."
86
124
  else
87
- ' and will be removed in the next releases.'
125
+ ' and will be removed in a future release.'
88
126
  end
127
+ message << " See explanation for this deprecation: #{reference}." unless reference.empty?
89
128
 
90
- warn message
129
+ warn message, &block
91
130
  end
92
131
 
93
132
  private
94
133
 
95
- def create_logger(output)
96
- logger = ::Logger.new(output)
97
- logger.progname = 'Selenium'
134
+ def create_logger(name)
135
+ logger = ::Logger.new($stdout)
136
+ logger.progname = name
98
137
  logger.level = default_level
99
138
  logger.formatter = proc do |severity, time, progname, msg|
100
139
  "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
@@ -104,11 +143,7 @@ module Selenium
104
143
  end
105
144
 
106
145
  def default_level
107
- if $DEBUG || ENV.key?('DEBUG')
108
- :debug
109
- else
110
- :warn
111
- end
146
+ $DEBUG || ENV.key?('DEBUG') ? :debug : :warn
112
147
  end
113
148
  end # Logger
114
149
  end # WebDriver