selenium-webdriver 2.45.0 → 3.142.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +795 -3
  3. data/Gemfile +2 -0
  4. data/{COPYING → LICENSE} +1 -3
  5. data/README.md +13 -9
  6. data/lib/selenium/server.rb +93 -71
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +7 -0
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +102 -0
  9. data/lib/selenium/webdriver/atoms.rb +37 -0
  10. data/lib/selenium/webdriver/chrome/bridge.rb +47 -99
  11. data/lib/selenium/webdriver/chrome/driver.rb +127 -0
  12. data/lib/selenium/webdriver/chrome/options.rb +190 -0
  13. data/lib/selenium/webdriver/chrome/profile.rb +40 -20
  14. data/lib/selenium/webdriver/chrome/service.rb +46 -62
  15. data/lib/selenium/webdriver/chrome.rb +34 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +69 -56
  17. data/lib/selenium/webdriver/common/alert.rb +25 -8
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +35 -20
  19. data/lib/selenium/webdriver/common/driver.rb +90 -63
  20. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +45 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +50 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +42 -0
  23. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +26 -11
  24. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +51 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +58 -0
  26. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +51 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +23 -6
  28. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +19 -2
  29. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +24 -7
  30. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +19 -3
  31. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +23 -7
  32. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +26 -5
  33. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +20 -6
  34. data/lib/selenium/webdriver/common/element.rb +79 -37
  35. data/lib/selenium/webdriver/common/error.rb +282 -106
  36. data/lib/selenium/webdriver/common/file_reaper.rb +23 -12
  37. data/lib/selenium/webdriver/common/html5/local_storage.rb +29 -12
  38. data/lib/selenium/webdriver/common/html5/session_storage.rb +29 -12
  39. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +29 -18
  40. data/lib/selenium/webdriver/common/interactions/input_device.rb +54 -0
  41. data/lib/selenium/webdriver/common/interactions/interaction.rb +53 -0
  42. data/lib/selenium/webdriver/common/interactions/interactions.rb +43 -0
  43. data/lib/selenium/webdriver/common/interactions/key_actions.rb +145 -0
  44. data/lib/selenium/webdriver/common/interactions/key_input.rb +66 -0
  45. data/lib/selenium/webdriver/common/interactions/none_input.rb +36 -0
  46. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +363 -0
  47. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +139 -0
  48. data/lib/selenium/webdriver/common/keyboard.rb +27 -12
  49. data/lib/selenium/webdriver/common/keys.rb +118 -81
  50. data/lib/selenium/webdriver/common/log_entry.rb +27 -8
  51. data/lib/selenium/webdriver/common/logger.rb +115 -0
  52. data/lib/selenium/webdriver/common/logs.rb +24 -7
  53. data/lib/selenium/webdriver/common/manager.rb +177 -0
  54. data/lib/selenium/webdriver/common/mouse.rb +29 -12
  55. data/lib/selenium/webdriver/common/navigation.rb +21 -4
  56. data/lib/selenium/webdriver/common/options.rb +43 -126
  57. data/lib/selenium/webdriver/common/platform.rb +101 -97
  58. data/lib/selenium/webdriver/common/port_prober.rb +24 -17
  59. data/lib/selenium/webdriver/common/profile_helper.rb +27 -11
  60. data/lib/selenium/webdriver/common/proxy.rb +86 -73
  61. data/lib/selenium/webdriver/common/search_context.rb +49 -33
  62. data/lib/selenium/webdriver/common/service.rb +219 -0
  63. data/lib/selenium/webdriver/common/socket_lock.rb +82 -0
  64. data/lib/selenium/webdriver/common/socket_poller.rb +47 -26
  65. data/lib/selenium/webdriver/common/target_locator.rb +35 -14
  66. data/lib/selenium/webdriver/common/timeouts.rb +23 -6
  67. data/lib/selenium/webdriver/common/touch_action_builder.rb +25 -11
  68. data/lib/selenium/webdriver/common/touch_screen.rb +42 -24
  69. data/lib/selenium/webdriver/common/w3c_action_builder.rb +212 -0
  70. data/lib/selenium/webdriver/common/w3c_manager.rb +45 -0
  71. data/lib/selenium/webdriver/common/wait.rb +34 -14
  72. data/lib/selenium/webdriver/common/window.rb +75 -16
  73. data/lib/selenium/webdriver/common/zipper.rb +26 -11
  74. data/lib/selenium/webdriver/common.rb +40 -7
  75. data/lib/selenium/webdriver/edge/bridge.rb +76 -0
  76. data/lib/selenium/webdriver/edge/driver.rb +66 -0
  77. data/lib/selenium/webdriver/edge/options.rb +80 -0
  78. data/lib/selenium/webdriver/edge/service.rb +52 -0
  79. data/lib/selenium/webdriver/edge.rb +44 -0
  80. data/lib/selenium/webdriver/firefox/binary.rb +70 -48
  81. data/lib/selenium/webdriver/firefox/driver.rb +50 -0
  82. data/lib/selenium/webdriver/firefox/extension/prefs.json +14 -13
  83. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  84. data/lib/selenium/webdriver/firefox/extension.rb +50 -19
  85. data/lib/selenium/webdriver/firefox/launcher.rb +33 -28
  86. data/lib/selenium/webdriver/firefox/legacy/driver.rb +83 -0
  87. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +49 -0
  88. data/lib/selenium/webdriver/firefox/marionette/driver.rb +90 -0
  89. data/lib/selenium/webdriver/firefox/options.rb +162 -0
  90. data/lib/selenium/webdriver/firefox/profile.rb +66 -48
  91. data/lib/selenium/webdriver/firefox/profiles_ini.rb +28 -16
  92. data/lib/selenium/webdriver/firefox/service.rb +52 -0
  93. data/lib/selenium/webdriver/firefox/util.rb +19 -2
  94. data/lib/selenium/webdriver/firefox.rb +46 -10
  95. data/lib/selenium/webdriver/ie/driver.rb +85 -0
  96. data/lib/selenium/webdriver/ie/options.rb +138 -0
  97. data/lib/selenium/webdriver/ie/service.rb +54 -0
  98. data/lib/selenium/webdriver/ie.rb +32 -10
  99. data/lib/selenium/webdriver/remote/bridge.rb +117 -572
  100. data/lib/selenium/webdriver/remote/capabilities.rb +116 -99
  101. data/lib/selenium/webdriver/remote/driver.rb +51 -0
  102. data/lib/selenium/webdriver/remote/http/common.rb +54 -23
  103. data/lib/selenium/webdriver/remote/http/curb.rb +30 -12
  104. data/lib/selenium/webdriver/remote/http/default.rb +85 -42
  105. data/lib/selenium/webdriver/remote/http/persistent.rb +29 -7
  106. data/lib/selenium/webdriver/remote/oss/bridge.rb +594 -0
  107. data/lib/selenium/webdriver/remote/oss/commands.rb +223 -0
  108. data/lib/selenium/webdriver/remote/response.rb +68 -30
  109. data/lib/selenium/webdriver/remote/server_error.rb +22 -5
  110. data/lib/selenium/webdriver/remote/w3c/bridge.rb +605 -0
  111. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +310 -0
  112. data/lib/selenium/webdriver/remote/w3c/commands.rb +157 -0
  113. data/lib/selenium/webdriver/remote.rb +27 -13
  114. data/lib/selenium/webdriver/safari/bridge.rb +38 -107
  115. data/lib/selenium/webdriver/safari/driver.rb +68 -0
  116. data/lib/selenium/webdriver/safari/options.rb +56 -75
  117. data/lib/selenium/webdriver/safari/service.rb +38 -0
  118. data/lib/selenium/webdriver/safari.rb +49 -31
  119. data/lib/selenium/webdriver/support/abstract_event_listener.rb +40 -6
  120. data/lib/selenium/webdriver/support/block_event_listener.rb +24 -7
  121. data/lib/selenium/webdriver/support/color.rb +82 -46
  122. data/lib/selenium/webdriver/support/escaper.rb +43 -0
  123. data/lib/selenium/webdriver/support/event_firing_bridge.rb +56 -39
  124. data/lib/selenium/webdriver/support/select.rb +66 -89
  125. data/lib/selenium/webdriver/support.rb +20 -0
  126. data/lib/selenium/webdriver/version.rb +24 -0
  127. data/lib/selenium/webdriver.rb +55 -25
  128. data/lib/selenium-webdriver.rb +19 -0
  129. data/selenium-webdriver.gemspec +42 -29
  130. metadata +331 -260
  131. data/Gemfile.lock +0 -48
  132. data/lib/selenium/client/base.rb +0 -132
  133. data/lib/selenium/client/driver.rb +0 -10
  134. data/lib/selenium/client/errors.rb +0 -9
  135. data/lib/selenium/client/extensions.rb +0 -118
  136. data/lib/selenium/client/idiomatic.rb +0 -488
  137. data/lib/selenium/client/javascript_expression_builder.rb +0 -116
  138. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -13
  139. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -13
  140. data/lib/selenium/client/legacy_driver.rb +0 -1720
  141. data/lib/selenium/client/protocol.rb +0 -104
  142. data/lib/selenium/client/selenium_helper.rb +0 -34
  143. data/lib/selenium/client.rb +0 -38
  144. data/lib/selenium/rake/server_task.rb +0 -157
  145. data/lib/selenium/webdriver/android/bridge.rb +0 -49
  146. data/lib/selenium/webdriver/android.rb +0 -9
  147. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -9
  148. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -42
  149. data/lib/selenium/webdriver/common/core_ext/string.rb +0 -5
  150. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +0 -17
  151. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +0 -39
  152. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  153. data/lib/selenium/webdriver/common/json_helper.rb +0 -34
  154. data/lib/selenium/webdriver/firefox/bridge.rb +0 -70
  155. data/lib/selenium/webdriver/firefox/socket_lock.rb +0 -61
  156. data/lib/selenium/webdriver/ie/bridge.rb +0 -69
  157. data/lib/selenium/webdriver/ie/server.rb +0 -90
  158. data/lib/selenium/webdriver/iphone/bridge.rb +0 -45
  159. data/lib/selenium/webdriver/iphone.rb +0 -9
  160. data/lib/selenium/webdriver/opera/bridge.rb +0 -112
  161. data/lib/selenium/webdriver/opera/service.rb +0 -49
  162. data/lib/selenium/webdriver/opera.rb +0 -24
  163. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -59
  164. data/lib/selenium/webdriver/phantomjs/service.rb +0 -90
  165. data/lib/selenium/webdriver/phantomjs.rb +0 -22
  166. data/lib/selenium/webdriver/remote/commands.rb +0 -192
  167. data/lib/selenium/webdriver/safari/browser.rb +0 -20
  168. data/lib/selenium/webdriver/safari/extensions.rb +0 -170
  169. data/lib/selenium/webdriver/safari/resources/SafariDriver.safariextz +0 -0
  170. data/lib/selenium/webdriver/safari/resources/client.js +0 -6903
  171. data/lib/selenium/webdriver/safari/server.rb +0 -145
  172. data/lib/selenium-client.rb +0 -2
