Selenium 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/bin/selenium +5 -0
- data/lib/selenium.rb +13 -0
- data/lib/selenium/button.rb +19 -0
- data/lib/selenium/directory_listing_page.rb +16 -0
- data/lib/selenium/link.rb +27 -0
- data/lib/selenium/locator.rb +15 -0
- data/lib/selenium/openqa/README +5 -0
- data/lib/selenium/openqa/selenium-server.jar.txt +0 -0
- data/lib/selenium/openqa/selenium.rb +1363 -0
- data/lib/selenium/selenium_server.rb +55 -0
- data/lib/selenium/server_manager.rb +82 -0
- data/lib/selenium/text_field.rb +18 -0
- data/lib/selenium/version +1 -0
- data/test/selenium/download_page.rb +13 -0
- data/test/selenium/home_page.rb +18 -0
- data/test/selenium/menu.rb +18 -0
- data/test/selenium/tc_basic_operation.rb +33 -0
- data/test/selenium/tc_selenium_server.rb +19 -0
- metadata +67 -0
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= Selenium Ruby[http://selenium.rubyforge.org] - Object-oriented testing with selenium
|
2
|
+
|
3
|
+
Homepage:: http://selenium.rubyforge.org
|
4
|
+
Author:: Shane
|
5
|
+
Copyright:: (c) 2006 Selenium-Ruby on rubyforge
|
6
|
+
License:: Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
|
7
|
+
|
8
|
+
Selenium Ruby[http://selenium.rubyforge.org] is a project that wraps selenium-rc[http://www.openqa.org/selenium-rc/]
|
9
|
+
into an object-oriented way, and wraps it into a RubyGem.
|
10
|
+
|
11
|
+
This rDoc is intended for you the check out the available methods on the objects. For a full
|
12
|
+
document of what Selenium can do for you, please check out the home page:
|
13
|
+
http://selenium.rubyforge.org
|
14
|
+
|
15
|
+
For document on the Selenium project and its RC, see Selenium homepage: http://www.openqa.org/selenium
|
16
|
+
|
17
|
+
Please post your question at mailing-list.
|
data/bin/selenium
ADDED
data/lib/selenium.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'selenium')
|
2
|
+
|
3
|
+
require 'openqa/selenium'
|
4
|
+
|
5
|
+
require 'selenium_server'
|
6
|
+
require 'server_manager'
|
7
|
+
require 'directory_listing_page'
|
8
|
+
|
9
|
+
require 'button'
|
10
|
+
require 'link'
|
11
|
+
require 'locator'
|
12
|
+
require 'text_field'
|
13
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Selenium
|
2
|
+
class Button
|
3
|
+
attr_reader :browser
|
4
|
+
|
5
|
+
def initialize(browser, locator)
|
6
|
+
@browser = browser
|
7
|
+
@locator = locator
|
8
|
+
end
|
9
|
+
|
10
|
+
def click
|
11
|
+
browser.click(@locator)
|
12
|
+
end
|
13
|
+
|
14
|
+
def click_wait
|
15
|
+
click
|
16
|
+
browser.wait_for_page_to_load
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'link'
|
3
|
+
|
4
|
+
module Selenium
|
5
|
+
class DirectoryListingPage
|
6
|
+
attr_reader :browser
|
7
|
+
|
8
|
+
def initialize(browser)
|
9
|
+
@browser = browser
|
10
|
+
end
|
11
|
+
|
12
|
+
def link_to_entry(text)
|
13
|
+
Link.new(browser, "link=#{text}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Selenium
|
2
|
+
class Link
|
3
|
+
attr_reader :browser
|
4
|
+
|
5
|
+
def Link::by_id(browser, id)
|
6
|
+
Link.new(browser, "id=#{id}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def Link::by_text(browser, text)
|
10
|
+
Link.new(browser, "link=#{text}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(browser, locator)
|
14
|
+
@browser = browser
|
15
|
+
@locator = locator
|
16
|
+
end
|
17
|
+
|
18
|
+
def click
|
19
|
+
@browser.click(@locator)
|
20
|
+
end
|
21
|
+
|
22
|
+
def click_wait
|
23
|
+
click
|
24
|
+
@browser.wait_for_page_to_load
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
All the files in this foler are from the "Selenium" project on OpenQA (http://www.openqa.org/selenium-rc/), under the
|
2
|
+
Apache License (http://www.openqa.org/selenium-rc/license.action)
|
3
|
+
|
4
|
+
The selenium-server.jar was renamed to have a txt extension because somehow ruby gem does not like jar extension (Installation
|
5
|
+
will fail on buffer error.
|
Binary file
|
@@ -0,0 +1,1363 @@
|
|
1
|
+
|
2
|
+
# Copyright 2006 ThoughtWorks, Inc
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
# -----------------
|
18
|
+
# Original code by Aslak Hellesoy and Darren Hobbs
|
19
|
+
# This file has been automatically generated via XSL
|
20
|
+
# -----------------
|
21
|
+
|
22
|
+
require 'net/http'
|
23
|
+
require 'uri'
|
24
|
+
require 'cgi'
|
25
|
+
|
26
|
+
# Defines an object that runs Selenium commands.
|
27
|
+
#
|
28
|
+
# ===Element Locators
|
29
|
+
# Element Locators tell Selenium which HTML element a command refers to.
|
30
|
+
# The format of a locator is:
|
31
|
+
# <em>locatorType</em><b>=</b><em>argument</em>
|
32
|
+
# We support the following strategies for locating elements:
|
33
|
+
#
|
34
|
+
# * <b>identifier</b>=<em>id</em>::
|
35
|
+
# Select the element with the specified @id attribute. If no match is
|
36
|
+
# found, select the first element whose @name attribute is <em>id</em>.
|
37
|
+
# (This is normally the default; see below.)
|
38
|
+
# * <b>id</b>=<em>id</em>::
|
39
|
+
# Select the element with the specified @id attribute.
|
40
|
+
# * <b>name</b>=<em>name</em>::
|
41
|
+
# Select the first element with the specified @name attribute.
|
42
|
+
#
|
43
|
+
# * username
|
44
|
+
# * name=username
|
45
|
+
#
|
46
|
+
#
|
47
|
+
#
|
48
|
+
# The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <b>value</b> is assumed.
|
49
|
+
#
|
50
|
+
# * name=flavour value=chocolate
|
51
|
+
#
|
52
|
+
#
|
53
|
+
# * <b>dom</b>=<em>javascriptExpression</em>::
|
54
|
+
#
|
55
|
+
# Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
|
56
|
+
# Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
|
57
|
+
# * dom=document.forms['myForm'].myDropdown
|
58
|
+
# * dom=document.images[56]
|
59
|
+
# * dom=function foo() { return document.links[1]; }; foo();
|
60
|
+
#
|
61
|
+
#
|
62
|
+
#
|
63
|
+
# * <b>xpath</b>=<em>xpathExpression</em>::
|
64
|
+
# Locate an element using an XPath expression.
|
65
|
+
# * xpath=//img[@alt='The image alt text']
|
66
|
+
# * xpath=//table[@id='table1']//tr[4]/td[2]
|
67
|
+
#
|
68
|
+
#
|
69
|
+
# * <b>link</b>=<em>textPattern</em>::
|
70
|
+
# Select the link (anchor) element which contains text matching the
|
71
|
+
# specified <em>pattern</em>.
|
72
|
+
# * link=The link text
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# * <b>css</b>=<em>cssSelectorSyntax</em>::
|
76
|
+
# Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
|
77
|
+
# * css=a[href="#id3"]
|
78
|
+
# * css=span#firstChild + span
|
79
|
+
#
|
80
|
+
#
|
81
|
+
#
|
82
|
+
# Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).
|
83
|
+
#
|
84
|
+
#
|
85
|
+
# Without an explicit locator prefix, Selenium uses the following default
|
86
|
+
# strategies:
|
87
|
+
#
|
88
|
+
# * <b>dom</b>, for locators starting with "document."
|
89
|
+
# * <b>xpath</b>, for locators starting with "//"
|
90
|
+
# * <b>identifier</b>, otherwise
|
91
|
+
#
|
92
|
+
# ===Element FiltersElement filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.
|
93
|
+
# Filters look much like locators, ie.
|
94
|
+
# <em>filterType</em><b>=</b><em>argument</em>Supported element-filters are:
|
95
|
+
# <b>value=</b><em>valuePattern</em>
|
96
|
+
#
|
97
|
+
# Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.<b>index=</b><em>index</em>
|
98
|
+
#
|
99
|
+
# Selects a single element based on its position in the list (offset from zero).===String-match Patterns
|
100
|
+
# Various Pattern syntaxes are available for matching string values:
|
101
|
+
#
|
102
|
+
# * <b>glob:</b><em>pattern</em>::
|
103
|
+
# Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
|
104
|
+
# kind of limited regular-expression syntax typically used in command-line
|
105
|
+
# shells. In a glob pattern, "*" represents any sequence of characters, and "?"
|
106
|
+
# represents any single character. Glob patterns match against the entire
|
107
|
+
# string.
|
108
|
+
# * <b>regexp:</b><em>regexp</em>::
|
109
|
+
# Match a string using a regular-expression. The full power of JavaScript
|
110
|
+
# regular-expressions is available.
|
111
|
+
# * <b>exact:</b><em>string</em>::
|
112
|
+
# Match a string exactly, verbatim, without any of that fancy wildcard
|
113
|
+
# stuff.
|
114
|
+
#
|
115
|
+
#
|
116
|
+
# If no pattern prefix is specified, Selenium assumes that it's a "glob"
|
117
|
+
# pattern.
|
118
|
+
#
|
119
|
+
#
|
120
|
+
module Selenium
|
121
|
+
|
122
|
+
class SeleniumDriver
|
123
|
+
include Selenium
|
124
|
+
|
125
|
+
def initialize(server_host, server_port, browserStartCommand, browserURL, timeout=30000)
|
126
|
+
@server_host = server_host
|
127
|
+
@server_port = server_port
|
128
|
+
@browserStartCommand = browserStartCommand
|
129
|
+
@browserURL = browserURL
|
130
|
+
@timeout = timeout
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_s
|
134
|
+
"SeleniumDriver"
|
135
|
+
end
|
136
|
+
|
137
|
+
def start()
|
138
|
+
result = get_string("getNewBrowserSession", [@browserStartCommand, @browserURL])
|
139
|
+
@session_id = result
|
140
|
+
end
|
141
|
+
|
142
|
+
def stop()
|
143
|
+
do_command("testComplete", [])
|
144
|
+
@session_id = nil
|
145
|
+
end
|
146
|
+
|
147
|
+
def do_command(verb, args)
|
148
|
+
timeout(@timeout) do
|
149
|
+
http = Net::HTTP.new(@server_host, @server_port)
|
150
|
+
command_string = '/selenium-server/driver/?cmd=' + CGI::escape(verb)
|
151
|
+
args.length.times do |i|
|
152
|
+
arg_num = (i+1).to_s
|
153
|
+
command_string = command_string + "&" + arg_num + "=" + CGI::escape(args[i].to_s)
|
154
|
+
end
|
155
|
+
if @session_id != nil
|
156
|
+
command_string = command_string + "&sessionId=" + @session_id.to_s
|
157
|
+
end
|
158
|
+
#print "Requesting --->" + command_string + "\n"
|
159
|
+
response, result = http.get(command_string)
|
160
|
+
#print "RESULT: " + result + "\n\n"
|
161
|
+
if (result[0..1] != "OK")
|
162
|
+
raise SeleniumCommandError.new(command_string), result
|
163
|
+
end
|
164
|
+
return result
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_string(verb, args)
|
169
|
+
result = do_command(verb, args)
|
170
|
+
return result[3..result.length]
|
171
|
+
end
|
172
|
+
|
173
|
+
def get_string_array(verb, args)
|
174
|
+
csv = get_string(verb, args)
|
175
|
+
token = ""
|
176
|
+
tokens = []
|
177
|
+
escape = false
|
178
|
+
csv.split(//).each do |letter|
|
179
|
+
if escape
|
180
|
+
token = token + letter
|
181
|
+
escape = false
|
182
|
+
next
|
183
|
+
end
|
184
|
+
if (letter == '\\')
|
185
|
+
escape = true
|
186
|
+
elsif (letter == ',')
|
187
|
+
tokens.push(token)
|
188
|
+
token = ""
|
189
|
+
else
|
190
|
+
token = token + letter
|
191
|
+
end
|
192
|
+
end
|
193
|
+
tokens.push(token)
|
194
|
+
return tokens
|
195
|
+
end
|
196
|
+
|
197
|
+
def get_number(verb, args)
|
198
|
+
# Is there something I need to do here?
|
199
|
+
return get_string(verb, args)
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_number_array(verb, args)
|
203
|
+
# Is there something I need to do here?
|
204
|
+
return get_string_array(verb, args)
|
205
|
+
end
|
206
|
+
|
207
|
+
def get_boolean(verb, args)
|
208
|
+
boolstr = get_string(verb, args)
|
209
|
+
if ("true" == boolstr)
|
210
|
+
return true
|
211
|
+
end
|
212
|
+
if ("false" == boolstr)
|
213
|
+
return false
|
214
|
+
end
|
215
|
+
raise ValueError, "result is neither 'true' nor 'false': " + boolstr
|
216
|
+
end
|
217
|
+
|
218
|
+
def get_boolean_array(verb, args)
|
219
|
+
boolarr = get_string_array(verb, args)
|
220
|
+
boolarr.length.times do |i|
|
221
|
+
if ("true" == boolstr)
|
222
|
+
boolarr[i] = true
|
223
|
+
next
|
224
|
+
end
|
225
|
+
if ("false" == boolstr)
|
226
|
+
boolarr[i] = false
|
227
|
+
next
|
228
|
+
end
|
229
|
+
raise ValueError, "result is neither 'true' nor 'false': " + boolarr[i]
|
230
|
+
end
|
231
|
+
return boolarr
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
# Clicks on a link, button, checkbox or radio button. If the click action
|
237
|
+
# causes a new page to load (like a link usually does), call
|
238
|
+
# waitForPageToLoad.
|
239
|
+
#
|
240
|
+
# 'locator' is an element locator
|
241
|
+
def click(locator)
|
242
|
+
do_command("click", [locator,])
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
# Double clicks on a link, button, checkbox or radio button. If the double click action
|
247
|
+
# causes a new page to load (like a link usually does), call
|
248
|
+
# waitForPageToLoad.
|
249
|
+
#
|
250
|
+
# 'locator' is an element locator
|
251
|
+
def double_click(locator)
|
252
|
+
do_command("doubleClick", [locator,])
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
# Clicks on a link, button, checkbox or radio button. If the click action
|
257
|
+
# causes a new page to load (like a link usually does), call
|
258
|
+
# waitForPageToLoad.
|
259
|
+
#
|
260
|
+
# 'locator' is an element locator
|
261
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
262
|
+
def click_at(locator,coordString)
|
263
|
+
do_command("clickAt", [locator,coordString,])
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
# Doubleclicks on a link, button, checkbox or radio button. If the action
|
268
|
+
# causes a new page to load (like a link usually does), call
|
269
|
+
# waitForPageToLoad.
|
270
|
+
#
|
271
|
+
# 'locator' is an element locator
|
272
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
273
|
+
def double_click_at(locator,coordString)
|
274
|
+
do_command("doubleClickAt", [locator,coordString,])
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
# Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
|
279
|
+
# handler.
|
280
|
+
#
|
281
|
+
# 'locator' is an element locator
|
282
|
+
# 'eventName' is the event name, e.g. "focus" or "blur"
|
283
|
+
def fire_event(locator,eventName)
|
284
|
+
do_command("fireEvent", [locator,eventName,])
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
# Simulates a user pressing and releasing a key.
|
289
|
+
#
|
290
|
+
# 'locator' is an element locator
|
291
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
292
|
+
def key_press(locator,keySequence)
|
293
|
+
do_command("keyPress", [locator,keySequence,])
|
294
|
+
end
|
295
|
+
|
296
|
+
|
297
|
+
# Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
|
298
|
+
#
|
299
|
+
def shift_key_down()
|
300
|
+
do_command("shiftKeyDown", [])
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
# Release the shift key.
|
305
|
+
#
|
306
|
+
def shift_key_up()
|
307
|
+
do_command("shiftKeyUp", [])
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
# Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
|
312
|
+
#
|
313
|
+
def meta_key_down()
|
314
|
+
do_command("metaKeyDown", [])
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
# Release the meta key.
|
319
|
+
#
|
320
|
+
def meta_key_up()
|
321
|
+
do_command("metaKeyUp", [])
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
# Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
|
326
|
+
#
|
327
|
+
def alt_key_down()
|
328
|
+
do_command("altKeyDown", [])
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
# Release the alt key.
|
333
|
+
#
|
334
|
+
def alt_key_up()
|
335
|
+
do_command("altKeyUp", [])
|
336
|
+
end
|
337
|
+
|
338
|
+
|
339
|
+
# Press the control key and hold it down until doControlUp() is called or a new page is loaded.
|
340
|
+
#
|
341
|
+
def control_key_down()
|
342
|
+
do_command("controlKeyDown", [])
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
# Release the control key.
|
347
|
+
#
|
348
|
+
def control_key_up()
|
349
|
+
do_command("controlKeyUp", [])
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
# Simulates a user pressing a key (without releasing it yet).
|
354
|
+
#
|
355
|
+
# 'locator' is an element locator
|
356
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
357
|
+
def key_down(locator,keySequence)
|
358
|
+
do_command("keyDown", [locator,keySequence,])
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
# Simulates a user releasing a key.
|
363
|
+
#
|
364
|
+
# 'locator' is an element locator
|
365
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
366
|
+
def key_up(locator,keySequence)
|
367
|
+
do_command("keyUp", [locator,keySequence,])
|
368
|
+
end
|
369
|
+
|
370
|
+
|
371
|
+
# Simulates a user hovering a mouse over the specified element.
|
372
|
+
#
|
373
|
+
# 'locator' is an element locator
|
374
|
+
def mouse_over(locator)
|
375
|
+
do_command("mouseOver", [locator,])
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
# Simulates a user moving the mouse pointer away from the specified element.
|
380
|
+
#
|
381
|
+
# 'locator' is an element locator
|
382
|
+
def mouse_out(locator)
|
383
|
+
do_command("mouseOut", [locator,])
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
388
|
+
# the specified element.
|
389
|
+
#
|
390
|
+
# 'locator' is an element locator
|
391
|
+
def mouse_down(locator)
|
392
|
+
do_command("mouseDown", [locator,])
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
397
|
+
# the specified element.
|
398
|
+
#
|
399
|
+
# 'locator' is an element locator
|
400
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
401
|
+
def mouse_down_at(locator,coordString)
|
402
|
+
do_command("mouseDownAt", [locator,coordString,])
|
403
|
+
end
|
404
|
+
|
405
|
+
|
406
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
407
|
+
# the specified element.
|
408
|
+
#
|
409
|
+
# 'locator' is an element locator
|
410
|
+
def mouse_up(locator)
|
411
|
+
do_command("mouseUp", [locator,])
|
412
|
+
end
|
413
|
+
|
414
|
+
|
415
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
416
|
+
# the specified element.
|
417
|
+
#
|
418
|
+
# 'locator' is an element locator
|
419
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
420
|
+
def mouse_up_at(locator,coordString)
|
421
|
+
do_command("mouseUpAt", [locator,coordString,])
|
422
|
+
end
|
423
|
+
|
424
|
+
|
425
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
426
|
+
# the specified element.
|
427
|
+
#
|
428
|
+
# 'locator' is an element locator
|
429
|
+
def mouse_move(locator)
|
430
|
+
do_command("mouseMove", [locator,])
|
431
|
+
end
|
432
|
+
|
433
|
+
|
434
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
435
|
+
# the specified element.
|
436
|
+
#
|
437
|
+
# 'locator' is an element locator
|
438
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
439
|
+
def mouse_move_at(locator,coordString)
|
440
|
+
do_command("mouseMoveAt", [locator,coordString,])
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
# Sets the value of an input field, as though you typed it in.
|
445
|
+
#
|
446
|
+
# Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
|
447
|
+
# value should be the value of the option selected, not the visible text.
|
448
|
+
#
|
449
|
+
#
|
450
|
+
# 'locator' is an element locator
|
451
|
+
# 'value' is the value to type
|
452
|
+
def type(locator,value)
|
453
|
+
do_command("type", [locator,value,])
|
454
|
+
end
|
455
|
+
|
456
|
+
|
457
|
+
# Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e.,
|
458
|
+
# the delay is 0 milliseconds.
|
459
|
+
#
|
460
|
+
# 'value' is the number of milliseconds to pause after operation
|
461
|
+
def set_speed(value)
|
462
|
+
do_command("setSpeed", [value,])
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
# Get execution speed (i.e., get the millisecond length of the delay following each selenium operation). By default, there is no such delay, i.e.,
|
467
|
+
# the delay is 0 milliseconds.
|
468
|
+
#
|
469
|
+
# See also setSpeed.
|
470
|
+
#
|
471
|
+
def get_speed()
|
472
|
+
do_command("getSpeed", [])
|
473
|
+
end
|
474
|
+
|
475
|
+
|
476
|
+
# Check a toggle-button (checkbox/radio)
|
477
|
+
#
|
478
|
+
# 'locator' is an element locator
|
479
|
+
def check(locator)
|
480
|
+
do_command("check", [locator,])
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
# Uncheck a toggle-button (checkbox/radio)
|
485
|
+
#
|
486
|
+
# 'locator' is an element locator
|
487
|
+
def uncheck(locator)
|
488
|
+
do_command("uncheck", [locator,])
|
489
|
+
end
|
490
|
+
|
491
|
+
|
492
|
+
# Select an option from a drop-down using an option locator.
|
493
|
+
#
|
494
|
+
#
|
495
|
+
# Option locators provide different ways of specifying options of an HTML
|
496
|
+
# Select element (e.g. for selecting a specific option, or for asserting
|
497
|
+
# that the selected option satisfies a specification). There are several
|
498
|
+
# forms of Select Option Locator.
|
499
|
+
#
|
500
|
+
# * <b>label</b>=<em>labelPattern</em>::
|
501
|
+
# matches options based on their labels, i.e. the visible text. (This
|
502
|
+
# is the default.)
|
503
|
+
# * label=regexp:^[Oo]ther
|
504
|
+
#
|
505
|
+
#
|
506
|
+
# * <b>value</b>=<em>valuePattern</em>::
|
507
|
+
# matches options based on their values.
|
508
|
+
# * value=other
|
509
|
+
#
|
510
|
+
#
|
511
|
+
# * <b>id</b>=<em>id</em>::
|
512
|
+
# matches options based on their ids.
|
513
|
+
# * id=option1
|
514
|
+
#
|
515
|
+
#
|
516
|
+
# * <b>index</b>=<em>index</em>::
|
517
|
+
# matches an option based on its index (offset from zero).
|
518
|
+
# * index=2
|
519
|
+
#
|
520
|
+
#
|
521
|
+
#
|
522
|
+
#
|
523
|
+
# If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
|
524
|
+
#
|
525
|
+
#
|
526
|
+
#
|
527
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
528
|
+
# 'optionLocator' is an option locator (a label by default)
|
529
|
+
def select(selectLocator,optionLocator)
|
530
|
+
do_command("select", [selectLocator,optionLocator,])
|
531
|
+
end
|
532
|
+
|
533
|
+
|
534
|
+
# Add a selection to the set of selected options in a multi-select element using an option locator.
|
535
|
+
#
|
536
|
+
# @see #doSelect for details of option locators
|
537
|
+
#
|
538
|
+
# 'locator' is an element locator identifying a multi-select box
|
539
|
+
# 'optionLocator' is an option locator (a label by default)
|
540
|
+
def add_selection(locator,optionLocator)
|
541
|
+
do_command("addSelection", [locator,optionLocator,])
|
542
|
+
end
|
543
|
+
|
544
|
+
|
545
|
+
# Remove a selection from the set of selected options in a multi-select element using an option locator.
|
546
|
+
#
|
547
|
+
# @see #doSelect for details of option locators
|
548
|
+
#
|
549
|
+
# 'locator' is an element locator identifying a multi-select box
|
550
|
+
# 'optionLocator' is an option locator (a label by default)
|
551
|
+
def remove_selection(locator,optionLocator)
|
552
|
+
do_command("removeSelection", [locator,optionLocator,])
|
553
|
+
end
|
554
|
+
|
555
|
+
|
556
|
+
# Submit the specified form. This is particularly useful for forms without
|
557
|
+
# submit buttons, e.g. single-input "Search" forms.
|
558
|
+
#
|
559
|
+
# 'formLocator' is an element locator for the form you want to submit
|
560
|
+
def submit(formLocator)
|
561
|
+
do_command("submit", [formLocator,])
|
562
|
+
end
|
563
|
+
|
564
|
+
|
565
|
+
# Opens an URL in the test frame. This accepts both relative and absolute
|
566
|
+
# URLs.
|
567
|
+
#
|
568
|
+
# The "open" command waits for the page to load before proceeding,
|
569
|
+
# ie. the "AndWait" suffix is implicit.
|
570
|
+
#
|
571
|
+
# <em>Note</em>: The URL must be on the same domain as the runner HTML
|
572
|
+
# due to security restrictions in the browser (Same Origin Policy). If you
|
573
|
+
# need to open an URL on another domain, use the Selenium Server to start a
|
574
|
+
# new browser session on that domain.
|
575
|
+
#
|
576
|
+
# 'url' is the URL to open; may be relative or absolute
|
577
|
+
def open(url)
|
578
|
+
do_command("open", [url,])
|
579
|
+
end
|
580
|
+
|
581
|
+
|
582
|
+
# Opens a popup window (if a window with that ID isn't already open).
|
583
|
+
# After opening the window, you'll need to select it using the selectWindow
|
584
|
+
# command.
|
585
|
+
#
|
586
|
+
# This command can also be a useful workaround for bug SEL-339. In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
|
587
|
+
# In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
|
588
|
+
# an empty (blank) url, like this: openWindow("", "myFunnyWindow").
|
589
|
+
#
|
590
|
+
#
|
591
|
+
# 'url' is the URL to open, which can be blank
|
592
|
+
# 'windowID' is the JavaScript window ID of the window to select
|
593
|
+
def open_window(url,windowID)
|
594
|
+
do_command("openWindow", [url,windowID,])
|
595
|
+
end
|
596
|
+
|
597
|
+
|
598
|
+
# Selects a popup window; once a popup window has been selected, all
|
599
|
+
# commands go to that window. To select the main window again, use null
|
600
|
+
# as the target.
|
601
|
+
#
|
602
|
+
# Selenium has several strategies for finding the window object referred to by the "windowID" parameter.
|
603
|
+
# 1.) if windowID is null, then it is assumed the user is referring to the original window instantiated by the browser).
|
604
|
+
# 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
|
605
|
+
# that this variable contains the return value from a call to the JavaScript window.open() method.
|
606
|
+
# 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window objects. Each of these string
|
607
|
+
# names matches the second parameter "windowName" past to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
|
608
|
+
# (which selenium intercepts).
|
609
|
+
# If you're having trouble figuring out what is the name of a window that you want to manipulate, look at the selenium log messages
|
610
|
+
# which identify the names of windows created via window.open (and therefore intercepted by selenium). You will see messages
|
611
|
+
# like the following for each window as it is opened:
|
612
|
+
# <tt>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</tt>
|
613
|
+
# In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
|
614
|
+
# (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
|
615
|
+
# an empty (blank) url, like this: openWindow("", "myFunnyWindow").
|
616
|
+
#
|
617
|
+
#
|
618
|
+
# 'windowID' is the JavaScript window ID of the window to select
|
619
|
+
def select_window(windowID)
|
620
|
+
do_command("selectWindow", [windowID,])
|
621
|
+
end
|
622
|
+
|
623
|
+
|
624
|
+
# Selects a frame within the current window. (You may invoke this command
|
625
|
+
# multiple times to select nested frames.) To select the parent frame, use
|
626
|
+
# "relative=parent" as a locator; to select the top frame, use "relative=top".
|
627
|
+
#
|
628
|
+
# You may also use a DOM expression to identify the frame you want directly,
|
629
|
+
# like this: <tt>dom=frames["main"].frames["subframe"]</tt>
|
630
|
+
#
|
631
|
+
#
|
632
|
+
# 'locator' is an element locator identifying a frame or iframe
|
633
|
+
def select_frame(locator)
|
634
|
+
do_command("selectFrame", [locator,])
|
635
|
+
end
|
636
|
+
|
637
|
+
|
638
|
+
# Return the contents of the log.
|
639
|
+
#
|
640
|
+
# This is a placeholder intended to make the code generator make this API
|
641
|
+
# available to clients. The selenium server will intercept this call, however,
|
642
|
+
# and return its recordkeeping of log messages since the last call to this API.
|
643
|
+
# Thus this code in JavaScript will never be called.
|
644
|
+
# The reason I opted for a servercentric solution is to be able to support
|
645
|
+
# multiple frames served from different domains, which would break a
|
646
|
+
# centralized JavaScript logging mechanism under some conditions.
|
647
|
+
#
|
648
|
+
#
|
649
|
+
def get_log_messages()
|
650
|
+
return get_string("getLogMessages", [])
|
651
|
+
end
|
652
|
+
|
653
|
+
|
654
|
+
# Determine whether current/locator identify the frame containing this running code.
|
655
|
+
#
|
656
|
+
# This is useful in proxy injection mode, where this code runs in every
|
657
|
+
# browser frame and window, and sometimes the selenium server needs to identify
|
658
|
+
# the "current" frame. In this case, when the test calls selectFrame, this
|
659
|
+
# routine is called for each frame to figure out which one has been selected.
|
660
|
+
# The selected frame will return true, while all others will return false.
|
661
|
+
#
|
662
|
+
#
|
663
|
+
# 'currentFrameString' is starting frame
|
664
|
+
# 'target' is new frame (which might be relative to the current one)
|
665
|
+
def get_whether_this_frame_match_frame_expression(currentFrameString,target)
|
666
|
+
return get_boolean("getWhetherThisFrameMatchFrameExpression", [currentFrameString,target,])
|
667
|
+
end
|
668
|
+
|
669
|
+
|
670
|
+
# Determine whether currentWindowString plus target identify the window containing this running code.
|
671
|
+
#
|
672
|
+
# This is useful in proxy injection mode, where this code runs in every
|
673
|
+
# browser frame and window, and sometimes the selenium server needs to identify
|
674
|
+
# the "current" window. In this case, when the test calls selectWindow, this
|
675
|
+
# routine is called for each window to figure out which one has been selected.
|
676
|
+
# The selected window will return true, while all others will return false.
|
677
|
+
#
|
678
|
+
#
|
679
|
+
# 'currentWindowString' is starting window
|
680
|
+
# 'target' is new window (which might be relative to the current one, e.g., "_parent")
|
681
|
+
def get_whether_this_window_match_window_expression(currentWindowString,target)
|
682
|
+
return get_boolean("getWhetherThisWindowMatchWindowExpression", [currentWindowString,target,])
|
683
|
+
end
|
684
|
+
|
685
|
+
|
686
|
+
# Waits for a popup window to appear and load up.
|
687
|
+
#
|
688
|
+
# 'windowID' is the JavaScript window ID of the window that will appear
|
689
|
+
# 'timeout' is a timeout in milliseconds, after which the action will return with an error
|
690
|
+
def wait_for_pop_up(windowID,timeout)
|
691
|
+
do_command("waitForPopUp", [windowID,timeout,])
|
692
|
+
end
|
693
|
+
|
694
|
+
|
695
|
+
# By default, Selenium's overridden window.confirm() function will
|
696
|
+
# return true, as if the user had manually clicked OK. After running
|
697
|
+
# this command, the next call to confirm() will return false, as if
|
698
|
+
# the user had clicked Cancel.
|
699
|
+
#
|
700
|
+
def choose_cancel_on_next_confirmation()
|
701
|
+
do_command("chooseCancelOnNextConfirmation", [])
|
702
|
+
end
|
703
|
+
|
704
|
+
|
705
|
+
# Instructs Selenium to return the specified answer string in response to
|
706
|
+
# the next JavaScript prompt [window.prompt()].
|
707
|
+
#
|
708
|
+
# 'answer' is the answer to give in response to the prompt pop-up
|
709
|
+
def answer_on_next_prompt(answer)
|
710
|
+
do_command("answerOnNextPrompt", [answer,])
|
711
|
+
end
|
712
|
+
|
713
|
+
|
714
|
+
# Simulates the user clicking the "back" button on their browser.
|
715
|
+
#
|
716
|
+
def go_back()
|
717
|
+
do_command("goBack", [])
|
718
|
+
end
|
719
|
+
|
720
|
+
|
721
|
+
# Simulates the user clicking the "Refresh" button on their browser.
|
722
|
+
#
|
723
|
+
def refresh()
|
724
|
+
do_command("refresh", [])
|
725
|
+
end
|
726
|
+
|
727
|
+
|
728
|
+
# Simulates the user clicking the "close" button in the titlebar of a popup
|
729
|
+
# window or tab.
|
730
|
+
#
|
731
|
+
def close()
|
732
|
+
do_command("close", [])
|
733
|
+
end
|
734
|
+
|
735
|
+
|
736
|
+
# Has an alert occurred?
|
737
|
+
#
|
738
|
+
#
|
739
|
+
# This function never throws an exception
|
740
|
+
#
|
741
|
+
#
|
742
|
+
#
|
743
|
+
def is_alert_present()
|
744
|
+
return get_boolean("isAlertPresent", [])
|
745
|
+
end
|
746
|
+
|
747
|
+
|
748
|
+
# Has a prompt occurred?
|
749
|
+
#
|
750
|
+
#
|
751
|
+
# This function never throws an exception
|
752
|
+
#
|
753
|
+
#
|
754
|
+
#
|
755
|
+
def is_prompt_present()
|
756
|
+
return get_boolean("isPromptPresent", [])
|
757
|
+
end
|
758
|
+
|
759
|
+
|
760
|
+
# Has confirm() been called?
|
761
|
+
#
|
762
|
+
#
|
763
|
+
# This function never throws an exception
|
764
|
+
#
|
765
|
+
#
|
766
|
+
#
|
767
|
+
def is_confirmation_present()
|
768
|
+
return get_boolean("isConfirmationPresent", [])
|
769
|
+
end
|
770
|
+
|
771
|
+
|
772
|
+
# Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
|
773
|
+
#
|
774
|
+
# Getting an alert has the same effect as manually clicking OK. If an
|
775
|
+
# alert is generated but you do not get/verify it, the next Selenium action
|
776
|
+
# will fail.
|
777
|
+
# NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
|
778
|
+
# dialog.
|
779
|
+
# NOTE: Selenium does NOT support JavaScript alerts that are generated in a
|
780
|
+
# page's onload() event handler. In this case a visible dialog WILL be
|
781
|
+
# generated and Selenium will hang until someone manually clicks OK.
|
782
|
+
#
|
783
|
+
#
|
784
|
+
def get_alert()
|
785
|
+
return get_string("getAlert", [])
|
786
|
+
end
|
787
|
+
|
788
|
+
|
789
|
+
# Retrieves the message of a JavaScript confirmation dialog generated during
|
790
|
+
# the previous action.
|
791
|
+
#
|
792
|
+
#
|
793
|
+
# By default, the confirm function will return true, having the same effect
|
794
|
+
# as manually clicking OK. This can be changed by prior execution of the
|
795
|
+
# chooseCancelOnNextConfirmation command. If an confirmation is generated
|
796
|
+
# but you do not get/verify it, the next Selenium action will fail.
|
797
|
+
#
|
798
|
+
#
|
799
|
+
# NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
|
800
|
+
# dialog.
|
801
|
+
#
|
802
|
+
#
|
803
|
+
# NOTE: Selenium does NOT support JavaScript confirmations that are
|
804
|
+
# generated in a page's onload() event handler. In this case a visible
|
805
|
+
# dialog WILL be generated and Selenium will hang until you manually click
|
806
|
+
# OK.
|
807
|
+
#
|
808
|
+
#
|
809
|
+
#
|
810
|
+
def get_confirmation()
|
811
|
+
return get_string("getConfirmation", [])
|
812
|
+
end
|
813
|
+
|
814
|
+
|
815
|
+
# Retrieves the message of a JavaScript question prompt dialog generated during
|
816
|
+
# the previous action.
|
817
|
+
#
|
818
|
+
# Successful handling of the prompt requires prior execution of the
|
819
|
+
# answerOnNextPrompt command. If a prompt is generated but you
|
820
|
+
# do not get/verify it, the next Selenium action will fail.
|
821
|
+
# NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
|
822
|
+
# dialog.
|
823
|
+
# NOTE: Selenium does NOT support JavaScript prompts that are generated in a
|
824
|
+
# page's onload() event handler. In this case a visible dialog WILL be
|
825
|
+
# generated and Selenium will hang until someone manually clicks OK.
|
826
|
+
#
|
827
|
+
#
|
828
|
+
def get_prompt()
|
829
|
+
return get_string("getPrompt", [])
|
830
|
+
end
|
831
|
+
|
832
|
+
|
833
|
+
# Gets the absolute URL of the current page.
|
834
|
+
#
|
835
|
+
def get_location()
|
836
|
+
return get_string("getLocation", [])
|
837
|
+
end
|
838
|
+
|
839
|
+
|
840
|
+
# Gets the title of the current page.
|
841
|
+
#
|
842
|
+
def get_title()
|
843
|
+
return get_string("getTitle", [])
|
844
|
+
end
|
845
|
+
|
846
|
+
|
847
|
+
# Gets the entire text of the page.
|
848
|
+
#
|
849
|
+
def get_body_text()
|
850
|
+
return get_string("getBodyText", [])
|
851
|
+
end
|
852
|
+
|
853
|
+
|
854
|
+
# Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
|
855
|
+
# For checkbox/radio elements, the value will be "on" or "off" depending on
|
856
|
+
# whether the element is checked or not.
|
857
|
+
#
|
858
|
+
# 'locator' is an element locator
|
859
|
+
def get_value(locator)
|
860
|
+
return get_string("getValue", [locator,])
|
861
|
+
end
|
862
|
+
|
863
|
+
|
864
|
+
# Gets the text of an element. This works for any element that contains
|
865
|
+
# text. This command uses either the textContent (Mozilla-like browsers) or
|
866
|
+
# the innerText (IE-like browsers) of the element, which is the rendered
|
867
|
+
# text shown to the user.
|
868
|
+
#
|
869
|
+
# 'locator' is an element locator
|
870
|
+
def get_text(locator)
|
871
|
+
return get_string("getText", [locator,])
|
872
|
+
end
|
873
|
+
|
874
|
+
|
875
|
+
# Gets the result of evaluating the specified JavaScript snippet. The snippet may
|
876
|
+
# have multiple lines, but only the result of the last line will be returned.
|
877
|
+
#
|
878
|
+
# Note that, by default, the snippet will run in the context of the "selenium"
|
879
|
+
# object itself, so <tt>this</tt> will refer to the Selenium object, and <tt>window</tt> will
|
880
|
+
# refer to the top-level runner test window, not the window of your application.
|
881
|
+
# If you need a reference to the window of your application, you can refer
|
882
|
+
# to <tt>this.browserbot.getCurrentWindow()</tt> and if you need to use
|
883
|
+
# a locator to refer to a single element in your application page, you can
|
884
|
+
# use <tt>this.page().findElement("foo")</tt> where "foo" is your locator.
|
885
|
+
#
|
886
|
+
#
|
887
|
+
# 'script' is the JavaScript snippet to run
|
888
|
+
def get_eval(script)
|
889
|
+
return get_string("getEval", [script,])
|
890
|
+
end
|
891
|
+
|
892
|
+
|
893
|
+
# Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
|
894
|
+
#
|
895
|
+
# 'locator' is an element locator pointing to a checkbox or radio button
|
896
|
+
def is_checked(locator)
|
897
|
+
return get_boolean("isChecked", [locator,])
|
898
|
+
end
|
899
|
+
|
900
|
+
|
901
|
+
# Gets the text from a cell of a table. The cellAddress syntax
|
902
|
+
# tableLocator.row.column, where row and column start at 0.
|
903
|
+
#
|
904
|
+
# 'tableCellAddress' is a cell address, e.g. "foo.1.4"
|
905
|
+
def get_table(tableCellAddress)
|
906
|
+
return get_string("getTable", [tableCellAddress,])
|
907
|
+
end
|
908
|
+
|
909
|
+
|
910
|
+
# Gets all option labels (visible text) for selected options in the specified select or multi-select element.
|
911
|
+
#
|
912
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
913
|
+
def get_selected_labels(selectLocator)
|
914
|
+
return get_string_array("getSelectedLabels", [selectLocator,])
|
915
|
+
end
|
916
|
+
|
917
|
+
|
918
|
+
# Gets option label (visible text) for selected option in the specified select element.
|
919
|
+
#
|
920
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
921
|
+
def get_selected_label(selectLocator)
|
922
|
+
return get_string("getSelectedLabel", [selectLocator,])
|
923
|
+
end
|
924
|
+
|
925
|
+
|
926
|
+
# Gets all option values (value attributes) for selected options in the specified select or multi-select element.
|
927
|
+
#
|
928
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
929
|
+
def get_selected_values(selectLocator)
|
930
|
+
return get_string_array("getSelectedValues", [selectLocator,])
|
931
|
+
end
|
932
|
+
|
933
|
+
|
934
|
+
# Gets option value (value attribute) for selected option in the specified select element.
|
935
|
+
#
|
936
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
937
|
+
def get_selected_value(selectLocator)
|
938
|
+
return get_string("getSelectedValue", [selectLocator,])
|
939
|
+
end
|
940
|
+
|
941
|
+
|
942
|
+
# Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
|
943
|
+
#
|
944
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
945
|
+
def get_selected_indexes(selectLocator)
|
946
|
+
return get_string_array("getSelectedIndexes", [selectLocator,])
|
947
|
+
end
|
948
|
+
|
949
|
+
|
950
|
+
# Gets option index (option number, starting at 0) for selected option in the specified select element.
|
951
|
+
#
|
952
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
953
|
+
def get_selected_index(selectLocator)
|
954
|
+
return get_string("getSelectedIndex", [selectLocator,])
|
955
|
+
end
|
956
|
+
|
957
|
+
|
958
|
+
# Gets all option element IDs for selected options in the specified select or multi-select element.
|
959
|
+
#
|
960
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
961
|
+
def get_selected_ids(selectLocator)
|
962
|
+
return get_string_array("getSelectedIds", [selectLocator,])
|
963
|
+
end
|
964
|
+
|
965
|
+
|
966
|
+
# Gets option element ID for selected option in the specified select element.
|
967
|
+
#
|
968
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
969
|
+
def get_selected_id(selectLocator)
|
970
|
+
return get_string("getSelectedId", [selectLocator,])
|
971
|
+
end
|
972
|
+
|
973
|
+
|
974
|
+
# Determines whether some option in a drop-down menu is selected.
|
975
|
+
#
|
976
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
977
|
+
def is_something_selected(selectLocator)
|
978
|
+
return get_boolean("isSomethingSelected", [selectLocator,])
|
979
|
+
end
|
980
|
+
|
981
|
+
|
982
|
+
# Gets all option labels in the specified select drop-down.
|
983
|
+
#
|
984
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
985
|
+
def get_select_options(selectLocator)
|
986
|
+
return get_string_array("getSelectOptions", [selectLocator,])
|
987
|
+
end
|
988
|
+
|
989
|
+
|
990
|
+
# Gets the value of an element attribute.
|
991
|
+
#
|
992
|
+
# 'attributeLocator' is an element locator followed by an
|
993
|
+
def get_attribute(attributeLocator)
|
994
|
+
return get_string("getAttribute", [attributeLocator,])
|
995
|
+
end
|
996
|
+
|
997
|
+
|
998
|
+
# Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
|
999
|
+
#
|
1000
|
+
# 'pattern' is a pattern to match with the text of the page
|
1001
|
+
def is_text_present(pattern)
|
1002
|
+
return get_boolean("isTextPresent", [pattern,])
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
|
1006
|
+
# Verifies that the specified element is somewhere on the page.
|
1007
|
+
#
|
1008
|
+
# 'locator' is an element locator
|
1009
|
+
def is_element_present(locator)
|
1010
|
+
return get_boolean("isElementPresent", [locator,])
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
|
1014
|
+
# Determines if the specified element is visible. An
|
1015
|
+
# element can be rendered invisible by setting the CSS "visibility"
|
1016
|
+
# property to "hidden", or the "display" property to "none", either for the
|
1017
|
+
# element itself or one if its ancestors. This method will fail if
|
1018
|
+
# the element is not present.
|
1019
|
+
#
|
1020
|
+
# 'locator' is an element locator
|
1021
|
+
def is_visible(locator)
|
1022
|
+
return get_boolean("isVisible", [locator,])
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
|
1026
|
+
# Determines whether the specified input element is editable, ie hasn't been disabled.
|
1027
|
+
# This method will fail if the specified element isn't an input element.
|
1028
|
+
#
|
1029
|
+
# 'locator' is an element locator
|
1030
|
+
def is_editable(locator)
|
1031
|
+
return get_boolean("isEditable", [locator,])
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
|
1035
|
+
# Returns the IDs of all buttons on the page.
|
1036
|
+
#
|
1037
|
+
# If a given button has no ID, it will appear as "" in this array.
|
1038
|
+
#
|
1039
|
+
#
|
1040
|
+
def get_all_buttons()
|
1041
|
+
return get_string_array("getAllButtons", [])
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
|
1045
|
+
# Returns the IDs of all links on the page.
|
1046
|
+
#
|
1047
|
+
# If a given link has no ID, it will appear as "" in this array.
|
1048
|
+
#
|
1049
|
+
#
|
1050
|
+
def get_all_links()
|
1051
|
+
return get_string_array("getAllLinks", [])
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
|
1055
|
+
# Returns the IDs of all input fields on the page.
|
1056
|
+
#
|
1057
|
+
# If a given field has no ID, it will appear as "" in this array.
|
1058
|
+
#
|
1059
|
+
#
|
1060
|
+
def get_all_fields()
|
1061
|
+
return get_string_array("getAllFields", [])
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
|
1065
|
+
# Returns every instance of some attribute from all known windows.
|
1066
|
+
#
|
1067
|
+
# 'attributeName' is name of an attribute on the windows
|
1068
|
+
def get_attribute_from_all_windows(attributeName)
|
1069
|
+
return get_string_array("getAttributeFromAllWindows", [attributeName,])
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
|
1073
|
+
# deprecated - use dragAndDrop instead
|
1074
|
+
#
|
1075
|
+
# 'locator' is an element locator
|
1076
|
+
# 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
|
1077
|
+
def dragdrop(locator,movementsString)
|
1078
|
+
do_command("dragdrop", [locator,movementsString,])
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
|
1082
|
+
# Drags an element a certain distance and then drops it
|
1083
|
+
#
|
1084
|
+
# 'locator' is an element locator
|
1085
|
+
# 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
|
1086
|
+
def drag_and_drop(locator,movementsString)
|
1087
|
+
do_command("dragAndDrop", [locator,movementsString,])
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
|
1091
|
+
# Drags an element and drops it on another element
|
1092
|
+
#
|
1093
|
+
# 'locatorOfObjectToBeDragged' is an element to be dragged
|
1094
|
+
# 'locatorOfDragDestinationObject' is an element whose location (i.e., whose top left corner) will be the point where locatorOfObjectToBeDragged is dropped
|
1095
|
+
def drag_and_drop_to_object(locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
|
1096
|
+
do_command("dragAndDropToObject", [locatorOfObjectToBeDragged,locatorOfDragDestinationObject,])
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
|
1100
|
+
# Gives focus to a window
|
1101
|
+
#
|
1102
|
+
# 'windowName' is name of the window to be given focus
|
1103
|
+
def window_focus(windowName)
|
1104
|
+
do_command("windowFocus", [windowName,])
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
|
1108
|
+
# Resize window to take up the entire screen
|
1109
|
+
#
|
1110
|
+
# 'windowName' is name of the window to be enlarged
|
1111
|
+
def window_maximize(windowName)
|
1112
|
+
do_command("windowMaximize", [windowName,])
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
|
1116
|
+
# Returns the IDs of all windows that the browser knows about.
|
1117
|
+
#
|
1118
|
+
def get_all_window_ids()
|
1119
|
+
return get_string_array("getAllWindowIds", [])
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
|
1123
|
+
# Returns the names of all windows that the browser knows about.
|
1124
|
+
#
|
1125
|
+
def get_all_window_names()
|
1126
|
+
return get_string_array("getAllWindowNames", [])
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
|
1130
|
+
# Returns the titles of all windows that the browser knows about.
|
1131
|
+
#
|
1132
|
+
def get_all_window_titles()
|
1133
|
+
return get_string_array("getAllWindowTitles", [])
|
1134
|
+
end
|
1135
|
+
|
1136
|
+
|
1137
|
+
# Returns the entire HTML source between the opening and
|
1138
|
+
# closing "html" tags.
|
1139
|
+
#
|
1140
|
+
def get_html_source()
|
1141
|
+
return get_string("getHtmlSource", [])
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
|
1145
|
+
# Moves the text cursor to the specified position in the given input element or textarea.
|
1146
|
+
# This method will fail if the specified element isn't an input element or textarea.
|
1147
|
+
#
|
1148
|
+
# 'locator' is an element locator pointing to an input element or textarea
|
1149
|
+
# 'position' is the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
|
1150
|
+
def set_cursor_position(locator,position)
|
1151
|
+
do_command("setCursorPosition", [locator,position,])
|
1152
|
+
end
|
1153
|
+
|
1154
|
+
|
1155
|
+
# Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
|
1156
|
+
# will be ignored.
|
1157
|
+
#
|
1158
|
+
# 'locator' is an element locator pointing to an element
|
1159
|
+
def get_element_index(locator)
|
1160
|
+
return get_number("getElementIndex", [locator,])
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
|
1164
|
+
# Check if these two elements have same parent and are ordered. Two same elements will
|
1165
|
+
# not be considered ordered.
|
1166
|
+
#
|
1167
|
+
# 'locator1' is an element locator pointing to the first element
|
1168
|
+
# 'locator2' is an element locator pointing to the second element
|
1169
|
+
def is_ordered(locator1,locator2)
|
1170
|
+
return get_boolean("isOrdered", [locator1,locator2,])
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
|
1174
|
+
# Retrieves the horizontal position of an element
|
1175
|
+
#
|
1176
|
+
# 'locator' is an element locator pointing to an element OR an element itself
|
1177
|
+
def get_element_position_left(locator)
|
1178
|
+
return get_number("getElementPositionLeft", [locator,])
|
1179
|
+
end
|
1180
|
+
|
1181
|
+
|
1182
|
+
# Retrieves the vertical position of an element
|
1183
|
+
#
|
1184
|
+
# 'locator' is an element locator pointing to an element OR an element itself
|
1185
|
+
def get_element_position_top(locator)
|
1186
|
+
return get_number("getElementPositionTop", [locator,])
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
|
1190
|
+
# Retrieves the width of an element
|
1191
|
+
#
|
1192
|
+
# 'locator' is an element locator pointing to an element
|
1193
|
+
def get_element_width(locator)
|
1194
|
+
return get_number("getElementWidth", [locator,])
|
1195
|
+
end
|
1196
|
+
|
1197
|
+
|
1198
|
+
# Retrieves the height of an element
|
1199
|
+
#
|
1200
|
+
# 'locator' is an element locator pointing to an element
|
1201
|
+
def get_element_height(locator)
|
1202
|
+
return get_number("getElementHeight", [locator,])
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
|
1206
|
+
# Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
|
1207
|
+
#
|
1208
|
+
# Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
|
1209
|
+
# return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243.
|
1210
|
+
#
|
1211
|
+
# This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
|
1212
|
+
#
|
1213
|
+
# 'locator' is an element locator pointing to an input element or textarea
|
1214
|
+
def get_cursor_position(locator)
|
1215
|
+
return get_number("getCursorPosition", [locator,])
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
|
1219
|
+
# Writes a message to the status bar and adds a note to the browser-side
|
1220
|
+
# log.
|
1221
|
+
#
|
1222
|
+
# If logLevelThreshold is specified, set the threshold for logging
|
1223
|
+
# to that level (debug, info, warn, error).
|
1224
|
+
# (Note that the browser-side logs will <em>not</em> be sent back to the
|
1225
|
+
# server, and are invisible to the Client Driver.)
|
1226
|
+
#
|
1227
|
+
#
|
1228
|
+
# 'context' is the message to be sent to the browser
|
1229
|
+
# 'logLevelThreshold' is one of "debug", "info", "warn", "error", sets the threshold for browser-side logging
|
1230
|
+
def set_context(context,logLevelThreshold)
|
1231
|
+
do_command("setContext", [context,logLevelThreshold,])
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
|
1235
|
+
# Returns the specified expression.
|
1236
|
+
#
|
1237
|
+
# This is useful because of JavaScript preprocessing.
|
1238
|
+
# It is used to generate commands like assertExpression and waitForExpression.
|
1239
|
+
#
|
1240
|
+
#
|
1241
|
+
# 'expression' is the value to return
|
1242
|
+
def get_expression(expression)
|
1243
|
+
return get_string("getExpression", [expression,])
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
|
1247
|
+
# Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
|
1248
|
+
# The snippet may have multiple lines, but only the result of the last line
|
1249
|
+
# will be considered.
|
1250
|
+
#
|
1251
|
+
# Note that, by default, the snippet will be run in the runner's test window, not in the window
|
1252
|
+
# of your application. To get the window of your application, you can use
|
1253
|
+
# the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
|
1254
|
+
# run your JavaScript in there
|
1255
|
+
#
|
1256
|
+
#
|
1257
|
+
# 'script' is the JavaScript snippet to run
|
1258
|
+
# 'timeout' is a timeout in milliseconds, after which this command will return with an error
|
1259
|
+
def wait_for_condition(script,timeout)
|
1260
|
+
do_command("waitForCondition", [script,timeout,])
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
|
1264
|
+
# Specifies the amount of time that Selenium will wait for actions to complete.
|
1265
|
+
#
|
1266
|
+
# Actions that require waiting include "open" and the "waitFor*" actions.
|
1267
|
+
#
|
1268
|
+
# The default timeout is 30 seconds.
|
1269
|
+
#
|
1270
|
+
# 'timeout' is a timeout in milliseconds, after which the action will return with an error
|
1271
|
+
def set_timeout(timeout)
|
1272
|
+
do_command("setTimeout", [timeout,])
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
|
1276
|
+
# Waits for a new page to load.
|
1277
|
+
#
|
1278
|
+
# You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
|
1279
|
+
# (which are only available in the JS API).
|
1280
|
+
# Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
|
1281
|
+
# flag when it first notices a page load. Running any other Selenium command after
|
1282
|
+
# turns the flag to false. Hence, if you want to wait for a page to load, you must
|
1283
|
+
# wait immediately after a Selenium command that caused a page-load.
|
1284
|
+
#
|
1285
|
+
#
|
1286
|
+
# 'timeout' is a timeout in milliseconds, after which this command will return with an error
|
1287
|
+
def wait_for_page_to_load(timeout=@timeout)
|
1288
|
+
do_command("waitForPageToLoad", [timeout,])
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
|
1292
|
+
# Return all cookies of the current page under test.
|
1293
|
+
#
|
1294
|
+
def get_cookie()
|
1295
|
+
return get_string("getCookie", [])
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
|
1299
|
+
# Create a new cookie whose path and domain are same with those of current page
|
1300
|
+
# under test, unless you specified a path for this cookie explicitly.
|
1301
|
+
#
|
1302
|
+
# 'nameValuePair' is name and value of the cookie in a format "name=value"
|
1303
|
+
# 'optionsString' is options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
|
1304
|
+
def create_cookie(nameValuePair,optionsString)
|
1305
|
+
do_command("createCookie", [nameValuePair,optionsString,])
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
|
1309
|
+
# Delete a named cookie with specified path.
|
1310
|
+
#
|
1311
|
+
# 'name' is the name of the cookie to be deleted
|
1312
|
+
# 'path' is the path property of the cookie to be deleted
|
1313
|
+
def delete_cookie(name,path)
|
1314
|
+
do_command("deleteCookie", [name,path,])
|
1315
|
+
end
|
1316
|
+
|
1317
|
+
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
SeleneseInterpreter = SeleniumDriver # for backward compatibility
|
1321
|
+
|
1322
|
+
end
|
1323
|
+
|
1324
|
+
class SeleniumCommandError < RuntimeError
|
1325
|
+
def initialize(command_string)
|
1326
|
+
@command_string = command_string
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
def to_s
|
1330
|
+
super + "(command=#{@command_string})"
|
1331
|
+
end
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
# Defines a mixin module that you can use to write Selenium tests
|
1335
|
+
# without typing "@selenium." in front of every command. Every
|
1336
|
+
# call to a missing method will be automatically sent to the @selenium
|
1337
|
+
# object.
|
1338
|
+
module SeleniumHelper
|
1339
|
+
|
1340
|
+
# Overrides standard "open" method with @selenium.open
|
1341
|
+
def open(addr)
|
1342
|
+
@selenium.open(addr)
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
# Overrides standard "type" method with @selenium.type
|
1346
|
+
def type(inputLocator, value)
|
1347
|
+
@selenium.type(inputLocator, value)
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
# Overrides standard "select" method with @selenium.select
|
1351
|
+
def select(inputLocator, optionLocator)
|
1352
|
+
@selenium.select(inputLocator, optionLocator)
|
1353
|
+
end
|
1354
|
+
|
1355
|
+
# Passes all calls to missing methods to @selenium
|
1356
|
+
def method_missing(method_name, *args)
|
1357
|
+
if args.empty?
|
1358
|
+
@selenium.send(method_name)
|
1359
|
+
else
|
1360
|
+
@selenium.send(method_name, *args)
|
1361
|
+
end
|
1362
|
+
end
|
1363
|
+
end
|