bbc-selenium-webdriver 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +473 -0
- data/README +31 -0
- data/lib/selenium-client.rb +2 -0
- data/lib/selenium-webdriver.rb +1 -0
- data/lib/selenium/client.rb +37 -0
- data/lib/selenium/client/base.rb +118 -0
- data/lib/selenium/client/driver.rb +10 -0
- data/lib/selenium/client/errors.rb +9 -0
- data/lib/selenium/client/extensions.rb +118 -0
- data/lib/selenium/client/idiomatic.rb +488 -0
- data/lib/selenium/client/javascript_expression_builder.rb +116 -0
- data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
- data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
- data/lib/selenium/client/legacy_driver.rb +1720 -0
- data/lib/selenium/client/protocol.rb +104 -0
- data/lib/selenium/client/selenium_helper.rb +34 -0
- data/lib/selenium/rake/server_task.rb +157 -0
- data/lib/selenium/server.rb +223 -0
- data/lib/selenium/webdriver.rb +64 -0
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +51 -0
- data/lib/selenium/webdriver/chrome.rb +26 -0
- data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
- data/lib/selenium/webdriver/chrome/profile.rb +83 -0
- data/lib/selenium/webdriver/chrome/service.rb +74 -0
- data/lib/selenium/webdriver/common.rb +30 -0
- data/lib/selenium/webdriver/common/action_builder.rb +352 -0
- data/lib/selenium/webdriver/common/alert.rb +26 -0
- data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
- data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
- data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
- data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
- data/lib/selenium/webdriver/common/driver.rb +301 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
- data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
- data/lib/selenium/webdriver/common/element.rb +262 -0
- data/lib/selenium/webdriver/common/error.rb +212 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
- data/lib/selenium/webdriver/common/keyboard.rb +52 -0
- data/lib/selenium/webdriver/common/keys.rb +109 -0
- data/lib/selenium/webdriver/common/mouse.rb +65 -0
- data/lib/selenium/webdriver/common/navigation.rb +43 -0
- data/lib/selenium/webdriver/common/options.rb +128 -0
- data/lib/selenium/webdriver/common/platform.rb +166 -0
- data/lib/selenium/webdriver/common/port_prober.rb +25 -0
- data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
- data/lib/selenium/webdriver/common/proxy.rb +120 -0
- data/lib/selenium/webdriver/common/search_context.rb +92 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
- data/lib/selenium/webdriver/common/target_locator.rb +81 -0
- data/lib/selenium/webdriver/common/timeouts.rb +29 -0
- data/lib/selenium/webdriver/common/wait.rb +60 -0
- data/lib/selenium/webdriver/common/window.rb +96 -0
- data/lib/selenium/webdriver/common/zipper.rb +82 -0
- data/lib/selenium/webdriver/firefox.rb +37 -0
- data/lib/selenium/webdriver/firefox/binary.rb +161 -0
- data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
- data/lib/selenium/webdriver/firefox/extension.rb +52 -0
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
- data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/profile.rb +315 -0
- data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
- data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
- data/lib/selenium/webdriver/firefox/util.rb +29 -0
- data/lib/selenium/webdriver/ie.rb +19 -0
- data/lib/selenium/webdriver/ie/bridge.rb +60 -0
- data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/server.rb +64 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
- data/lib/selenium/webdriver/opera.rb +24 -0
- data/lib/selenium/webdriver/opera/bridge.rb +113 -0
- data/lib/selenium/webdriver/opera/service.rb +49 -0
- data/lib/selenium/webdriver/remote.rb +21 -0
- data/lib/selenium/webdriver/remote/bridge.rb +473 -0
- data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
- data/lib/selenium/webdriver/remote/commands.rb +181 -0
- data/lib/selenium/webdriver/remote/http/common.rb +74 -0
- data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
- data/lib/selenium/webdriver/remote/http/default.rb +102 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
- data/lib/selenium/webdriver/remote/response.rb +99 -0
- data/lib/selenium/webdriver/remote/server_error.rb +17 -0
- data/lib/selenium/webdriver/support.rb +4 -0
- data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
- data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
- data/lib/selenium/webdriver/support/select.rb +293 -0
- data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
- data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
- data/spec/integration/selenium/client/api/click_spec.rb +39 -0
- data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
- data/spec/integration/selenium/client/api/element_spec.rb +14 -0
- data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
- data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
- data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
- data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
- data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
- data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
- data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
- data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
- data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
- data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
- data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
- data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
- data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
- data/spec/integration/selenium/client/spec_helper.rb +125 -0
- data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
- data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
- data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
- data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
- data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
- data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
- data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
- data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
- data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
- data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
- data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
- data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
- data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
- data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
- data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
- data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
- data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
- data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
- data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
- data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
- data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
- data/spec/unit/selenium/client/base_spec.rb +239 -0
- data/spec/unit/selenium/client/extensions_spec.rb +174 -0
- data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
- data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
- data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
- data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
- data/spec/unit/selenium/client/protocol_spec.rb +124 -0
- data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
- data/spec/unit/selenium/client/spec_helper.rb +24 -0
- data/spec/unit/selenium/rake/task_spec.rb +79 -0
- data/spec/unit/selenium/server_spec.rb +131 -0
- data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
- data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
- data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
- data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
- data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
- data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
- data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
- data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
- data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
- data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
- data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
- data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
- data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
- data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
- data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
- data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
- data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
- metadata +215 -0
@@ -0,0 +1,352 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
|
4
|
+
#
|
5
|
+
# The ActionBuilder provides the user a way to set up and perform
|
6
|
+
# complex user interactions.
|
7
|
+
#
|
8
|
+
# This class should not be instantiated directly, but is created by
|
9
|
+
# Selenium::WebDriver::DriverExtensions::HasInputDevices#action, which
|
10
|
+
# is available on Driver instances that support the user interaction API.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# driver.action.key_down(:shift).
|
15
|
+
# click(element).
|
16
|
+
# click(second_element).
|
17
|
+
# key_up(:shift).
|
18
|
+
# drag_and_drop(element, third_element).
|
19
|
+
# perform
|
20
|
+
#
|
21
|
+
|
22
|
+
class ActionBuilder
|
23
|
+
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
#
|
27
|
+
|
28
|
+
def initialize(mouse, keyboard)
|
29
|
+
@devices = {
|
30
|
+
:mouse => mouse,
|
31
|
+
:keyboard => keyboard
|
32
|
+
}
|
33
|
+
|
34
|
+
@actions = []
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Performs a modifier key press. Does not release
|
39
|
+
# the modifier key - subsequent interactions may assume it's kept pressed.
|
40
|
+
# Note that the modifier key is never released implicitly - either
|
41
|
+
# #key_up(key) or #send_keys(:null) must be called to release the modifier.
|
42
|
+
#
|
43
|
+
# Equivalent to:
|
44
|
+
# driver.action.click(element).send_keys(key)
|
45
|
+
# # or
|
46
|
+
# driver.action.click.send_keys(key)
|
47
|
+
#
|
48
|
+
# @example Press a key
|
49
|
+
#
|
50
|
+
# driver.action.key_down(:control).perform
|
51
|
+
#
|
52
|
+
# @example Press a key on an element
|
53
|
+
#
|
54
|
+
# el = driver.find_element(:id, "some_id")
|
55
|
+
# driver.action.key_down(el, :shift).perform
|
56
|
+
#
|
57
|
+
# @param [:shift, :alt, :control, :command, :meta] The key to press.
|
58
|
+
# @param [Selenium::WebDriver::Element] element An optional element
|
59
|
+
# @raise [ArgumentError] if the given key is not a modifier
|
60
|
+
# @return [ActionBuilder] A self reference.
|
61
|
+
#
|
62
|
+
|
63
|
+
def key_down(*args)
|
64
|
+
if args.first.kind_of? Element
|
65
|
+
@actions << [:mouse, :click, [args.shift]]
|
66
|
+
end
|
67
|
+
|
68
|
+
@actions << [:keyboard, :press, args]
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Performs a modifier key release.
|
74
|
+
# Releasing a non-depressed modifier key will yield undefined behaviour.
|
75
|
+
#
|
76
|
+
# @example Release a key
|
77
|
+
#
|
78
|
+
# driver.action.key_up(:shift).perform
|
79
|
+
#
|
80
|
+
# @example Release a key from an element
|
81
|
+
#
|
82
|
+
# el = driver.find_element(:id, "some_id")
|
83
|
+
# driver.action.key_up(el, :alt).perform
|
84
|
+
#
|
85
|
+
# @param [:shift, :alt, :control, :command, :meta] The modifier key to release.
|
86
|
+
# @param [Selenium::WebDriver::Element] element An optional element
|
87
|
+
# @raise [ArgumentError] if the given key is not a modifier key
|
88
|
+
# @return [ActionBuilder] A self reference.
|
89
|
+
#
|
90
|
+
|
91
|
+
def key_up(*args)
|
92
|
+
if args.first.kind_of? Element
|
93
|
+
@actions << [:mouse, :click, [args.shift]]
|
94
|
+
end
|
95
|
+
|
96
|
+
@actions << [:keyboard, :release, args]
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Sends keys to the active element. This differs from calling
|
102
|
+
# Element#send_keys(keys) on the active element in two ways:
|
103
|
+
#
|
104
|
+
# * The modifier keys included in this call are not released.
|
105
|
+
# * There is no attempt to re-focus the element - so send_keys(:tab) for switching elements should work.
|
106
|
+
#
|
107
|
+
# @example Send the text "help" to an element
|
108
|
+
#
|
109
|
+
# el = driver.find_element(:id, "some_id")
|
110
|
+
# driver.action.send_keys(el, "help").perform
|
111
|
+
#
|
112
|
+
# @example Send the text "help" to the currently focused element
|
113
|
+
#
|
114
|
+
# driver.action.send_keys("help").perform
|
115
|
+
#
|
116
|
+
# @param [Selenium::WebDriver::Element] element An optional element
|
117
|
+
# @param [String] keys The keys to be sent.
|
118
|
+
# @return [ActionBuilder] A self reference.
|
119
|
+
#
|
120
|
+
|
121
|
+
def send_keys(*args)
|
122
|
+
if args.first.kind_of? Element
|
123
|
+
@actions << [:mouse, :click, [args.shift]]
|
124
|
+
end
|
125
|
+
|
126
|
+
@actions << [:keyboard, :send_keys, args]
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Clicks (without releasing) in the middle of the given element. This is
|
132
|
+
# equivalent to:
|
133
|
+
#
|
134
|
+
# driver.action.move_to(element).click_and_hold
|
135
|
+
#
|
136
|
+
# @example Clicking and holding on some element
|
137
|
+
#
|
138
|
+
# el = driver.find_element(:id, "some_id")
|
139
|
+
# driver.action.click_and_hold(el).perform
|
140
|
+
#
|
141
|
+
# @param [Selenium::WebDriver::Element] element the element to move to and click.
|
142
|
+
# @return [ActionBuilder] A self reference.
|
143
|
+
#
|
144
|
+
|
145
|
+
def click_and_hold(element)
|
146
|
+
@actions << [:mouse, :down, [element]]
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Releases the depressed left mouse button at the current mouse location.
|
152
|
+
#
|
153
|
+
# @example Releasing an element after clicking and holding it
|
154
|
+
#
|
155
|
+
# el = driver.find_element(:id, "some_id")
|
156
|
+
# driver.action.click_and_hold(el).release.perform
|
157
|
+
#
|
158
|
+
# @return [ActionBuilder] A self reference.
|
159
|
+
#
|
160
|
+
|
161
|
+
def release(element = nil)
|
162
|
+
@actions << [:mouse, :up, [element]]
|
163
|
+
self
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Clicks in the middle of the given element. Equivalent to:
|
168
|
+
#
|
169
|
+
# driver.action.move_to(element).click
|
170
|
+
#
|
171
|
+
# When no element is passed, the current mouse position will be clicked.
|
172
|
+
#
|
173
|
+
# @example Clicking on an element
|
174
|
+
#
|
175
|
+
# el = driver.find_element(:id, "some_id")
|
176
|
+
# driver.action.click(el).perform
|
177
|
+
#
|
178
|
+
# @example Clicking at the current mouse position
|
179
|
+
#
|
180
|
+
# driver.action.click.perform
|
181
|
+
#
|
182
|
+
# @param [Selenium::WebDriver::Element] element An optional element to click.
|
183
|
+
# @return [ActionBuilder] A self reference.
|
184
|
+
#
|
185
|
+
|
186
|
+
def click(element = nil)
|
187
|
+
@actions << [:mouse, :click, [element]]
|
188
|
+
self
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# Performs a double-click at middle of the given element. Equivalent to:
|
193
|
+
#
|
194
|
+
# driver.action.move_to(element).double_click
|
195
|
+
#
|
196
|
+
# @example Double click an element
|
197
|
+
#
|
198
|
+
# el = driver.find_element(:id, "some_id")
|
199
|
+
# driver.action.double_click(el).perform
|
200
|
+
#
|
201
|
+
# @param [Selenium::WebDriver::Element] element An optional element to move to.
|
202
|
+
# @return [ActionBuilder] A self reference.
|
203
|
+
#
|
204
|
+
|
205
|
+
def double_click(element = nil)
|
206
|
+
@actions << [:mouse, :double_click, [element]]
|
207
|
+
self
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# Moves the mouse to the middle of the given element. The element is scrolled into
|
212
|
+
# view and its location is calculated using getBoundingClientRect. Then the
|
213
|
+
# mouse is moved to optional offset coordinates from the element.
|
214
|
+
#
|
215
|
+
# Note that when using offsets, both coordinates need to be passed.
|
216
|
+
#
|
217
|
+
# @example Scroll element into view and move the mouse to it
|
218
|
+
#
|
219
|
+
# el = driver.find_element(:id, "some_id")
|
220
|
+
# driver.action.move_to(el).perform
|
221
|
+
#
|
222
|
+
# @example
|
223
|
+
#
|
224
|
+
# el = driver.find_element(:id, "some_id")
|
225
|
+
# driver.action.move_to(el, 100, 100).perform
|
226
|
+
#
|
227
|
+
# @param [Selenium::WebDriver::Element] element to move to.
|
228
|
+
# @param [Integer] right_by Optional offset from the top-left corner. A negative value means
|
229
|
+
# coordinates right from the element.
|
230
|
+
# @param [Integer] down_by Optional offset from the top-left corner. A negative value means
|
231
|
+
# coordinates above the element.
|
232
|
+
# @return [ActionBuilder] A self reference.
|
233
|
+
#
|
234
|
+
|
235
|
+
def move_to(element, right_by = nil, down_by = nil)
|
236
|
+
if right_by && down_by
|
237
|
+
@actions << [:mouse, :move_to, [element, right_by, down_by]]
|
238
|
+
else
|
239
|
+
@actions << [:mouse, :move_to, [element]]
|
240
|
+
end
|
241
|
+
|
242
|
+
self
|
243
|
+
end
|
244
|
+
|
245
|
+
#
|
246
|
+
# Moves the mouse from its current position (or 0,0) by the given offset.
|
247
|
+
# If the coordinates provided are outside the viewport (the mouse will
|
248
|
+
# end up outside the browser window) then the viewport is scrolled to
|
249
|
+
# match.
|
250
|
+
#
|
251
|
+
# @example Move the mouse to a certain offset from its current position
|
252
|
+
#
|
253
|
+
# driver.action.move_by(100, 100).perform
|
254
|
+
#
|
255
|
+
# @param [Integer] right_by horizontal offset. A negative value means moving the
|
256
|
+
# mouse left.
|
257
|
+
# @param [Integer] down_by vertical offset. A negative value means moving the mouse
|
258
|
+
# up.
|
259
|
+
# @return [ActionBuilder] A self reference.
|
260
|
+
# @raise [MoveTargetOutOfBoundsError] if the provided offset is outside
|
261
|
+
# the document's boundaries.
|
262
|
+
#
|
263
|
+
|
264
|
+
def move_by(right_by, down_by)
|
265
|
+
@actions << [:mouse, :move_by, [right_by, down_by]]
|
266
|
+
self
|
267
|
+
end
|
268
|
+
|
269
|
+
#
|
270
|
+
# Performs a context-click at middle of the given element. First performs
|
271
|
+
# a move_to to the location of the element.
|
272
|
+
#
|
273
|
+
# @example Context-click at middle of given element
|
274
|
+
#
|
275
|
+
# el = driver.find_element(:id, "some_id")
|
276
|
+
# driver.action.context_click(el).perform
|
277
|
+
#
|
278
|
+
# @param [Selenium::WebDriver::Element] element An element to context click.
|
279
|
+
# @return [ActionBuilder] A self reference.
|
280
|
+
#
|
281
|
+
|
282
|
+
def context_click(element)
|
283
|
+
@actions << [:mouse, :context_click, [element]]
|
284
|
+
self
|
285
|
+
end
|
286
|
+
|
287
|
+
#
|
288
|
+
# A convenience method that performs click-and-hold at the location of the
|
289
|
+
# source element, moves to the location of the target element, then
|
290
|
+
# releases the mouse.
|
291
|
+
#
|
292
|
+
# @example Drag and drop one element onto another
|
293
|
+
#
|
294
|
+
# el1 = driver.find_element(:id, "some_id1")
|
295
|
+
# el2 = driver.find_element(:id, "some_id2")
|
296
|
+
# driver.action.drag_and_drop(el1, el2).perform
|
297
|
+
#
|
298
|
+
# @param [Selenium::WebDriver::Element] source element to emulate button down at.
|
299
|
+
# @param [Selenium::WebDriver::Element] target element to move to and release the
|
300
|
+
# mouse at.
|
301
|
+
# @return [ActionBuilder] A self reference.
|
302
|
+
#
|
303
|
+
|
304
|
+
def drag_and_drop(source, target)
|
305
|
+
click_and_hold source
|
306
|
+
move_to target
|
307
|
+
release target
|
308
|
+
|
309
|
+
self
|
310
|
+
end
|
311
|
+
|
312
|
+
#
|
313
|
+
# A convenience method that performs click-and-hold at the location of
|
314
|
+
# the source element, moves by a given offset, then releases the mouse.
|
315
|
+
#
|
316
|
+
# @example Drag and drop an element by offset
|
317
|
+
#
|
318
|
+
# el = driver.find_element(:id, "some_id1")
|
319
|
+
# driver.action.drag_and_drop_by(el, 100, 100).perform
|
320
|
+
#
|
321
|
+
# @param [Selenium::WebDriver::Element] source Element to emulate button down at.
|
322
|
+
# @param [Integer] right_by horizontal move offset.
|
323
|
+
# @param [Integer] down_by vertical move offset.
|
324
|
+
# @param [Selenium::WebDriver::Element] target Element to move to and release the
|
325
|
+
# mouse at.
|
326
|
+
# @return [ActionBuilder] A self reference.
|
327
|
+
#
|
328
|
+
|
329
|
+
def drag_and_drop_by(source, right_by, down_by)
|
330
|
+
click_and_hold source
|
331
|
+
move_by right_by, down_by
|
332
|
+
release
|
333
|
+
|
334
|
+
self
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
#
|
339
|
+
# Executes the actions added to the builder.
|
340
|
+
#
|
341
|
+
|
342
|
+
def perform
|
343
|
+
@actions.each { |receiver, method, args|
|
344
|
+
@devices.fetch(receiver).__send__(method, *args)
|
345
|
+
}
|
346
|
+
|
347
|
+
nil
|
348
|
+
end
|
349
|
+
|
350
|
+
end # ActionBuilder
|
351
|
+
end # WebDriver
|
352
|
+
end # Selenium
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
class Alert
|
4
|
+
|
5
|
+
attr_reader :text
|
6
|
+
|
7
|
+
def initialize(bridge)
|
8
|
+
@bridge = bridge
|
9
|
+
@text = bridge.getAlertText
|
10
|
+
end
|
11
|
+
|
12
|
+
def accept
|
13
|
+
@bridge.acceptAlert
|
14
|
+
end
|
15
|
+
|
16
|
+
def dismiss
|
17
|
+
@bridge.dismissAlert
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_keys(keys)
|
21
|
+
@bridge.setAlertValue keys
|
22
|
+
end
|
23
|
+
|
24
|
+
end # Alert
|
25
|
+
end # WebDriver
|
26
|
+
end # Selenium
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
|
4
|
+
#
|
5
|
+
# Shared across bridges
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
#
|
9
|
+
|
10
|
+
module BridgeHelper
|
11
|
+
|
12
|
+
def unwrap_script_result(arg)
|
13
|
+
case arg
|
14
|
+
when Array
|
15
|
+
arg.map { |e| unwrap_script_result(e) }
|
16
|
+
when Hash
|
17
|
+
if id = element_id_from(arg)
|
18
|
+
Element.new self, id
|
19
|
+
else
|
20
|
+
arg.each { |k, v| arg[k] = unwrap_script_result(v) }
|
21
|
+
end
|
22
|
+
else
|
23
|
+
arg
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def element_id_from(id)
|
28
|
+
id['ELEMENT']
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_cookie_string(str)
|
32
|
+
result = {
|
33
|
+
'name' => '',
|
34
|
+
'value' => '',
|
35
|
+
'domain' => '',
|
36
|
+
'path' => '',
|
37
|
+
'expires' => '',
|
38
|
+
'secure' => false
|
39
|
+
}
|
40
|
+
|
41
|
+
str.split(";").each do |attribute|
|
42
|
+
if attribute.include? "="
|
43
|
+
key, value = attribute.strip.split("=", 2)
|
44
|
+
if result['name'].empty?
|
45
|
+
result['name'] = key
|
46
|
+
result['value'] = value
|
47
|
+
elsif key == 'domain' && value.strip =~ /^\.(.+)/
|
48
|
+
result['domain'] = $1
|
49
|
+
elsif key && value
|
50
|
+
result[key] = value
|
51
|
+
end
|
52
|
+
elsif attribute == "secure"
|
53
|
+
result['secure'] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
unless [nil, "", "0"].include?(result['expires'])
|
57
|
+
# firefox stores expiry as number of seconds
|
58
|
+
result['expires'] = Time.at(result['expires'].to_i)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
end # BridgeHelper
|
66
|
+
end # WebDriver
|
67
|
+
end # Selenium
|