@@ -1,33 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
22
  module HTML5
4
-
5
23
  class SessionStorage
6
24
  include Enumerable
7
25
  include SharedWebStorage
8
26
 
9
27
  def [](key)
10
- @bridge.getSessionStorageItem key
28
+ @bridge.session_storage_item key
11
29
  end
12
30
 
13
31
  def []=(key, value)
14
- @bridge.setSessionStorageItem key, value
32
+ @bridge.session_storage_item key, value
15
33
  end
16
34
 
17
35
  def delete(key)
18
- @bridge.removeSessionStorageItem key
36
+ @bridge.remove_session_storage_item key
19
37
  end
20
38
 
21
39
  def clear
22
- @bridge.clearSessionStorage
40
+ @bridge.clear_session_storage
23
41
  end
24
42
 
25
43
  def size
26
- @bridge.getSessionStorageSize
44
+ @bridge.session_storage_size
27
45
  end
28
46
 
29
47
  def keys
30
- @bridge.getSessionStorageKeys.reverse
48
+ @bridge.session_storage_keys.reverse
31
49
  end
32
50
 
33
51
  #
@@ -37,8 +55,7 @@ module Selenium
37
55
  def initialize(bridge)
38
56
  @bridge = bridge
39
57
  end
40
- end
41
-
42
- end
43
- end
44
- end
58
+ end # SessionStorage
59
+ end # HTML5
60
+ end # WebDriver
61
+ end # Selenium
@@ -1,7 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
1
20
  module Selenium
