selenium-webdriver 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +10 -0
- data/lib/selenium/webdriver.rb +23 -1
- data/lib/selenium/webdriver/chrome/bridge.rb +5 -1
- data/lib/selenium/webdriver/chrome/command_executor.rb +1 -1
- data/lib/selenium/webdriver/chrome/extension.zip +0 -0
- data/lib/selenium/webdriver/chrome/launcher.rb +10 -4
- data/lib/selenium/webdriver/common.rb +1 -0
- data/lib/selenium/webdriver/common/alert.rb +27 -0
- data/lib/selenium/webdriver/common/bridge_helper.rb +10 -7
- data/lib/selenium/webdriver/common/core_ext/dir.rb +1 -1
- data/lib/selenium/webdriver/common/driver.rb +8 -16
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +1 -1
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +1 -1
- data/lib/selenium/webdriver/common/element.rb +4 -4
- data/lib/selenium/webdriver/common/keys.rb +3 -1
- data/lib/selenium/webdriver/common/options.rb +2 -2
- data/lib/selenium/webdriver/common/platform.rb +11 -3
- data/lib/selenium/webdriver/common/socket_poller.rb +5 -1
- data/lib/selenium/webdriver/common/target_locator.rb +11 -3
- data/lib/selenium/webdriver/common/timeouts.rb +10 -0
- data/lib/selenium/webdriver/firefox/binary.rb +4 -2
- data/lib/selenium/webdriver/firefox/bridge.rb +1 -1
- data/lib/selenium/webdriver/firefox/extension.rb +2 -2
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +1 -1
- data/lib/selenium/webdriver/firefox/profiles_ini.rb +2 -2
- data/lib/selenium/webdriver/firefox/socket_lock.rb +1 -1
- data/lib/selenium/webdriver/firefox/util.rb +2 -2
- data/lib/selenium/webdriver/ie.rb +3 -4
- data/lib/selenium/webdriver/ie/bridge.rb +20 -565
- data/lib/selenium/webdriver/ie/lib.rb +4 -99
- 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/remote.rb +1 -1
- data/lib/selenium/webdriver/remote/bridge.rb +21 -1
- data/lib/selenium/webdriver/remote/commands.rb +6 -1
- data/lib/selenium/webdriver/remote/http/default.rb +2 -1
- data/lib/selenium/webdriver/remote/response.rb +1 -1
- metadata +19 -10
- data/lib/selenium/webdriver/ie/native/win32/InternetExplorerDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/InternetExplorerDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/util.rb +0 -138
@@ -2,7 +2,7 @@ module Selenium
|
|
2
2
|
module WebDriver
|
3
3
|
module Firefox
|
4
4
|
|
5
|
-
# @private
|
5
|
+
# @api private
|
6
6
|
class Binary
|
7
7
|
|
8
8
|
NO_FOCUS_LIBRARY_NAME = "x_ignore_nofocus.so"
|
@@ -87,7 +87,7 @@ module Selenium
|
|
87
87
|
class << self
|
88
88
|
|
89
89
|
#
|
90
|
-
# @private
|
90
|
+
# @api private
|
91
91
|
#
|
92
92
|
# @see Firefox.path=
|
93
93
|
#
|
@@ -109,6 +109,8 @@ module Selenium
|
|
109
109
|
raise Error::WebDriverError, "unknown platform: #{Platform.os}"
|
110
110
|
end
|
111
111
|
|
112
|
+
@path = Platform.cygwin_path(@path) if Platform.cygwin?
|
113
|
+
|
112
114
|
unless File.file?(@path.to_s)
|
113
115
|
raise Error::WebDriverError, "Could not find Firefox binary (os=#{Platform.os}). Make sure Firefox is installed or set the path manually with #{self}.path="
|
114
116
|
end
|
@@ -2,7 +2,7 @@ module Selenium
|
|
2
2
|
module WebDriver
|
3
3
|
module Firefox
|
4
4
|
|
5
|
-
# @private
|
5
|
+
# @api private
|
6
6
|
class Extension
|
7
7
|
EM_NAMESPACE_URI = "http://www.mozilla.org/2004/em-rdf#" # not used?
|
8
8
|
|
@@ -51,4 +51,4 @@ module Selenium
|
|
51
51
|
end # Extension
|
52
52
|
end # Firefox
|
53
53
|
end # WebDriver
|
54
|
-
end # Selenium
|
54
|
+
end # Selenium
|
Binary file
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Selenium
|
2
2
|
module WebDriver
|
3
3
|
|
4
|
-
# @private
|
4
|
+
# @api private
|
5
5
|
module IE
|
6
6
|
DLLS = {
|
7
|
-
:win32 => "#{WebDriver.root}/selenium/webdriver/ie/native/win32/
|
8
|
-
:x64 => "#{WebDriver.root}/selenium/webdriver/ie/native/x64/
|
7
|
+
:win32 => "#{WebDriver.root}/selenium/webdriver/ie/native/win32/IEDriver.dll",
|
8
|
+
:x64 => "#{WebDriver.root}/selenium/webdriver/ie/native/x64/IEDriver.dll"
|
9
9
|
}
|
10
10
|
end
|
11
11
|
end
|
@@ -14,5 +14,4 @@ end
|
|
14
14
|
require "ffi"
|
15
15
|
|
16
16
|
require "selenium/webdriver/ie/lib"
|
17
|
-
require "selenium/webdriver/ie/util"
|
18
17
|
require "selenium/webdriver/ie/bridge"
|
@@ -3,20 +3,29 @@ module Selenium
|
|
3
3
|
module IE
|
4
4
|
|
5
5
|
#
|
6
|
-
# @private
|
6
|
+
# @api private
|
7
7
|
#
|
8
8
|
|
9
|
-
class Bridge
|
10
|
-
|
9
|
+
class Bridge < Remote::Bridge
|
10
|
+
|
11
|
+
HOST = "localhost"
|
12
|
+
|
13
|
+
DEFAULT_PORT = 5555
|
14
|
+
DEFAULT_TIMEOUT = 30
|
11
15
|
|
12
16
|
def initialize(opts = {})
|
13
|
-
|
17
|
+
timeout = opts[:timeout] || DEFAULT_TIMEOUT
|
18
|
+
@port = opts[:port] || DEFAULT_PORT
|
19
|
+
@speed = opts[:speed] || :fast
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
@server_pointer = Lib.start_server @port
|
22
|
+
|
23
|
+
unless SocketPoller.new(HOST, @port, timeout).connected?
|
24
|
+
raise "unable to connect to IE server within #{timeout} seconds"
|
25
|
+
end
|
17
26
|
|
18
|
-
@
|
19
|
-
|
27
|
+
super(:url => "http://#{HOST}:#{@port}",
|
28
|
+
:desired_capabilities => :internet_explorer)
|
20
29
|
end
|
21
30
|
|
22
31
|
def browser
|
@@ -27,565 +36,11 @@ module Selenium
|
|
27
36
|
[]
|
28
37
|
end
|
29
38
|
|
30
|
-
def get(url)
|
31
|
-
check_error_code Lib.wdGet(@driver_pointer, wstring_ptr(url)),
|
32
|
-
"Cannot get url #{url.inspect}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def getCurrentUrl
|
36
|
-
create_string do |wrapper|
|
37
|
-
check_error_code Lib.wdGetCurrentUrl(@driver_pointer, wrapper),
|
38
|
-
"unable to get current URL"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def goBack
|
43
|
-
check_error_code Lib.wdGoBack(@driver_pointer),
|
44
|
-
"Cannot navigate back"
|
45
|
-
end
|
46
|
-
|
47
|
-
def goForward
|
48
|
-
check_error_code Lib.wdGoForward(@driver_pointer),
|
49
|
-
"Cannot navigate back"
|
50
|
-
end
|
51
|
-
|
52
|
-
def getTitle
|
53
|
-
create_string do |wrapper|
|
54
|
-
check_error_code Lib.wdGetTitle(@driver_pointer, wrapper),
|
55
|
-
"unable to get title"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def getPageSource
|
60
|
-
create_string do |wrapper|
|
61
|
-
check_error_code Lib.wdGetPageSource(@driver_pointer, wrapper),
|
62
|
-
"unable to get page source"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def getBrowserVisible
|
67
|
-
int_ptr = FFI::MemoryPointer.new :int
|
68
|
-
check_error_code Lib.wdGetVisible(@driver_pointer, int_ptr), "unable to determine if browser is visible"
|
69
|
-
|
70
|
-
int_ptr.get_int(0) == 1
|
71
|
-
end
|
72
|
-
|
73
|
-
def setBrowserVisible(bool)
|
74
|
-
check_error_code Lib.wdSetVisible(@driver_pointer, bool ? 1 : 0),
|
75
|
-
"unable to change the visibility of the browser"
|
76
|
-
end
|
77
|
-
|
78
|
-
def setImplicitWaitTimeout(milliseconds)
|
79
|
-
check_error_code Lib.wdSetImplicitWaitTimeout(@driver_pointer, milliseconds),
|
80
|
-
"unable to set implicit wait timeout"
|
81
|
-
end
|
82
|
-
|
83
|
-
def switchToWindow(id)
|
84
|
-
check_error_code Lib.wdSwitchToWindow(@driver_pointer, wstring_ptr(id)),
|
85
|
-
"unable to locate window #{id.inspect}"
|
86
|
-
end
|
87
|
-
|
88
|
-
def switchToFrame(id)
|
89
|
-
check_error_code Lib.wdSwitchToFrame(@driver_pointer, wstring_ptr(id)),
|
90
|
-
"unable to locate frame #{id.inspect}"
|
91
|
-
end
|
92
|
-
|
93
|
-
def switchToActiveElement
|
94
|
-
create_element do |ptr|
|
95
|
-
check_error_code Lib.wdSwitchToActiveElement(@driver_pointer, ptr),
|
96
|
-
"unable to switch to active element"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def switchToDefaultContent
|
101
|
-
switchToFrame ""
|
102
|
-
end
|
103
|
-
|
104
39
|
def quit
|
105
|
-
|
106
|
-
|
107
|
-
switchToWindow handle
|
108
|
-
close
|
109
|
-
rescue Error::NoSuchWindowError
|
110
|
-
end
|
111
|
-
end
|
112
|
-
ensure
|
113
|
-
ptr = @driver_pointer
|
114
|
-
@driver_pointer = nil
|
115
|
-
|
116
|
-
check_error_code Lib.wdFreeDriver(ptr), "unable to free driver #{self}"
|
117
|
-
end
|
118
|
-
|
119
|
-
def close
|
120
|
-
check_error_code Lib.wdClose(@driver_pointer), "unable to close driver"
|
121
|
-
end
|
122
|
-
|
123
|
-
def refresh
|
124
|
-
check_error_code Lib.wdRefresh(@driver_pointer), "unable to refresh current page"
|
125
|
-
end
|
126
|
-
|
127
|
-
def getWindowHandles
|
128
|
-
raw_handles = FFI::MemoryPointer.new :pointer
|
129
|
-
check_error_code Lib.wdGetAllWindowHandles(@driver_pointer, raw_handles),
|
130
|
-
"unable to obtain all window handles"
|
131
|
-
|
132
|
-
string_array_from(raw_handles).uniq
|
133
|
-
end
|
134
|
-
|
135
|
-
def getCurrentWindowHandle
|
136
|
-
create_string do |string_pointer|
|
137
|
-
check_error_code Lib.wdGetCurrentWindowHandle(@driver_pointer, string_pointer),
|
138
|
-
"unable to obtain current window handle"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def executeScript(script, *args)
|
143
|
-
script_args_ref = FFI::MemoryPointer.new :pointer
|
144
|
-
result = Lib.wdNewScriptArgs(script_args_ref, args.size)
|
145
|
-
|
146
|
-
check_error_code result, "unable to create new script arguments array"
|
147
|
-
|
148
|
-
args_pointer = script_args_ref.get_pointer(0)
|
149
|
-
populate_arguments(result, args_pointer, args)
|
150
|
-
|
151
|
-
script = "(function() { return function(){" + script + "};})();"
|
152
|
-
script_result_ref = FFI::MemoryPointer.new :pointer
|
153
|
-
|
154
|
-
check_error_code Lib.wdExecuteScript(@driver_pointer, wstring_ptr(script), args_pointer, script_result_ref),
|
155
|
-
"Cannot execute script"
|
156
|
-
|
157
|
-
extract_return_value script_result_ref
|
158
|
-
ensure
|
159
|
-
Lib.wdFreeScriptArgs(args_pointer) if args_pointer
|
160
|
-
end
|
161
|
-
|
162
|
-
def waitForLoadToComplete
|
163
|
-
Lib.wdWaitForLoadToComplete(@driver_pointer)
|
164
|
-
end
|
165
|
-
|
166
|
-
#
|
167
|
-
# Configuration
|
168
|
-
#
|
169
|
-
|
170
|
-
def addCookie(opts)
|
171
|
-
cookie_string = "#{opts[:name]}=#{opts[:value]}; "
|
172
|
-
cookie_string << "path=#{opts[:path]}; " if opts[:path] && !opts[:path].empty?
|
173
|
-
cookie_string << "domain=#{opts[:domain][/^(.+?):/, 1]};" if opts[:domain] && !opts[:domain].empty?
|
174
|
-
|
175
|
-
check_error_code Lib.wdAddCookie(@driver_pointer, wstring_ptr(cookie_string)),
|
176
|
-
"unable to add cookie"
|
177
|
-
end
|
178
|
-
|
179
|
-
def getAllCookies
|
180
|
-
str = create_string do |wrapper|
|
181
|
-
check_error_code Lib.wdGetCookies(@driver_pointer, wrapper), "unable to get cookies"
|
182
|
-
end
|
183
|
-
|
184
|
-
str.split("; ").map do |cookie_string|
|
185
|
-
parts = cookie_string.split("=")
|
186
|
-
next unless parts.size == 2
|
187
|
-
|
188
|
-
{
|
189
|
-
'name' => parts[0],
|
190
|
-
'value' => parts[1],
|
191
|
-
'domain' => getCurrentUrl,
|
192
|
-
'path' => "",
|
193
|
-
'expires' => nil,
|
194
|
-
'secure' => false
|
195
|
-
}
|
196
|
-
end.compact
|
197
|
-
end
|
198
|
-
|
199
|
-
def deleteCookie(name)
|
200
|
-
raise NotImplementedError, "missing from IE driver"
|
201
|
-
end
|
202
|
-
|
203
|
-
def deleteAllCookies
|
204
|
-
raise NotImplementedError, "missing from IE driver"
|
205
|
-
end
|
206
|
-
|
207
|
-
def setSpeed(speed)
|
208
|
-
@speed = speed
|
209
|
-
end
|
210
|
-
|
211
|
-
def getSpeed
|
212
|
-
@speed
|
213
|
-
end
|
214
|
-
|
215
|
-
#
|
216
|
-
# Finders
|
217
|
-
#
|
218
|
-
|
219
|
-
def findElementByClassName(parent, class_name)
|
220
|
-
create_element do |raw_element|
|
221
|
-
check_error_code Lib.wdFindElementByClassName(@driver_pointer, parent, wstring_ptr(class_name), raw_element),
|
222
|
-
"unable to find element by class name using #{class_name.inspect}"
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def findElementsByClassName(parent, class_name)
|
227
|
-
create_element_collection do |raw_elements|
|
228
|
-
check_error_code Lib.wdFindElementsByClassName(@driver_pointer, parent, wstring_ptr(class_name), raw_elements),
|
229
|
-
"unable to find elements by class name using #{class_name.inspect}"
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def findElementByCssSelector(parent, selector)
|
234
|
-
create_element do |raw_element|
|
235
|
-
check_error_code Lib.wdFindElementByCss(@driver_pointer, parent, wstring_ptr(selector), raw_element),
|
236
|
-
"unable to find element by css selector using #{selector.inspect}"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def findElementsByCssSelector(parent, selector)
|
241
|
-
create_element_collection do |raw_elements|
|
242
|
-
check_error_code Lib.wdFindElementsByCss(@driver_pointer, parent, wstring_ptr(selector), raw_elements),
|
243
|
-
"unable to find elements by css selector using #{selector.inspect}"
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def findElementById(parent, id)
|
248
|
-
create_element do |raw_element|
|
249
|
-
check_error_code Lib.wdFindElementById(@driver_pointer, parent, wstring_ptr(id), raw_element),
|
250
|
-
"unable to find element by id using #{id.inspect}"
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
def findElementsById(parent, id)
|
255
|
-
create_element_collection do |raw_elements|
|
256
|
-
check_error_code Lib.wdFindElementsById(@driver_pointer, parent, wstring_ptr(id), raw_elements),
|
257
|
-
"unable to find elements by id using #{id.inspect}"
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def findElementByLinkText(parent, link_text)
|
262
|
-
create_element do |raw_element|
|
263
|
-
check_error_code Lib.wdFindElementByLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_element),
|
264
|
-
"unable to find element by link text using #{link_text.inspect}"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
def findElementsByLinkText(parent, link_text)
|
269
|
-
create_element_collection do |raw_elements|
|
270
|
-
check_error_code Lib.wdFindElementsByLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_elements),
|
271
|
-
"unable to find elements by link text using #{link_text.inspect}"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
def findElementByPartialLinkText(parent, link_text)
|
276
|
-
create_element do |raw_element|
|
277
|
-
check_error_code Lib.wdFindElementByPartialLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_element),
|
278
|
-
"unable to find element by partial link text using #{link_text.inspect}"
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def findElementsByPartialLinkText(parent, link_text)
|
283
|
-
create_element_collection do |raw_elements|
|
284
|
-
check_error_code Lib.wdFindElementsByPartialLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_elements),
|
285
|
-
"unable to find elements by partial link text using #{link_text.inspect}"
|
286
|
-
end
|
287
|
-
end
|
40
|
+
super
|
41
|
+
Lib.stop_server(@server_pointer)
|
288
42
|
|
289
|
-
|
290
|
-
create_element do |raw_element|
|
291
|
-
check_error_code Lib.wdFindElementByName(@driver_pointer, parent, wstring_ptr(name), raw_element),
|
292
|
-
"unable to find element by name using #{name.inspect}"
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def findElementsByName(parent, name)
|
297
|
-
create_element_collection do |raw_elements|
|
298
|
-
check_error_code Lib.wdFindElementsByName(@driver_pointer, parent, wstring_ptr(name), raw_elements),
|
299
|
-
"unable to find elements by name using #{name.inspect}"
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
def findElementByTagName(parent, tag_name)
|
304
|
-
create_element do |raw_element|
|
305
|
-
check_error_code Lib.wdFindElementByTagName(@driver_pointer, parent, wstring_ptr(tag_name), raw_element),
|
306
|
-
"unable to find element by tag name using #{tag_name.inspect}"
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def findElementsByTagName(parent, tag_name)
|
311
|
-
create_element_collection do |raw_elements|
|
312
|
-
check_error_code Lib.wdFindElementsByTagName(@driver_pointer, parent, wstring_ptr(tag_name), raw_elements),
|
313
|
-
"unable to find elements by tag name using #{tag_name.inspect}"
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
def findElementByXpath(parent, xpath)
|
318
|
-
create_element do |raw_element|
|
319
|
-
check_error_code Lib.wdFindElementByXPath(@driver_pointer, parent, wstring_ptr(xpath), raw_element),
|
320
|
-
"unable to find element by xpath using #{xpath.inspect}"
|
321
|
-
# TODO: Additional error handling
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
def findElementsByXpath(parent, xpath)
|
326
|
-
create_element_collection do |raw_elements|
|
327
|
-
check_error_code Lib.wdFindElementsByXPath(@driver_pointer, parent, wstring_ptr(xpath), raw_elements),
|
328
|
-
"unable to find elements by xpath using #{xpath.inspect}"
|
329
|
-
# TODO: Additional error handling
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
|
334
|
-
#
|
335
|
-
# Element functions
|
336
|
-
#
|
337
|
-
|
338
|
-
def clickElement(element_pointer)
|
339
|
-
check_error_code Lib.wdeClick(element_pointer), "unable to click element"
|
340
|
-
end
|
341
|
-
|
342
|
-
def getElementTagName(element_pointer)
|
343
|
-
create_string do |string_pointer|
|
344
|
-
check_error_code Lib.wdeGetTagName(element_pointer, string_pointer),
|
345
|
-
"unable to get tag name"
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
def getElementAttribute(element_pointer, name)
|
350
|
-
create_string do |string_pointer|
|
351
|
-
check_error_code Lib.wdeGetAttribute(@driver_pointer, element_pointer, wstring_ptr(name), string_pointer),
|
352
|
-
"unable to get attribute #{name.inspect}"
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
def getElementValue(element_pointer)
|
357
|
-
val = getElementAttribute(element_pointer, 'value')
|
358
|
-
val.gsub("\r\n", "\n") if val
|
359
|
-
end
|
360
|
-
|
361
|
-
def getElementText(element_pointer)
|
362
|
-
val = create_string do |string_pointer|
|
363
|
-
check_error_code Lib.wdeGetText(element_pointer, string_pointer),
|
364
|
-
"unable to get text"
|
365
|
-
end
|
366
|
-
|
367
|
-
val.gsub("\r\n", "\n") if val
|
368
|
-
end
|
369
|
-
|
370
|
-
def sendKeysToElement(element_pointer, string)
|
371
|
-
check_error_code Lib.wdeSendKeys(element_pointer, wstring_ptr(string)),
|
372
|
-
"unable to send keys to #{self}"
|
373
|
-
waitForLoadToComplete
|
374
|
-
end
|
375
|
-
|
376
|
-
def clearElement(element_pointer)
|
377
|
-
check_error_code Lib.wdeClear(element_pointer), "unable to clear element"
|
378
|
-
end
|
379
|
-
|
380
|
-
def isElementEnabled(element_pointer)
|
381
|
-
int_ptr = FFI::MemoryPointer.new(:int)
|
382
|
-
check_error_code Lib.wdeIsEnabled(element_pointer, int_ptr),
|
383
|
-
"unable to get enabled state"
|
384
|
-
|
385
|
-
int_ptr.get_int(0) == 1
|
386
|
-
end
|
387
|
-
|
388
|
-
def isElementSelected(element_pointer)
|
389
|
-
int_ptr = FFI::MemoryPointer.new(:int)
|
390
|
-
check_error_code Lib.wdeIsSelected(element_pointer, int_ptr),
|
391
|
-
"unable to get selected state"
|
392
|
-
|
393
|
-
int_ptr.get_int(0) == 1
|
394
|
-
end
|
395
|
-
|
396
|
-
def isElementDisplayed(element_pointer)
|
397
|
-
int_ptr = FFI::MemoryPointer.new :int
|
398
|
-
check_error_code Lib.wdeIsDisplayed(element_pointer, int_ptr), "unable to check visibilty"
|
399
|
-
|
400
|
-
int_ptr.get_int(0) == 1;
|
401
|
-
end
|
402
|
-
|
403
|
-
def submitElement(element_pointer)
|
404
|
-
check_error_code Lib.wdeSubmit(element_pointer), "unable to submit element"
|
405
|
-
end
|
406
|
-
|
407
|
-
def toggleElement(element_pointer)
|
408
|
-
int_ptr = FFI::MemoryPointer.new :int
|
409
|
-
result = Lib.wdeToggle(element_pointer, int_ptr)
|
410
|
-
|
411
|
-
if result == 9
|
412
|
-
raise WebDriver::UnsupportedOperationError,
|
413
|
-
"You may not toggle this element: #{get_element_tag_name(element_pointer)}"
|
414
|
-
end
|
415
|
-
|
416
|
-
check_error_code result, "unable to toggle element"
|
417
|
-
|
418
|
-
int_ptr.get_int(0) == 1
|
419
|
-
end
|
420
|
-
|
421
|
-
def setElementSelected(element_pointer)
|
422
|
-
check_error_code Lib.wdeSetSelected(element_pointer), "unable to select element"
|
423
|
-
end
|
424
|
-
|
425
|
-
def getElementValueOfCssProperty(element_pointer, prop)
|
426
|
-
create_string do |string_pointer|
|
427
|
-
check_error_code Lib.wdeGetValueOfCssProperty(element_pointer, wstring_ptr(prop), string_pointer),
|
428
|
-
"unable to get value of css property: #{prop.inspect}"
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
def hoverOverElement(element_pointer)
|
433
|
-
raise NotImplementedError
|
434
|
-
end
|
435
|
-
|
436
|
-
def elementEquals(element, other)
|
437
|
-
executeScript "return arguments[0] === arguments[1]", element, other
|
438
|
-
end
|
439
|
-
|
440
|
-
def dragElement(element_pointer, right_by, down_by)
|
441
|
-
# TODO: check return values?
|
442
|
-
hwnd = FFI::MemoryPointer.new :pointer
|
443
|
-
x, y, width, height = Array.new(4) { FFI::MemoryPointer.new :long }
|
444
|
-
|
445
|
-
check_error_code Lib.wdeGetDetailsOnceScrolledOnToScreen(element_pointer, hwnd, x, y, width, height),
|
446
|
-
"unable to determine location once scrolled on to screen"
|
447
|
-
|
448
|
-
Lib.wdeMouseDownAt(hwnd.get_pointer(0), x.get_long(0), y.get_long(0))
|
449
|
-
|
450
|
-
destination_x = x.get_long(0) + right_by
|
451
|
-
destination_y = y.get_long(0) + down_by
|
452
|
-
duration = 500 # TODO: parent.manage().getSpeed().getTimeOut();
|
453
|
-
|
454
|
-
Lib.wdeMouseMoveTo(hwnd.get_pointer(0), duration, x.get_long(0), y.get_long(0), destination_x, destination_y)
|
455
|
-
Lib.wdeMouseUpAt(hwnd.get_pointer(0), destination_x, destination_y)
|
456
|
-
end
|
457
|
-
|
458
|
-
def getElementLocation(element_pointer)
|
459
|
-
x = FFI::MemoryPointer.new :long
|
460
|
-
y = FFI::MemoryPointer.new :long
|
461
|
-
|
462
|
-
check_error_code Lib.wdeGetLocation(element_pointer, x, y), "unable to get location of element"
|
463
|
-
|
464
|
-
Point.new x.get_int(0), y.get_int(0)
|
465
|
-
end
|
466
|
-
|
467
|
-
def getElementSize(element_pointer)
|
468
|
-
width = FFI::MemoryPointer.new :long
|
469
|
-
height = FFI::MemoryPointer.new :long
|
470
|
-
|
471
|
-
check_error_code Lib.wdeGetSize(element_pointer, width, height), "unable to get size of element"
|
472
|
-
|
473
|
-
Dimension.new width.get_int(0), height.get_int(0)
|
474
|
-
end
|
475
|
-
|
476
|
-
def finalize(element_pointer)
|
477
|
-
check_error_code Lib.wdeFreeElement(element_pointer),
|
478
|
-
"unable to finalize #{element_pointer} for #{self}"
|
479
|
-
end
|
480
|
-
|
481
|
-
private
|
482
|
-
|
483
|
-
def populate_arguments(result, args_pointer, args)
|
484
|
-
args.each do |arg|
|
485
|
-
case arg
|
486
|
-
when String
|
487
|
-
result = Lib.wdAddStringScriptArg(args_pointer, wstring_ptr(arg))
|
488
|
-
when TrueClass, FalseClass, NilClass
|
489
|
-
result = Lib.wdAddBooleanScriptArg(args_pointer, arg == true ? 1 : 0)
|
490
|
-
when Float
|
491
|
-
result = Lib.wdAddDoubleScriptArg(args_pointer, arg)
|
492
|
-
when Integer
|
493
|
-
result = Lib.wdAddNumberScriptArg(args_pointer, arg)
|
494
|
-
when WebDriver::Element
|
495
|
-
result = Lib.wdAddElementScriptArg(args_pointer, arg.ref)
|
496
|
-
else
|
497
|
-
raise TypeError, "Parameter is not of recognized type: #{arg.inspect}:#{arg.class}"
|
498
|
-
end
|
499
|
-
|
500
|
-
check_error_code result, "unable to add argument: #{arg.inspect}"
|
501
|
-
end
|
502
|
-
|
503
|
-
|
504
|
-
result
|
505
|
-
end
|
506
|
-
|
507
|
-
def extract_return_value(pointer_ref)
|
508
|
-
result, returned = nil
|
509
|
-
script_result = pointer_ref.get_pointer(0)
|
510
|
-
|
511
|
-
type_pointer = FFI::MemoryPointer.new(:int)
|
512
|
-
result = Lib.wdGetScriptResultType(@driver_pointer, script_result, type_pointer)
|
513
|
-
|
514
|
-
check_error_code result, "Cannot determine result type"
|
515
|
-
result_type = type_pointer.get_int(0)
|
516
|
-
|
517
|
-
case result_type
|
518
|
-
when 1 # String
|
519
|
-
create_string do |wrapper|
|
520
|
-
check_error_code Lib.wdGetStringScriptResult(script_result, wrapper), "Cannot extract string result"
|
521
|
-
end
|
522
|
-
when 2 # Long
|
523
|
-
long_pointer = FFI::MemoryPointer.new(:long)
|
524
|
-
check_error_code Lib.wdGetNumberScriptResult(script_result, long_pointer),
|
525
|
-
"Cannot extract number result"
|
526
|
-
|
527
|
-
long_pointer.get_long(0)
|
528
|
-
when 3 # Boolean
|
529
|
-
int_pointer = FFI::MemoryPointer.new(:int)
|
530
|
-
check_error_code Lib.wdGetBooleanScriptResult(script_result, int_pointer),
|
531
|
-
"Cannot extract boolean result"
|
532
|
-
|
533
|
-
int_pointer.get_int(0) == 1
|
534
|
-
when 4 # WebElement
|
535
|
-
element_pointer = FFI::MemoryPointer.new(:pointer)
|
536
|
-
check_error_code Lib.wdGetElementScriptResult(script_result, @driver_pointer, element_pointer),
|
537
|
-
"Cannot extract element result"
|
538
|
-
|
539
|
-
auto_ptr = FFI::AutoPointer.new(element_pointer.get_pointer(0), Lib.method(:finalize_element))
|
540
|
-
Element.new(self, auto_ptr)
|
541
|
-
when 5 # Nothing
|
542
|
-
nil
|
543
|
-
when 6 # Exception
|
544
|
-
message = create_string do |string_pointer|
|
545
|
-
check_error_code Lib.wdGetStringScriptResult(script_result, string_pointer), "Cannot extract string result"
|
546
|
-
end
|
547
|
-
|
548
|
-
raise Error::WebDriverError, message
|
549
|
-
when 7 # Double
|
550
|
-
double_pointer = FFI::MemoryPointer.new(:double)
|
551
|
-
check_error_code Lib.wdGetDoubleScriptResult(script_result, double_pointer), "Cannot extract double result"
|
552
|
-
|
553
|
-
double_pointer.get_double(0)
|
554
|
-
when 8 # Array
|
555
|
-
array_length_pointer = FFI::MemoryPointer.new(:int)
|
556
|
-
check_error_code Lib.wdGetArrayLengthScriptResult(@driver_pointer, script_result, array_length_pointer),
|
557
|
-
"Cannot extract array length"
|
558
|
-
|
559
|
-
arr = []
|
560
|
-
array_length_pointer.get_int(0).times do |idx|
|
561
|
-
current_item_pointer = FFI::MemoryPointer.new(:pointer)
|
562
|
-
result_code = Lib.wdGetArrayItemFromScriptResult(@driver_pointer, script_result, idx, current_item_pointer)
|
563
|
-
|
564
|
-
# free the pointer if the call failed
|
565
|
-
if Error.for_code(result_code)
|
566
|
-
Lib.wdFreeScriptResult(current_item_pointer.get_pointer(0))
|
567
|
-
check_error_code result_code
|
568
|
-
end
|
569
|
-
|
570
|
-
arr << extract_return_value(current_item_pointer)
|
571
|
-
end
|
572
|
-
|
573
|
-
arr
|
574
|
-
else
|
575
|
-
raise Error::WebDriverError, "Cannot determine result type (#{result_type.inspect})"
|
576
|
-
end
|
577
|
-
ensure
|
578
|
-
Lib.wdFreeScriptResult(script_result) if script_result
|
579
|
-
end
|
580
|
-
|
581
|
-
def check_error_code(code, message)
|
582
|
-
return unless ex = WebDriver::Error.for_code(code)
|
583
|
-
|
584
|
-
if ex == Error::TimeOutError
|
585
|
-
raise ex, "#{message} (#{code}): The driver reported that the command timed out. There may be several reasons for this. Check that the destination site is in IE's 'Trusted Sites' (accessed from Tools->Internet Options in the 'Security' tab). If it is a trusted site, then the request may have taken more than a minute to finish."
|
586
|
-
else
|
587
|
-
raise ex, "#{message} (#{code})"
|
588
|
-
end
|
43
|
+
nil
|
589
44
|
end
|
590
45
|
|
591
46
|
end # Bridge
|