2
21
  module WebDriver
3
22
  module HTML5
4
-
5
23
  module SharedWebStorage
6
24
  include Enumerable
7
25
 
@@ -11,32 +29,25 @@ module Selenium
11
29
  alias_method :member?, :key?
12
30
  alias_method :has_key?, :key?
13
31
 
14
- def fetch(key, &blk)
15
- if self.key? key
16
- return self[key]
17
- end
32
+ def fetch(key)
33
+ return self[key] if key? key
34
+ return yield(key) if block_given?
18
35
 
19
- if block_given?
20
- yield key
21
- else
22
- # should be KeyError, but it's 1.9-specific
23
- raise IndexError, "missing key #{key.inspect}"
24
- end
36
+ raise KeyError, "missing key #{key.inspect}"
25
37
  end
26
38
 
27
39
  def empty?
28
- size == 0
40
+ to_a.empty?
29
41
  end
30
42
 
31
- def each(&blk)
43
+ def each
32
44
  return enum_for(:each) unless block_given?
33
45
 
34
46
  keys.each do |k|
35
47
  yield k, self[k]
36
48
  end
37
49
  end
38
- end
39
-
40
- end
41
- end
42
- end
50
+ end # SharedWebStorage
51
+ end # HTML5
52
+ end # WebDriver
53
+ end # Selenium
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ require 'securerandom'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module Interactions
25
+ class InputDevice
26
+ attr_reader :name, :actions
27
+
28
+ def initialize(name = nil)
29
+ @name = name || SecureRandom.uuid
30
+ @actions = []
31
+ end
32
+
33
+ def add_action(action)
34
+ raise TypeError, "#{action.inspect} is not a valid action" unless action.class < Interaction
35
+
36
+ @actions << action
37
+ end
38
+
39
+ def clear_actions
40
+ @actions.clear
41
+ end
42
+
43
+ def create_pause(duration = 0)
44
+ add_action(Pause.new(self, duration))
45
+ end
46
+
47
+ def no_actions? # Determine if only pauses are present
48
+ actions = @actions.reject { |action| action.type == Interaction::PAUSE }
49
+ actions.empty?
50
+ end
51
+ end # InputDevice
52
+ end # Interactions
53
+ end # WebDriver
54
+ end # Selenium
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module Interactions
23
+ class Interaction
24
+ PAUSE = :pause
25
+
26
+ attr_reader :source
27
+
28
+ 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
32
+ end
33
+ end
34
+
35
+ class Pause < Interaction
36
+ def initialize(source, duration = nil)
37
+ super(source)
38
+ @duration = duration
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
51
+ end # Interactions
52
+ end # WebDriver
53
+ end # Selenium
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module Interactions
23
+ KEY = :key
24
+ POINTER = :pointer
25
+ NONE = :none
26
+ SOURCE_TYPES = [KEY, POINTER, NONE].freeze
27
+
28
+ class << self
29
+ def key(name)
30
+ KeyInput.new(name)
31
+ end
32
+
33
+ def pointer(kind, **kwargs)
34
+ PointerInput.new(kind, **kwargs)
35
+ end
36
+
37
+ def none(name = nil)
38
+ NoneInput.new(name)
39
+ end
40
+ end
41
+ end # Interactions
42
+ end # WebDriver
43
+ end # Selenium
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module KeyActions
23
+ #
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
26
+ # must be called to release the key.
27
+ #
28
+ # @example Press a key
29
+ #
30
+ # driver.action.key_down(:control).perform
31
+ #
32
+ # @example Press a key on an element
33
+ #
34
+ # el = driver.find_element(id: "some_id")
35
+ # driver.action.key_down(el, :shift).perform
36
+ #
37
+ # @overload key_down(key, device: nil)
38
+ # @param [Symbol, String] key The key to press
39
+ # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
40
+ # @overload key_down(element, key, device: nil)
41
+ # @param [Element] element An optional element to move to first
42
+ # @param [Symbol, String] key The key to press
43
+ # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
44
+ # @return [W3CActionBuilder] A self reference
45
+ #
46
+
47
+ def key_down(*args, device: nil)
48
+ key_action(*args, action: :create_key_down, device: device)
49
+ end
50
+
51
+ #
52
+ # Performs a key release.
53
+ # Releasing a non-depressed key will yield undefined behaviour.
54
+ #
55
+ # @example Release a key
56
+ #
57
+ # driver.action.key_up(:shift).perform
58
+ #
59
+ # @example Release a key from an element
60
+ #
61
+ # el = driver.find_element(id: "some_id")
62
+ # driver.action.key_up(el, :alt).perform
63
+ #
64
+ # @overload key_up(key, device: nil)
65
+ # @param [Symbol, String] key The key to press
66
+ # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
67
+ # @overload key_up(element, key, device: nil)
68
+ # @param [Element] element An optional element to move to first
69
+ # @param [Symbol, String] key The key to release
70
+ # @param [Symbol, String] device Optional name of the KeyInput device to release the key on
71
+ # @return [W3CActionBuilder] A self reference
72
+ #
73
+
74
+ def key_up(*args, device: nil)
75
+ key_action(*args, action: :create_key_up, device: device)
76
+ end
77
+
78
+ #
79
+ # Sends keys to the active element. This differs from calling
80
+ # Element#send_keys(keys) on the active element in two ways:
81
+ #
82
+ # * The modifier keys included in this call are not released.
83
+ # * There is no attempt to re-focus the element - so send_keys(:tab) for switching elements should work.
84
+ #
85
+ # @example Send the text "help" to an element
86
+ #
87
+ # el = driver.find_element(id: "some_id")
88
+ # driver.action.send_keys(el, "help").perform
89
+ #
90
+ # @example Send the text "help" to the currently focused element
91
+ #
92
+ # driver.action.send_keys("help").perform
93
+ #
94
+ # @overload send_keys(keys, device: nil)
95
+ # @param [Array, Symbol, String] keys The key(s) to press and release
96
+ # @param [Symbol, String] device Optional name of the KeyInput device to press and release the keys on
97
+ # @overload send_keys(element, keys, device: nil)
98
+ # @param [Element] element An optional element to move to first
99
+ # @param [Array, Symbol, String] keys The key(s) to press and release
100
+ # @param [Symbol, String] device Optional name of the KeyInput device to press and release the keys on
101
+ # @return [W3CActionBuilder] A self reference
102
+ #
103
+
104
+ def send_keys(*args, device: nil)
105
+ click(args.shift) if args.first.is_a? Element
106
+ args.map { |x| x.is_a?(String) ? x.chars : x }.flatten.each do |arg|
107
+ key_down(arg, device: device)
108
+ key_up(arg, device: device)
109
+ end
110
+ self
111
+ end
112
+
113
+ private
114
+
115
+ #
116
+ # @api private
117
+ #
118
+ # @overload key_down(key, action: nil, device: nil)
119
+ # @param [Symbol, String] key The key to press
120
+ # @param [Symbol] action The name of the key action to perform
121
+ # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
122
+ # @overload key_down(element, key, action: nil, device: nil)
123
+ # @param [Element] element An optional element to move to first
124
+ # @param [Symbol, String] key The key to press
125
+ # @param [Symbol] action The name of the key action to perform
126
+ # @param [Symbol, String] device Optional name of the KeyInput device to press the key on
127
+ #
128
+ # @param [Array] args
129
+ # @option args [Element] element An optional element to move to first
130
+ # @option args [Symbol, String] key The key to perform the action with
131
+ # @param [Symbol] action The name of the key action to perform
132
+ # @param [Symbol, String] device optional name of the KeyInput device to press the key on
133
+ # @return [W3CActionBuilder] A self reference
134
+ #
135
+
136
+ def key_action(*args, action: nil, device: nil)
137
+ key_input = get_device(device) || key_inputs.first
138
+ click(args.shift) if args.first.is_a? Element
139
+ key_input.send(action, args.last)
140
+ tick(key_input)
141
+ self
142
+ end
143
+ end # KeyActions
144
+ end # WebDriver
145
+ end # Selenium
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module Interactions
23
+ class KeyInput < InputDevice
24
+ SUBTYPES = {down: :keyDown, up: :keyUp, pause: :pause}.freeze
25
+
26
+ def type
27
+ Interactions::KEY
28
+ end
29
+
30
+ def encode
31
+ return nil if no_actions?
32
+
33
+ {type: type, id: name, actions: @actions.map(&:encode)}
34
+ end
35
+
36
+ def create_key_down(key)
37
+ add_action(TypingInteraction.new(self, :down, key))
38
+ end
39
+
40
+ def create_key_up(key)
41
+ add_action(TypingInteraction.new(self, :up, key))
42
+ end
43
+
44
+ class TypingInteraction < Interaction
45
+ attr_reader :type
46
+
47
+ def initialize(source, type, key)
48
+ super(source)
49
+ @type = assert_type(type)
50
+ @key = Keys.encode_key(key)
51
+ end
52
+
53
+ def assert_type(type)
54
+ raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
55
+
56
+ KeyInput::SUBTYPES[type]
57
+ end
58
+
59
+ def encode
60
+ {type: @type, value: @key}
61
+ end
62
+ end # TypingInteraction
63
+ end # KeyInput
64
+ end # Interactions
65
+ end # WebDriver
66
+ end # Selenium
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module Interactions
23
+ class NoneInput < InputDevice
24
+ def type
25
+ Interactions::NONE
26
+ end
27
+
28
+ def encode
29
+ return nil if no_actions?
30
+
31
+ {type: type, id: name, actions: @actions.map(&:encode)}
32
+ end
33
+ end # NoneInput
34
+ end # Interactions
35
+ end # WebDriver
36
+ end # Selenium