sandoz.bbmb.ch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +26 -0
  4. data/Gemfile +12 -0
  5. data/History.txt +6 -0
  6. data/LICENSE +339 -0
  7. data/Rakefile +21 -0
  8. data/doc/index.rbx +14 -0
  9. data/doc/resources/activex/BbmbBarcodeReader.CAB +0 -0
  10. data/doc/resources/activex/BbmbBarcodeReader2.CAB +0 -0
  11. data/doc/resources/bbmb.css +301 -0
  12. data/doc/resources/errors/appdown.html +14 -0
  13. data/doc/resources/javascript/bcreader.js +131 -0
  14. data/doc/resources/javascript/order.js +65 -0
  15. data/doc/resources/javascript/widget/ContentToggler.js +60 -0
  16. data/doc/resources/javascript/widget/__package__.js +2 -0
  17. data/doc/resources/javascript/widget/templates/ContentToggler.html +4 -0
  18. data/doc/resources/logo.png +0 -0
  19. data/lib/bbmb/html/util/lookandfeel.rb +202 -0
  20. data/lib/bbmb/sandoz.rb +4 -0
  21. data/lib/bbmb/sandoz/html/state/viral/customer.rb +25 -0
  22. data/lib/bbmb/sandoz/version.rb +5 -0
  23. data/lib/bbmb/util/csv_importer.rb +123 -0
  24. data/readme.md +28 -0
  25. data/sandoz.bbmb.ch.gemspec +45 -0
  26. data/test/rcov +2 -0
  27. data/test/selenium.rb +1687 -0
  28. data/test/selenium/selenium-server.jar +0 -0
  29. data/test/selenium/test_current_order.rb +336 -0
  30. data/test/selenium/test_customer.rb +363 -0
  31. data/test/selenium/test_customers.rb +92 -0
  32. data/test/selenium/test_favorites.rb +257 -0
  33. data/test/selenium/test_favorites_result.rb +81 -0
  34. data/test/selenium/test_history.rb +112 -0
  35. data/test/selenium/test_login.rb +112 -0
  36. data/test/selenium/test_orders.rb +111 -0
  37. data/test/selenium/test_result.rb +157 -0
  38. data/test/selenium/unit.rb +146 -0
  39. data/test/stub/http_server.rb +140 -0
  40. data/test/stub/persistence.rb +58 -0
  41. data/test/suite.rb +15 -0
  42. data/test/util/data/Artikel.TXT +50 -0
  43. data/test/util/data/Kunden.TXT +14 -0
  44. data/test/util/test_csv_importer.rb +136 -0
  45. metadata +414 -0
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bbmb/sandoz/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sandoz.bbmb.ch"
8
+ spec.version = BBMB::SANDOZ::VERSION
9
+ spec.author = "Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger"
10
+ spec.email = "mhatakeyama@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com"
11
+ spec.description = "Sandoz skin for BBMB. A Ruby gem"
12
+ spec.summary = "Sandoz skin for BBMB"
13
+ spec.homepage = "https://github.com/zdavatz/sandoz.bbmb.ch"
14
+ spec.license = "GPL-v2"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "odba", '>= 1.1.2'
21
+ spec.add_dependency "ydbd-pg", '>= 0.5.1'
22
+ spec.add_dependency "ydbi", '>= 0.5.1'
23
+ spec.add_dependency "json"
24
+ spec.add_dependency "sbsm"
25
+ spec.add_dependency "htmlgrid"
26
+ spec.add_dependency "ydim", '>= 0.5.1'
27
+ spec.add_dependency "syck"
28
+ spec.add_dependency "rmail"
29
+ spec.add_dependency "rclconf"
30
+ spec.add_dependency "needle"
31
+ spec.add_dependency "hpricot"
32
+ spec.add_dependency "bbmb", '>= 2.0.1'
33
+ spec.add_runtime_dependency 'deprecated', '= 2.0.1'
34
+
35
+ spec.add_runtime_dependency "yus"
36
+
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "simplecov"
39
+ spec.add_development_dependency "rake"
40
+ spec.add_development_dependency "flexmock"
41
+ spec.add_development_dependency "test-unit"
42
+ spec.add_development_dependency "minitest"
43
+ spec.add_development_dependency "rspec"
44
+ end
45
+
data/test/rcov ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exec rcov -Ilib -I ../bbmb/lib/ test/suite.rb ../bbmb/test/suite.rb
data/test/selenium.rb ADDED
@@ -0,0 +1,1687 @@
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
+ # * username
43
+ # * name=username
44
+ #
45
+ # 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.
46
+ # * name=flavour value=chocolate
47
+ #
48
+ #
49
+ # * <b>dom</b>=<em>javascriptExpression</em>:
50
+ #
51
+ # Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
52
+ # Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
53
+ # * dom=document.forms['myForm'].myDropdown
54
+ # * dom=document.images[56]
55
+ # * dom=function foo() { return document.links[1]; }; foo();
56
+ #
57
+ #
58
+ # * <b>xpath</b>=<em>xpathExpression</em>:
59
+ # Locate an element using an XPath expression.
60
+ # * xpath=//img[@alt='The image alt text']
61
+ # * xpath=//table[@id='table1']//tr[4]/td[2]
62
+ # * xpath=//a[contains(@href,'#id1')]
63
+ # * xpath=//a[contains(@href,'#id1')]/@class
64
+ # * xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
65
+ # * xpath=//input[@name='name2' and @value='yes']
66
+ # * xpath=//*[text()="right"]
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
+ # 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).
81
+ #
82
+ #
83
+ #
84
+ # Without an explicit locator prefix, Selenium uses the following default
85
+ # strategies:
86
+ #
87
+ # * <b>dom</b>, for locators starting with "document."
88
+ # * <b>xpath</b>, for locators starting with "//"
89
+ # * <b>identifier</b>, otherwise
90
+ #
91
+ # ===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.
92
+ # Filters look much like locators, ie.
93
+ # <em>filterType</em><b>=</b><em>argument</em>Supported element-filters are:
94
+ # <b>value=</b><em>valuePattern</em>
95
+ #
96
+ # 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>
97
+ #
98
+ # Selects a single element based on its position in the list (offset from zero).===String-match Patterns
99
+ # Various Pattern syntaxes are available for matching string values:
100
+ #
101
+ # * <b>glob:</b><em>pattern</em>:
102
+ # Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
103
+ # kind of limited regular-expression syntax typically used in command-line
104
+ # shells. In a glob pattern, "*" represents any sequence of characters, and "?"
105
+ # represents any single character. Glob patterns match against the entire
106
+ # string.
107
+ # * <b>regexp:</b><em>regexp</em>:
108
+ # Match a string using a regular-expression. The full power of JavaScript
109
+ # regular-expressions is available.
110
+ # * <b>regexpi:</b><em>regexpi</em>:
111
+ # Match a string using a case-insensitive regular-expression.
112
+ # * <b>exact:</b><em>string</em>:
113
+ #
114
+ # Match a string exactly, verbatim, without any of that fancy wildcard
115
+ # stuff.
116
+ #
117
+ #
118
+ # If no pattern prefix is specified, Selenium assumes that it's a "glob"
119
+ # pattern.
120
+ #
121
+ #
122
+ # For commands that return multiple values (such as verifySelectOptions),
123
+ # the string being matched is a comma-separated list of the return values,
124
+ # where both commas and backslashes in the values are backslash-escaped.
125
+ # When providing a pattern, the optional matching syntax (i.e. glob,
126
+ # regexp, etc.) is specified once, as usual, at the beginning of the
127
+ # pattern.
128
+ #
129
+ #
130
+ module Selenium
131
+
132
+ class SeleniumDriver
133
+ include Selenium
134
+
135
+ def initialize(server_host, server_port, browserStartCommand, browserURL, timeout=30000)
136
+ @server_host = server_host
137
+ @server_port = server_port
138
+ @browserStartCommand = browserStartCommand
139
+ @browserURL = browserURL
140
+ @timeout = timeout
141
+ end
142
+
143
+ def to_s
144
+ "SeleniumDriver"
145
+ end
146
+
147
+ def start()
148
+ result = get_string("getNewBrowserSession", [@browserStartCommand, @browserURL])
149
+ @session_id = result
150
+ end
151
+
152
+ def stop()
153
+ do_command("testComplete", [])
154
+ @session_id = nil
155
+ end
156
+
157
+ def do_command(verb, args)
158
+ timeout(@timeout) do
159
+ http = Net::HTTP.new(@server_host, @server_port)
160
+ command_string = '/selenium-server/driver/?cmd=' + CGI::escape(verb)
161
+ args.length.times do |i|
162
+ arg_num = (i+1).to_s
163
+ command_string = command_string + "&" + arg_num + "=" + CGI::escape(args[i].to_s)
164
+ end
165
+ if @session_id != nil
166
+ command_string = command_string + "&sessionId=" + @session_id.to_s
167
+ end
168
+ #print "Requesting --->" + command_string + "\n"
169
+ response = http.get(command_string)
170
+ #print "RESULT: " + response.body + "\n\n"
171
+ if (response.body[0..1] != "OK")
172
+ raise SeleniumCommandError, response.body
173
+ end
174
+ return response.body
175
+ end
176
+ end
177
+
178
+ def get_string(verb, args)
179
+ result = do_command(verb, args)
180
+ return result[3..result.length]
181
+ end
182
+
183
+ def get_string_array(verb, args)
184
+ csv = get_string(verb, args)
185
+ token = ""
186
+ tokens = []
187
+ escape = false
188
+ csv.split(//).each do |letter|
189
+ if escape
190
+ token = token + letter
191
+ escape = false
192
+ next
193
+ end
194
+ if (letter == '\\')
195
+ escape = true
196
+ elsif (letter == ',')
197
+ tokens.push(token)
198
+ token = ""
199
+ else
200
+ token = token + letter
201
+ end
202
+ end
203
+ tokens.push(token)
204
+ return tokens
205
+ end
206
+
207
+ def get_number(verb, args)
208
+ # Is there something I need to do here?
209
+ return get_string(verb, args)
210
+ end
211
+
212
+ def get_number_array(verb, args)
213
+ # Is there something I need to do here?
214
+ return get_string_array(verb, args)
215
+ end
216
+
217
+ def get_boolean(verb, args)
218
+ boolstr = get_string(verb, args)
219
+ if ("true" == boolstr)
220
+ return true
221
+ end
222
+ if ("false" == boolstr)
223
+ return false
224
+ end
225
+ raise ValueError, "result is neither 'true' nor 'false': " + boolstr
226
+ end
227
+
228
+ def get_boolean_array(verb, args)
229
+ boolarr = get_string_array(verb, args)
230
+ boolarr.length.times do |i|
231
+ if ("true" == boolstr)
232
+ boolarr[i] = true
233
+ next
234
+ end
235
+ if ("false" == boolstr)
236
+ boolarr[i] = false
237
+ next
238
+ end
239
+ raise ValueError, "result is neither 'true' nor 'false': " + boolarr[i]
240
+ end
241
+ return boolarr
242
+ end
243
+
244
+
245
+
246
+ # Clicks on a link, button, checkbox or radio button. If the 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 click(locator)
252
+ do_command("click", [locator,])
253
+ end
254
+
255
+
256
+ # Double clicks on a link, button, checkbox or radio button. If the double 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
+ def double_click(locator)
262
+ do_command("doubleClick", [locator,])
263
+ end
264
+
265
+
266
+ # Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
267
+ #
268
+ # 'locator' is an element locator
269
+ def context_menu(locator)
270
+ do_command("contextMenu", [locator,])
271
+ end
272
+
273
+
274
+ # Clicks on a link, button, checkbox or radio button. If the click action
275
+ # causes a new page to load (like a link usually does), call
276
+ # waitForPageToLoad.
277
+ #
278
+ # 'locator' is an element locator
279
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
280
+ def click_at(locator,coordString)
281
+ do_command("clickAt", [locator,coordString,])
282
+ end
283
+
284
+
285
+ # Doubleclicks on a link, button, checkbox or radio button. If the action
286
+ # causes a new page to load (like a link usually does), call
287
+ # waitForPageToLoad.
288
+ #
289
+ # 'locator' is an element locator
290
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
291
+ def double_click_at(locator,coordString)
292
+ do_command("doubleClickAt", [locator,coordString,])
293
+ end
294
+
295
+
296
+ # Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
297
+ #
298
+ # 'locator' is an element locator
299
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
300
+ def context_menu_at(locator,coordString)
301
+ do_command("contextMenuAt", [locator,coordString,])
302
+ end
303
+
304
+
305
+ # Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
306
+ # handler.
307
+ #
308
+ # 'locator' is an element locator
309
+ # 'eventName' is the event name, e.g. "focus" or "blur"
310
+ def fire_event(locator,eventName)
311
+ do_command("fireEvent", [locator,eventName,])
312
+ end
313
+
314
+
315
+ # Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
316
+ #
317
+ # 'locator' is an element locator
318
+ def focus(locator)
319
+ do_command("focus", [locator,])
320
+ end
321
+
322
+
323
+ # Simulates a user pressing and releasing a key.
324
+ #
325
+ # 'locator' is an element locator
326
+ # '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".
327
+ def key_press(locator,keySequence)
328
+ do_command("keyPress", [locator,keySequence,])
329
+ end
330
+
331
+
332
+ # Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
333
+ #
334
+ def shift_key_down()
335
+ do_command("shiftKeyDown", [])
336
+ end
337
+
338
+
339
+ # Release the shift key.
340
+ #
341
+ def shift_key_up()
342
+ do_command("shiftKeyUp", [])
343
+ end
344
+
345
+
346
+ # Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
347
+ #
348
+ def meta_key_down()
349
+ do_command("metaKeyDown", [])
350
+ end
351
+
352
+
353
+ # Release the meta key.
354
+ #
355
+ def meta_key_up()
356
+ do_command("metaKeyUp", [])
357
+ end
358
+
359
+
360
+ # Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
361
+ #
362
+ def alt_key_down()
363
+ do_command("altKeyDown", [])
364
+ end
365
+
366
+
367
+ # Release the alt key.
368
+ #
369
+ def alt_key_up()
370
+ do_command("altKeyUp", [])
371
+ end
372
+
373
+
374
+ # Press the control key and hold it down until doControlUp() is called or a new page is loaded.
375
+ #
376
+ def control_key_down()
377
+ do_command("controlKeyDown", [])
378
+ end
379
+
380
+
381
+ # Release the control key.
382
+ #
383
+ def control_key_up()
384
+ do_command("controlKeyUp", [])
385
+ end
386
+
387
+
388
+ # Simulates a user pressing a key (without releasing it yet).
389
+ #
390
+ # 'locator' is an element locator
391
+ # '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".
392
+ def key_down(locator,keySequence)
393
+ do_command("keyDown", [locator,keySequence,])
394
+ end
395
+
396
+
397
+ # Simulates a user releasing a key.
398
+ #
399
+ # 'locator' is an element locator
400
+ # '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".
401
+ def key_up(locator,keySequence)
402
+ do_command("keyUp", [locator,keySequence,])
403
+ end
404
+
405
+
406
+ # Simulates a user hovering a mouse over the specified element.
407
+ #
408
+ # 'locator' is an element locator
409
+ def mouse_over(locator)
410
+ do_command("mouseOver", [locator,])
411
+ end
412
+
413
+
414
+ # Simulates a user moving the mouse pointer away from the specified element.
415
+ #
416
+ # 'locator' is an element locator
417
+ def mouse_out(locator)
418
+ do_command("mouseOut", [locator,])
419
+ end
420
+
421
+
422
+ # Simulates a user pressing the mouse button (without releasing it yet) on
423
+ # the specified element.
424
+ #
425
+ # 'locator' is an element locator
426
+ def mouse_down(locator)
427
+ do_command("mouseDown", [locator,])
428
+ end
429
+
430
+
431
+ # Simulates a user pressing the mouse button (without releasing it yet) at
432
+ # the specified location.
433
+ #
434
+ # 'locator' is an element locator
435
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
436
+ def mouse_down_at(locator,coordString)
437
+ do_command("mouseDownAt", [locator,coordString,])
438
+ end
439
+
440
+
441
+ # Simulates the event that occurs when the user releases the mouse button (i.e., stops
442
+ # holding the button down) on the specified element.
443
+ #
444
+ # 'locator' is an element locator
445
+ def mouse_up(locator)
446
+ do_command("mouseUp", [locator,])
447
+ end
448
+
449
+
450
+ # Simulates the event that occurs when the user releases the mouse button (i.e., stops
451
+ # holding the button down) at the specified location.
452
+ #
453
+ # 'locator' is an element locator
454
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
455
+ def mouse_up_at(locator,coordString)
456
+ do_command("mouseUpAt", [locator,coordString,])
457
+ end
458
+
459
+
460
+ # Simulates a user pressing the mouse button (without releasing it yet) on
461
+ # the specified element.
462
+ #
463
+ # 'locator' is an element locator
464
+ def mouse_move(locator)
465
+ do_command("mouseMove", [locator,])
466
+ end
467
+
468
+
469
+ # Simulates a user pressing the mouse button (without releasing it yet) on
470
+ # the specified element.
471
+ #
472
+ # 'locator' is an element locator
473
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
474
+ def mouse_move_at(locator,coordString)
475
+ do_command("mouseMoveAt", [locator,coordString,])
476
+ end
477
+
478
+
479
+ # Sets the value of an input field, as though you typed it in.
480
+ #
481
+ # Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
482
+ # value should be the value of the option selected, not the visible text.
483
+ #
484
+ #
485
+ # 'locator' is an element locator
486
+ # 'value' is the value to type
487
+ def type(locator,value)
488
+ do_command("type", [locator,value,])
489
+ end
490
+
491
+
492
+ # Simulates keystroke events on the specified element, as though you typed the value key-by-key.
493
+ #
494
+ # This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;
495
+ # this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
496
+ # Unlike the simple "type" command, which forces the specified value into the page directly, this command
497
+ # may or may not have any visible effect, even in cases where typing keys would normally have a visible effect.
498
+ # For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in
499
+ # the field.
500
+ # In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to
501
+ # send the keystroke events corresponding to what you just typed.
502
+ #
503
+ #
504
+ # 'locator' is an element locator
505
+ # 'value' is the value to type
506
+ def type_keys(locator,value)
507
+ do_command("typeKeys", [locator,value,])
508
+ end
509
+
510
+
511
+ # 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.,
512
+ # the delay is 0 milliseconds.
513
+ #
514
+ # 'value' is the number of milliseconds to pause after operation
515
+ def set_speed(value)
516
+ do_command("setSpeed", [value,])
517
+ end
518
+
519
+
520
+ # 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.,
521
+ # the delay is 0 milliseconds.
522
+ #
523
+ # See also setSpeed.
524
+ #
525
+ def get_speed()
526
+ return get_string("getSpeed", [])
527
+ end
528
+
529
+
530
+ # Check a toggle-button (checkbox/radio)
531
+ #
532
+ # 'locator' is an element locator
533
+ def check(locator)
534
+ do_command("check", [locator,])
535
+ end
536
+
537
+
538
+ # Uncheck a toggle-button (checkbox/radio)
539
+ #
540
+ # 'locator' is an element locator
541
+ def uncheck(locator)
542
+ do_command("uncheck", [locator,])
543
+ end
544
+
545
+
546
+ # Select an option from a drop-down using an option locator.
547
+ #
548
+ #
549
+ # Option locators provide different ways of specifying options of an HTML
550
+ # Select element (e.g. for selecting a specific option, or for asserting
551
+ # that the selected option satisfies a specification). There are several
552
+ # forms of Select Option Locator.
553
+ #
554
+ # * <b>label</b>=<em>labelPattern</em>:
555
+ # matches options based on their labels, i.e. the visible text. (This
556
+ # is the default.)
557
+ # * label=regexp:^[Oo]ther
558
+ #
559
+ #
560
+ # * <b>value</b>=<em>valuePattern</em>:
561
+ # matches options based on their values.
562
+ # * value=other
563
+ #
564
+ #
565
+ # * <b>id</b>=<em>id</em>:
566
+ #
567
+ # matches options based on their ids.
568
+ # * id=option1
569
+ #
570
+ #
571
+ # * <b>index</b>=<em>index</em>:
572
+ # matches an option based on its index (offset from zero).
573
+ # * index=2
574
+ #
575
+ #
576
+ #
577
+ #
578
+ # If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
579
+ #
580
+ #
581
+ #
582
+ # 'selectLocator' is an element locator identifying a drop-down menu
583
+ # 'optionLocator' is an option locator (a label by default)
584
+ def select(selectLocator,optionLocator)
585
+ do_command("select", [selectLocator,optionLocator,])
586
+ end
587
+
588
+
589
+ # Add a selection to the set of selected options in a multi-select element using an option locator.
590
+ #
591
+ # @see #doSelect for details of option locators
592
+ #
593
+ # 'locator' is an element locator identifying a multi-select box
594
+ # 'optionLocator' is an option locator (a label by default)
595
+ def add_selection(locator,optionLocator)
596
+ do_command("addSelection", [locator,optionLocator,])
597
+ end
598
+
599
+
600
+ # Remove a selection from the set of selected options in a multi-select element using an option locator.
601
+ #
602
+ # @see #doSelect for details of option locators
603
+ #
604
+ # 'locator' is an element locator identifying a multi-select box
605
+ # 'optionLocator' is an option locator (a label by default)
606
+ def remove_selection(locator,optionLocator)
607
+ do_command("removeSelection", [locator,optionLocator,])
608
+ end
609
+
610
+
611
+ # Unselects all of the selected options in a multi-select element.
612
+ #
613
+ # 'locator' is an element locator identifying a multi-select box
614
+ def remove_all_selections(locator)
615
+ do_command("removeAllSelections", [locator,])
616
+ end
617
+
618
+
619
+ # Submit the specified form. This is particularly useful for forms without
620
+ # submit buttons, e.g. single-input "Search" forms.
621
+ #
622
+ # 'formLocator' is an element locator for the form you want to submit
623
+ def submit(formLocator)
624
+ do_command("submit", [formLocator,])
625
+ end
626
+
627
+
628
+ # Opens an URL in the test frame. This accepts both relative and absolute
629
+ # URLs.
630
+ #
631
+ # The "open" command waits for the page to load before proceeding,
632
+ # ie. the "AndWait" suffix is implicit.
633
+ #
634
+ # <em>Note</em>: The URL must be on the same domain as the runner HTML
635
+ # due to security restrictions in the browser (Same Origin Policy). If you
636
+ # need to open an URL on another domain, use the Selenium Server to start a
637
+ # new browser session on that domain.
638
+ #
639
+ # 'url' is the URL to open; may be relative or absolute
640
+ def open(url)
641
+ do_command("open", [url,])
642
+ end
643
+
644
+
645
+ # Opens a popup window (if a window with that ID isn't already open).
646
+ # After opening the window, you'll need to select it using the selectWindow
647
+ # command.
648
+ #
649
+ # 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).
650
+ # In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
651
+ # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
652
+ #
653
+ #
654
+ # 'url' is the URL to open, which can be blank
655
+ # 'windowID' is the JavaScript window ID of the window to select
656
+ def open_window(url,windowID)
657
+ do_command("openWindow", [url,windowID,])
658
+ end
659
+
660
+
661
+ # Selects a popup window using a window locator; once a popup window has been selected, all
662
+ # commands go to that window. To select the main window again, use null
663
+ # as the target.
664
+ #
665
+ #
666
+ #
667
+ # Window locators provide different ways of specifying the window object:
668
+ # by title, by internal JavaScript "name," or by JavaScript variable.
669
+ #
670
+ # * <b>title</b>=<em>My Special Window</em>:
671
+ # Finds the window using the text that appears in the title bar. Be careful;
672
+ # two windows can share the same title. If that happens, this locator will
673
+ # just pick one.
674
+ #
675
+ # * <b>name</b>=<em>myWindow</em>:
676
+ # Finds the window using its internal JavaScript "name" property. This is the second
677
+ # parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
678
+ # (which Selenium intercepts).
679
+ #
680
+ # * <b>var</b>=<em>variableName</em>:
681
+ # Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current
682
+ # application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using
683
+ # "var=foo".
684
+ #
685
+ #
686
+ #
687
+ # If no window locator prefix is provided, we'll try to guess what you mean like this:
688
+ # 1.) if windowID is null, (or the string "null") then it is assumed the user is referring to the original window instantiated by the browser).
689
+ # 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
690
+ # that this variable contains the return value from a call to the JavaScript window.open() method.
691
+ # 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".
692
+ # 4.) If <em>that</em> fails, we'll try looping over all of the known windows to try to find the appropriate "title".
693
+ # Since "title" is not necessarily unique, this may have unexpected behavior.
694
+ # If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messages
695
+ # which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages
696
+ # like the following for each window as it is opened:
697
+ # <tt>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</tt>
698
+ # 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).
699
+ # (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
700
+ # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
701
+ #
702
+ #
703
+ # 'windowID' is the JavaScript window ID of the window to select
704
+ def select_window(windowID)
705
+ do_command("selectWindow", [windowID,])
706
+ end
707
+
708
+
709
+ # Selects a frame within the current window. (You may invoke this command
710
+ # multiple times to select nested frames.) To select the parent frame, use
711
+ # "relative=parent" as a locator; to select the top frame, use "relative=top".
712
+ # You can also select a frame by its 0-based index number; select the first frame with
713
+ # "index=0", or the third frame with "index=2".
714
+ #
715
+ # You may also use a DOM expression to identify the frame you want directly,
716
+ # like this: <tt>dom=frames["main"].frames["subframe"]</tt>
717
+ #
718
+ #
719
+ # 'locator' is an element locator identifying a frame or iframe
720
+ def select_frame(locator)
721
+ do_command("selectFrame", [locator,])
722
+ end
723
+
724
+
725
+ # Determine whether current/locator identify the frame containing this running code.
726
+ #
727
+ # This is useful in proxy injection mode, where this code runs in every
728
+ # browser frame and window, and sometimes the selenium server needs to identify
729
+ # the "current" frame. In this case, when the test calls selectFrame, this
730
+ # routine is called for each frame to figure out which one has been selected.
731
+ # The selected frame will return true, while all others will return false.
732
+ #
733
+ #
734
+ # 'currentFrameString' is starting frame
735
+ # 'target' is new frame (which might be relative to the current one)
736
+ def get_whether_this_frame_match_frame_expression(currentFrameString,target)
737
+ return get_boolean("getWhetherThisFrameMatchFrameExpression", [currentFrameString,target,])
738
+ end
739
+
740
+
741
+ # Determine whether currentWindowString plus target identify the window containing this running code.
742
+ #
743
+ # This is useful in proxy injection mode, where this code runs in every
744
+ # browser frame and window, and sometimes the selenium server needs to identify
745
+ # the "current" window. In this case, when the test calls selectWindow, this
746
+ # routine is called for each window to figure out which one has been selected.
747
+ # The selected window will return true, while all others will return false.
748
+ #
749
+ #
750
+ # 'currentWindowString' is starting window
751
+ # 'target' is new window (which might be relative to the current one, e.g., "_parent")
752
+ def get_whether_this_window_match_window_expression(currentWindowString,target)
753
+ return get_boolean("getWhetherThisWindowMatchWindowExpression", [currentWindowString,target,])
754
+ end
755
+
756
+
757
+ # Waits for a popup window to appear and load up.
758
+ #
759
+ # 'windowID' is the JavaScript window "name" of the window that will appear (not the text of the title bar)
760
+ # 'timeout' is a timeout in milliseconds, after which the action will return with an error
761
+ def wait_for_pop_up(windowID,timeout)
762
+ do_command("waitForPopUp", [windowID,timeout,])
763
+ end
764
+
765
+
766
+ # By default, Selenium's overridden window.confirm() function will
767
+ # return true, as if the user had manually clicked OK; after running
768
+ # this command, the next call to confirm() will return false, as if
769
+ # the user had clicked Cancel. Selenium will then resume using the
770
+ # default behavior for future confirmations, automatically returning
771
+ # true (OK) unless/until you explicitly call this command for each
772
+ # confirmation.
773
+ #
774
+ def choose_cancel_on_next_confirmation()
775
+ do_command("chooseCancelOnNextConfirmation", [])
776
+ end
777
+
778
+
779
+ # Undo the effect of calling chooseCancelOnNextConfirmation. Note
780
+ # that Selenium's overridden window.confirm() function will normally automatically
781
+ # return true, as if the user had manually clicked OK, so you shouldn't
782
+ # need to use this command unless for some reason you need to change
783
+ # your mind prior to the next confirmation. After any confirmation, Selenium will resume using the
784
+ # default behavior for future confirmations, automatically returning
785
+ # true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each
786
+ # confirmation.
787
+ #
788
+ def choose_ok_on_next_confirmation()
789
+ do_command("chooseOkOnNextConfirmation", [])
790
+ end
791
+
792
+
793
+ # Instructs Selenium to return the specified answer string in response to
794
+ # the next JavaScript prompt [window.prompt()].
795
+ #
796
+ # 'answer' is the answer to give in response to the prompt pop-up
797
+ def answer_on_next_prompt(answer)
798
+ do_command("answerOnNextPrompt", [answer,])
799
+ end
800
+
801
+
802
+ # Simulates the user clicking the "back" button on their browser.
803
+ #
804
+ def go_back()
805
+ do_command("goBack", [])
806
+ end
807
+
808
+
809
+ # Simulates the user clicking the "Refresh" button on their browser.
810
+ #
811
+ def refresh()
812
+ do_command("refresh", [])
813
+ end
814
+
815
+
816
+ # Simulates the user clicking the "close" button in the titlebar of a popup
817
+ # window or tab.
818
+ #
819
+ def close()
820
+ do_command("close", [])
821
+ end
822
+
823
+
824
+ # Has an alert occurred?
825
+ #
826
+ #
827
+ # This function never throws an exception
828
+ #
829
+ #
830
+ #
831
+ def is_alert_present()
832
+ return get_boolean("isAlertPresent", [])
833
+ end
834
+
835
+
836
+ # Has a prompt occurred?
837
+ #
838
+ #
839
+ # This function never throws an exception
840
+ #
841
+ #
842
+ #
843
+ def is_prompt_present()
844
+ return get_boolean("isPromptPresent", [])
845
+ end
846
+
847
+
848
+ # Has confirm() been called?
849
+ #
850
+ #
851
+ # This function never throws an exception
852
+ #
853
+ #
854
+ #
855
+ def is_confirmation_present()
856
+ return get_boolean("isConfirmationPresent", [])
857
+ end
858
+
859
+
860
+ # Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
861
+ #
862
+ # Getting an alert has the same effect as manually clicking OK. If an
863
+ # alert is generated but you do not get/verify it, the next Selenium action
864
+ # will fail.
865
+ # NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
866
+ # dialog.
867
+ # NOTE: Selenium does NOT support JavaScript alerts that are generated in a
868
+ # page's onload() event handler. In this case a visible dialog WILL be
869
+ # generated and Selenium will hang until someone manually clicks OK.
870
+ #
871
+ #
872
+ def get_alert()
873
+ return get_string("getAlert", [])
874
+ end
875
+
876
+
877
+ # Retrieves the message of a JavaScript confirmation dialog generated during
878
+ # the previous action.
879
+ #
880
+ #
881
+ # By default, the confirm function will return true, having the same effect
882
+ # as manually clicking OK. This can be changed by prior execution of the
883
+ # chooseCancelOnNextConfirmation command. If an confirmation is generated
884
+ # but you do not get/verify it, the next Selenium action will fail.
885
+ #
886
+ #
887
+ # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
888
+ # dialog.
889
+ #
890
+ #
891
+ # NOTE: Selenium does NOT support JavaScript confirmations that are
892
+ # generated in a page's onload() event handler. In this case a visible
893
+ # dialog WILL be generated and Selenium will hang until you manually click
894
+ # OK.
895
+ #
896
+ #
897
+ #
898
+ def get_confirmation()
899
+ return get_string("getConfirmation", [])
900
+ end
901
+
902
+
903
+ # Retrieves the message of a JavaScript question prompt dialog generated during
904
+ # the previous action.
905
+ #
906
+ # Successful handling of the prompt requires prior execution of the
907
+ # answerOnNextPrompt command. If a prompt is generated but you
908
+ # do not get/verify it, the next Selenium action will fail.
909
+ # NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
910
+ # dialog.
911
+ # NOTE: Selenium does NOT support JavaScript prompts that are generated in a
912
+ # page's onload() event handler. In this case a visible dialog WILL be
913
+ # generated and Selenium will hang until someone manually clicks OK.
914
+ #
915
+ #
916
+ def get_prompt()
917
+ return get_string("getPrompt", [])
918
+ end
919
+
920
+
921
+ # Gets the absolute URL of the current page.
922
+ #
923
+ def get_location()
924
+ return get_string("getLocation", [])
925
+ end
926
+
927
+
928
+ # Gets the title of the current page.
929
+ #
930
+ def get_title()
931
+ return get_string("getTitle", [])
932
+ end
933
+
934
+
935
+ # Gets the entire text of the page.
936
+ #
937
+ def get_body_text()
938
+ return get_string("getBodyText", [])
939
+ end
940
+
941
+
942
+ # Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
943
+ # For checkbox/radio elements, the value will be "on" or "off" depending on
944
+ # whether the element is checked or not.
945
+ #
946
+ # 'locator' is an element locator
947
+ def get_value(locator)
948
+ return get_string("getValue", [locator,])
949
+ end
950
+
951
+
952
+ # Gets the text of an element. This works for any element that contains
953
+ # text. This command uses either the textContent (Mozilla-like browsers) or
954
+ # the innerText (IE-like browsers) of the element, which is the rendered
955
+ # text shown to the user.
956
+ #
957
+ # 'locator' is an element locator
958
+ def get_text(locator)
959
+ return get_string("getText", [locator,])
960
+ end
961
+
962
+
963
+ # Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
964
+ #
965
+ # 'locator' is an element locator
966
+ def highlight(locator)
967
+ do_command("highlight", [locator,])
968
+ end
969
+
970
+
971
+ # Gets the result of evaluating the specified JavaScript snippet. The snippet may
972
+ # have multiple lines, but only the result of the last line will be returned.
973
+ #
974
+ # Note that, by default, the snippet will run in the context of the "selenium"
975
+ # object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
976
+ # refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
977
+ # If you need to use
978
+ # a locator to refer to a single element in your application page, you can
979
+ # use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
980
+ #
981
+ #
982
+ # 'script' is the JavaScript snippet to run
983
+ def get_eval(script)
984
+ return get_string("getEval", [script,])
985
+ end
986
+
987
+
988
+ # Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
989
+ #
990
+ # 'locator' is an element locator pointing to a checkbox or radio button
991
+ def is_checked(locator)
992
+ return get_boolean("isChecked", [locator,])
993
+ end
994
+
995
+
996
+ # Gets the text from a cell of a table. The cellAddress syntax
997
+ # tableLocator.row.column, where row and column start at 0.
998
+ #
999
+ # 'tableCellAddress' is a cell address, e.g. "foo.1.4"
1000
+ def get_table(tableCellAddress)
1001
+ return get_string("getTable", [tableCellAddress,])
1002
+ end
1003
+
1004
+
1005
+ # Gets all option labels (visible text) for selected options in the specified select or multi-select element.
1006
+ #
1007
+ # 'selectLocator' is an element locator identifying a drop-down menu
1008
+ def get_selected_labels(selectLocator)
1009
+ return get_string_array("getSelectedLabels", [selectLocator,])
1010
+ end
1011
+
1012
+
1013
+ # Gets option label (visible text) for selected option in the specified select element.
1014
+ #
1015
+ # 'selectLocator' is an element locator identifying a drop-down menu
1016
+ def get_selected_label(selectLocator)
1017
+ return get_string("getSelectedLabel", [selectLocator,])
1018
+ end
1019
+
1020
+
1021
+ # Gets all option values (value attributes) for selected options in the specified select or multi-select element.
1022
+ #
1023
+ # 'selectLocator' is an element locator identifying a drop-down menu
1024
+ def get_selected_values(selectLocator)
1025
+ return get_string_array("getSelectedValues", [selectLocator,])
1026
+ end
1027
+
1028
+
1029
+ # Gets option value (value attribute) for selected option in the specified select element.
1030
+ #
1031
+ # 'selectLocator' is an element locator identifying a drop-down menu
1032
+ def get_selected_value(selectLocator)
1033
+ return get_string("getSelectedValue", [selectLocator,])
1034
+ end
1035
+
1036
+
1037
+ # Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
1038
+ #
1039
+ # 'selectLocator' is an element locator identifying a drop-down menu
1040
+ def get_selected_indexes(selectLocator)
1041
+ return get_string_array("getSelectedIndexes", [selectLocator,])
1042
+ end
1043
+
1044
+
1045
+ # Gets option index (option number, starting at 0) for selected option in the specified select element.
1046
+ #
1047
+ # 'selectLocator' is an element locator identifying a drop-down menu
1048
+ def get_selected_index(selectLocator)
1049
+ return get_string("getSelectedIndex", [selectLocator,])
1050
+ end
1051
+
1052
+
1053
+ # Gets all option element IDs for selected options in the specified select or multi-select element.
1054
+ #
1055
+ # 'selectLocator' is an element locator identifying a drop-down menu
1056
+ def get_selected_ids(selectLocator)
1057
+ return get_string_array("getSelectedIds", [selectLocator,])
1058
+ end
1059
+
1060
+
1061
+ # Gets option element ID for selected option in the specified select element.
1062
+ #
1063
+ # 'selectLocator' is an element locator identifying a drop-down menu
1064
+ def get_selected_id(selectLocator)
1065
+ return get_string("getSelectedId", [selectLocator,])
1066
+ end
1067
+
1068
+
1069
+ # Determines whether some option in a drop-down menu is selected.
1070
+ #
1071
+ # 'selectLocator' is an element locator identifying a drop-down menu
1072
+ def is_something_selected(selectLocator)
1073
+ return get_boolean("isSomethingSelected", [selectLocator,])
1074
+ end
1075
+
1076
+
1077
+ # Gets all option labels in the specified select drop-down.
1078
+ #
1079
+ # 'selectLocator' is an element locator identifying a drop-down menu
1080
+ def get_select_options(selectLocator)
1081
+ return get_string_array("getSelectOptions", [selectLocator,])
1082
+ end
1083
+
1084
+
1085
+ # Gets the value of an element attribute. The value of the attribute may
1086
+ # differ across browsers (this is the case for the "style" attribute, for
1087
+ # example).
1088
+ #
1089
+ # 'attributeLocator' is an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"
1090
+ def get_attribute(attributeLocator)
1091
+ return get_string("getAttribute", [attributeLocator,])
1092
+ end
1093
+
1094
+
1095
+ # Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
1096
+ #
1097
+ # 'pattern' is a pattern to match with the text of the page
1098
+ def is_text_present(pattern)
1099
+ return get_boolean("isTextPresent", [pattern,])
1100
+ end
1101
+
1102
+
1103
+ # Verifies that the specified element is somewhere on the page.
1104
+ #
1105
+ # 'locator' is an element locator
1106
+ def is_element_present(locator)
1107
+ return get_boolean("isElementPresent", [locator,])
1108
+ end
1109
+
1110
+
1111
+ # Determines if the specified element is visible. An
1112
+ # element can be rendered invisible by setting the CSS "visibility"
1113
+ # property to "hidden", or the "display" property to "none", either for the
1114
+ # element itself or one if its ancestors. This method will fail if
1115
+ # the element is not present.
1116
+ #
1117
+ # 'locator' is an element locator
1118
+ def is_visible(locator)
1119
+ return get_boolean("isVisible", [locator,])
1120
+ end
1121
+
1122
+
1123
+ # Determines whether the specified input element is editable, ie hasn't been disabled.
1124
+ # This method will fail if the specified element isn't an input element.
1125
+ #
1126
+ # 'locator' is an element locator
1127
+ def is_editable(locator)
1128
+ return get_boolean("isEditable", [locator,])
1129
+ end
1130
+
1131
+
1132
+ # Returns the IDs of all buttons on the page.
1133
+ #
1134
+ # If a given button has no ID, it will appear as "" in this array.
1135
+ #
1136
+ #
1137
+ def get_all_buttons()
1138
+ return get_string_array("getAllButtons", [])
1139
+ end
1140
+
1141
+
1142
+ # Returns the IDs of all links on the page.
1143
+ #
1144
+ # If a given link has no ID, it will appear as "" in this array.
1145
+ #
1146
+ #
1147
+ def get_all_links()
1148
+ return get_string_array("getAllLinks", [])
1149
+ end
1150
+
1151
+
1152
+ # Returns the IDs of all input fields on the page.
1153
+ #
1154
+ # If a given field has no ID, it will appear as "" in this array.
1155
+ #
1156
+ #
1157
+ def get_all_fields()
1158
+ return get_string_array("getAllFields", [])
1159
+ end
1160
+
1161
+
1162
+ # Returns every instance of some attribute from all known windows.
1163
+ #
1164
+ # 'attributeName' is name of an attribute on the windows
1165
+ def get_attribute_from_all_windows(attributeName)
1166
+ return get_string_array("getAttributeFromAllWindows", [attributeName,])
1167
+ end
1168
+
1169
+
1170
+ # deprecated - use dragAndDrop instead
1171
+ #
1172
+ # 'locator' is an element locator
1173
+ # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1174
+ def dragdrop(locator,movementsString)
1175
+ do_command("dragdrop", [locator,movementsString,])
1176
+ end
1177
+
1178
+
1179
+ # Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
1180
+ # Setting this value to 0 means that we'll send a "mousemove" event to every single pixel
1181
+ # in between the start location and the end location; that can be very slow, and may
1182
+ # cause some browsers to force the JavaScript to timeout.
1183
+ # If the mouse speed is greater than the distance between the two dragged objects, we'll
1184
+ # just send one "mousemove" at the start location and then one final one at the end location.
1185
+ #
1186
+ #
1187
+ # 'pixels' is the number of pixels between "mousemove" events
1188
+ def set_mouse_speed(pixels)
1189
+ do_command("setMouseSpeed", [pixels,])
1190
+ end
1191
+
1192
+
1193
+ # Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
1194
+ #
1195
+ def get_mouse_speed()
1196
+ return get_number("getMouseSpeed", [])
1197
+ end
1198
+
1199
+
1200
+ # Drags an element a certain distance and then drops it
1201
+ #
1202
+ # 'locator' is an element locator
1203
+ # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1204
+ def drag_and_drop(locator,movementsString)
1205
+ do_command("dragAndDrop", [locator,movementsString,])
1206
+ end
1207
+
1208
+
1209
+ # Drags an element and drops it on another element
1210
+ #
1211
+ # 'locatorOfObjectToBeDragged' is an element to be dragged
1212
+ # 'locatorOfDragDestinationObject' is an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
1213
+ def drag_and_drop_to_object(locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
1214
+ do_command("dragAndDropToObject", [locatorOfObjectToBeDragged,locatorOfDragDestinationObject,])
1215
+ end
1216
+
1217
+
1218
+ # Gives focus to the currently selected window
1219
+ #
1220
+ def window_focus()
1221
+ do_command("windowFocus", [])
1222
+ end
1223
+
1224
+
1225
+ # Resize currently selected window to take up the entire screen
1226
+ #
1227
+ def window_maximize()
1228
+ do_command("windowMaximize", [])
1229
+ end
1230
+
1231
+
1232
+ # Returns the IDs of all windows that the browser knows about.
1233
+ #
1234
+ def get_all_window_ids()
1235
+ return get_string_array("getAllWindowIds", [])
1236
+ end
1237
+
1238
+
1239
+ # Returns the names of all windows that the browser knows about.
1240
+ #
1241
+ def get_all_window_names()
1242
+ return get_string_array("getAllWindowNames", [])
1243
+ end
1244
+
1245
+
1246
+ # Returns the titles of all windows that the browser knows about.
1247
+ #
1248
+ def get_all_window_titles()
1249
+ return get_string_array("getAllWindowTitles", [])
1250
+ end
1251
+
1252
+
1253
+ # Returns the entire HTML source between the opening and
1254
+ # closing "html" tags.
1255
+ #
1256
+ def get_html_source()
1257
+ return get_string("getHtmlSource", [])
1258
+ end
1259
+
1260
+
1261
+ # Moves the text cursor to the specified position in the given input element or textarea.
1262
+ # This method will fail if the specified element isn't an input element or textarea.
1263
+ #
1264
+ # 'locator' is an element locator pointing to an input element or textarea
1265
+ # '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.
1266
+ def set_cursor_position(locator,position)
1267
+ do_command("setCursorPosition", [locator,position,])
1268
+ end
1269
+
1270
+
1271
+ # Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
1272
+ # will be ignored.
1273
+ #
1274
+ # 'locator' is an element locator pointing to an element
1275
+ def get_element_index(locator)
1276
+ return get_number("getElementIndex", [locator,])
1277
+ end
1278
+
1279
+
1280
+ # Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will
1281
+ # not be considered ordered.
1282
+ #
1283
+ # 'locator1' is an element locator pointing to the first element
1284
+ # 'locator2' is an element locator pointing to the second element
1285
+ def is_ordered(locator1,locator2)
1286
+ return get_boolean("isOrdered", [locator1,locator2,])
1287
+ end
1288
+
1289
+
1290
+ # Retrieves the horizontal position of an element
1291
+ #
1292
+ # 'locator' is an element locator pointing to an element OR an element itself
1293
+ def get_element_position_left(locator)
1294
+ return get_number("getElementPositionLeft", [locator,])
1295
+ end
1296
+
1297
+
1298
+ # Retrieves the vertical position of an element
1299
+ #
1300
+ # 'locator' is an element locator pointing to an element OR an element itself
1301
+ def get_element_position_top(locator)
1302
+ return get_number("getElementPositionTop", [locator,])
1303
+ end
1304
+
1305
+
1306
+ # Retrieves the width of an element
1307
+ #
1308
+ # 'locator' is an element locator pointing to an element
1309
+ def get_element_width(locator)
1310
+ return get_number("getElementWidth", [locator,])
1311
+ end
1312
+
1313
+
1314
+ # Retrieves the height of an element
1315
+ #
1316
+ # 'locator' is an element locator pointing to an element
1317
+ def get_element_height(locator)
1318
+ return get_number("getElementHeight", [locator,])
1319
+ end
1320
+
1321
+
1322
+ # Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
1323
+ #
1324
+ # Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
1325
+ # 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.
1326
+ #
1327
+ # This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
1328
+ #
1329
+ # 'locator' is an element locator pointing to an input element or textarea
1330
+ def get_cursor_position(locator)
1331
+ return get_number("getCursorPosition", [locator,])
1332
+ end
1333
+
1334
+
1335
+ # Returns the specified expression.
1336
+ #
1337
+ # This is useful because of JavaScript preprocessing.
1338
+ # It is used to generate commands like assertExpression and waitForExpression.
1339
+ #
1340
+ #
1341
+ # 'expression' is the value to return
1342
+ def get_expression(expression)
1343
+ return get_string("getExpression", [expression,])
1344
+ end
1345
+
1346
+
1347
+ # Returns the number of nodes that match the specified xpath, eg. "//table" would give
1348
+ # the number of tables.
1349
+ #
1350
+ # 'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
1351
+ def get_xpath_count(xpath)
1352
+ return get_number("getXpathCount", [xpath,])
1353
+ end
1354
+
1355
+
1356
+ # Temporarily sets the "id" attribute of the specified element, so you can locate it in the future
1357
+ # using its ID rather than a slow/complicated XPath. This ID will disappear once the page is
1358
+ # reloaded.
1359
+ #
1360
+ # 'locator' is an element locator pointing to an element
1361
+ # 'identifier' is a string to be used as the ID of the specified element
1362
+ def assign_id(locator,identifier)
1363
+ do_command("assignId", [locator,identifier,])
1364
+ end
1365
+
1366
+
1367
+ # Specifies whether Selenium should use the native in-browser implementation
1368
+ # of XPath (if any native version is available); if you pass "false" to
1369
+ # this function, we will always use our pure-JavaScript xpath library.
1370
+ # Using the pure-JS xpath library can improve the consistency of xpath
1371
+ # element locators between different browser vendors, but the pure-JS
1372
+ # version is much slower than the native implementations.
1373
+ #
1374
+ # 'allow' is boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
1375
+ def allow_native_xpath(allow)
1376
+ do_command("allowNativeXpath", [allow,])
1377
+ end
1378
+
1379
+
1380
+ # Specifies whether Selenium will ignore xpath attributes that have no
1381
+ # value, i.e. are the empty string, when using the non-native xpath
1382
+ # evaluation engine. You'd want to do this for performance reasons in IE.
1383
+ # However, this could break certain xpaths, for example an xpath that looks
1384
+ # for an attribute whose value is NOT the empty string.
1385
+ #
1386
+ # The hope is that such xpaths are relatively rare, but the user should
1387
+ # have the option of using them. Note that this only influences xpath
1388
+ # evaluation when using the ajaxslt engine (i.e. not "javascript-xpath").
1389
+ #
1390
+ # 'ignore' is boolean, true means we'll ignore attributes without value at the expense of xpath "correctness"; false means we'll sacrifice speed for correctness.
1391
+ def ignore_attributes_without_value(ignore)
1392
+ do_command("ignoreAttributesWithoutValue", [ignore,])
1393
+ end
1394
+
1395
+
1396
+ # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
1397
+ # The snippet may have multiple lines, but only the result of the last line
1398
+ # will be considered.
1399
+ #
1400
+ # Note that, by default, the snippet will be run in the runner's test window, not in the window
1401
+ # of your application. To get the window of your application, you can use
1402
+ # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
1403
+ # run your JavaScript in there
1404
+ #
1405
+ #
1406
+ # 'script' is the JavaScript snippet to run
1407
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1408
+ def wait_for_condition(script,timeout)
1409
+ do_command("waitForCondition", [script,timeout,])
1410
+ end
1411
+
1412
+
1413
+ # Specifies the amount of time that Selenium will wait for actions to complete.
1414
+ #
1415
+ # Actions that require waiting include "open" and the "waitFor*" actions.
1416
+ #
1417
+ # The default timeout is 30 seconds.
1418
+ #
1419
+ # 'timeout' is a timeout in milliseconds, after which the action will return with an error
1420
+ def set_timeout(timeout)
1421
+ do_command("setTimeout", [timeout,])
1422
+ end
1423
+
1424
+
1425
+ # Waits for a new page to load.
1426
+ #
1427
+ # You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
1428
+ # (which are only available in the JS API).
1429
+ # Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
1430
+ # flag when it first notices a page load. Running any other Selenium command after
1431
+ # turns the flag to false. Hence, if you want to wait for a page to load, you must
1432
+ # wait immediately after a Selenium command that caused a page-load.
1433
+ #
1434
+ #
1435
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1436
+ def wait_for_page_to_load(timeout)
1437
+ do_command("waitForPageToLoad", [timeout,])
1438
+ end
1439
+
1440
+
1441
+ # Waits for a new frame to load.
1442
+ #
1443
+ # Selenium constantly keeps track of new pages and frames loading,
1444
+ # and sets a "newPageLoaded" flag when it first notices a page load.
1445
+ #
1446
+ #
1447
+ # See waitForPageToLoad for more information.
1448
+ #
1449
+ # 'frameAddress' is FrameAddress from the server side
1450
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1451
+ def wait_for_frame_to_load(frameAddress,timeout)
1452
+ do_command("waitForFrameToLoad", [frameAddress,timeout,])
1453
+ end
1454
+
1455
+
1456
+ # Return all cookies of the current page under test.
1457
+ #
1458
+ def get_cookie()
1459
+ return get_string("getCookie", [])
1460
+ end
1461
+
1462
+
1463
+ # Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
1464
+ #
1465
+ # 'name' is the name of the cookie
1466
+ def get_cookie_by_name(name)
1467
+ return get_string("getCookieByName", [name,])
1468
+ end
1469
+
1470
+
1471
+ # Returns true if a cookie with the specified name is present, or false otherwise.
1472
+ #
1473
+ # 'name' is the name of the cookie
1474
+ def is_cookie_present(name)
1475
+ return get_boolean("isCookiePresent", [name,])
1476
+ end
1477
+
1478
+
1479
+ # Create a new cookie whose path and domain are same with those of current page
1480
+ # under test, unless you specified a path for this cookie explicitly.
1481
+ #
1482
+ # 'nameValuePair' is name and value of the cookie in a format "name=value"
1483
+ # 'optionsString' is options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'. the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
1484
+ def create_cookie(nameValuePair,optionsString)
1485
+ do_command("createCookie", [nameValuePair,optionsString,])
1486
+ end
1487
+
1488
+
1489
+ # Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
1490
+ # need to delete it using the exact same path and domain that were used to create the cookie.
1491
+ # If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
1492
+ # note that specifying a domain that isn't a subset of the current domain will usually fail.
1493
+ #
1494
+ # Since there's no way to discover at runtime the original path and domain of a given cookie,
1495
+ # we've added an option called 'recurse' to try all sub-domains of the current domain with
1496
+ # all paths that are a subset of the current path. Beware; this option can be slow. In
1497
+ # big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain
1498
+ # name and m is the number of slashes in the path.
1499
+ #
1500
+ # 'name' is the name of the cookie to be deleted
1501
+ # 'optionsString' is options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
1502
+ def delete_cookie(name,optionsString)
1503
+ do_command("deleteCookie", [name,optionsString,])
1504
+ end
1505
+
1506
+
1507
+ # Calls deleteCookie with recurse=true on all cookies visible to the current page.
1508
+ # As noted on the documentation for deleteCookie, recurse=true can be much slower
1509
+ # than simply deleting the cookies using a known domain/path.
1510
+ #
1511
+ def delete_all_visible_cookies()
1512
+ do_command("deleteAllVisibleCookies", [])
1513
+ end
1514
+
1515
+
1516
+ # Sets the threshold for browser-side logging messages; log messages beneath this threshold will be discarded.
1517
+ # Valid logLevel strings are: "debug", "info", "warn", "error" or "off".
1518
+ # To see the browser logs, you need to
1519
+ # either show the log window in GUI mode, or enable browser-side logging in Selenium RC.
1520
+ #
1521
+ # 'logLevel' is one of the following: "debug", "info", "warn", "error" or "off"
1522
+ def set_browser_log_level(logLevel)
1523
+ do_command("setBrowserLogLevel", [logLevel,])
1524
+ end
1525
+
1526
+
1527
+ # Creates a new "script" tag in the body of the current test window, and
1528
+ # adds the specified text into the body of the command. Scripts run in
1529
+ # this way can often be debugged more easily than scripts executed using
1530
+ # Selenium's "getEval" command. Beware that JS exceptions thrown in these script
1531
+ # tags aren't managed by Selenium, so you should probably wrap your script
1532
+ # in try/catch blocks if there is any chance that the script will throw
1533
+ # an exception.
1534
+ #
1535
+ # 'script' is the JavaScript snippet to run
1536
+ def run_script(script)
1537
+ do_command("runScript", [script,])
1538
+ end
1539
+
1540
+
1541
+ # Defines a new function for Selenium to locate elements on the page.
1542
+ # For example,
1543
+ # if you define the strategy "foo", and someone runs click("foo=blah"), we'll
1544
+ # run your function, passing you the string "blah", and click on the element
1545
+ # that your function
1546
+ # returns, or throw an "Element not found" error if your function returns null.
1547
+ #
1548
+ # We'll pass three arguments to your function:
1549
+ # * locator: the string the user passed in
1550
+ # * inWindow: the currently selected window
1551
+ # * inDocument: the currently selected document
1552
+ #
1553
+ #
1554
+ # The function must return null if the element can't be found.
1555
+ #
1556
+ # 'strategyName' is the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation.
1557
+ # 'functionDefinition' is a string defining the body of a function in JavaScript. For example: <tt>return inDocument.getElementById(locator);</tt>
1558
+ def add_location_strategy(strategyName,functionDefinition)
1559
+ do_command("addLocationStrategy", [strategyName,functionDefinition,])
1560
+ end
1561
+
1562
+
1563
+ # Saves the entire contents of the current window canvas to a PNG file.
1564
+ # Currently this only works in Mozilla and when running in chrome mode.
1565
+ # Contrast this with the captureScreenshot command, which captures the
1566
+ # contents of the OS viewport (i.e. whatever is currently being displayed
1567
+ # on the monitor), and is implemented in the RC only. Implementation
1568
+ # mostly borrowed from the Screengrab! Firefox extension. Please see
1569
+ # http://www.screengrab.org for details.
1570
+ #
1571
+ # 'filename' is the path to the file to persist the screenshot as. No filename extension will be appended by default. Directories will not be created if they do not exist, and an exception will be thrown, possibly by native code.
1572
+ def capture_entire_page_screenshot(filename)
1573
+ do_command("captureEntirePageScreenshot", [filename,])
1574
+ end
1575
+
1576
+
1577
+ # Writes a message to the status bar and adds a note to the browser-side
1578
+ # log.
1579
+ #
1580
+ # 'context' is the message to be sent to the browser
1581
+ def set_context(context)
1582
+ do_command("setContext", [context,])
1583
+ end
1584
+
1585
+
1586
+ # Sets a file input (upload) field to the file listed in fileLocator
1587
+ #
1588
+ # 'fieldLocator' is an element locator
1589
+ # 'fileLocator' is a URL pointing to the specified file. Before the file can be set in the input field (fieldLocator), Selenium RC may need to transfer the file to the local machine before attaching the file in a web page form. This is common in selenium grid configurations where the RC server driving the browser is not the same machine that started the test. Supported Browsers: Firefox ("*chrome") only.
1590
+ def attach_file(fieldLocator,fileLocator)
1591
+ do_command("attachFile", [fieldLocator,fileLocator,])
1592
+ end
1593
+
1594
+
1595
+ # Captures a PNG screenshot to the specified file.
1596
+ #
1597
+ # 'filename' is the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"
1598
+ def capture_screenshot(filename)
1599
+ do_command("captureScreenshot", [filename,])
1600
+ end
1601
+
1602
+
1603
+ # Kills the running Selenium Server and all browser sessions. After you run this command, you will no longer be able to send
1604
+ # commands to the server; you can't remotely start the server once it has been stopped. Normally
1605
+ # you should prefer to run the "stop" command, which terminates the current browser session, rather than
1606
+ # shutting down the entire server.
1607
+ #
1608
+ def shut_down_selenium_server()
1609
+ do_command("shutDownSeleniumServer", [])
1610
+ end
1611
+
1612
+
1613
+ # Simulates a user pressing a key (without releasing it yet) by sending a native operating system keystroke.
1614
+ # This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
1615
+ # a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
1616
+ # metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
1617
+ # element, focus on the element first before running this command.
1618
+ #
1619
+ # 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
1620
+ def key_down_native(keycode)
1621
+ do_command("keyDownNative", [keycode,])
1622
+ end
1623
+
1624
+
1625
+ # Simulates a user releasing a key by sending a native operating system keystroke.
1626
+ # This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
1627
+ # a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
1628
+ # metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
1629
+ # element, focus on the element first before running this command.
1630
+ #
1631
+ # 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
1632
+ def key_up_native(keycode)
1633
+ do_command("keyUpNative", [keycode,])
1634
+ end
1635
+
1636
+
1637
+ # Simulates a user pressing and releasing a key by sending a native operating system keystroke.
1638
+ # This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
1639
+ # a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
1640
+ # metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
1641
+ # element, focus on the element first before running this command.
1642
+ #
1643
+ # 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
1644
+ def key_press_native(keycode)
1645
+ do_command("keyPressNative", [keycode,])
1646
+ end
1647
+
1648
+
1649
+ end
1650
+
1651
+ SeleneseInterpreter = SeleniumDriver # for backward compatibility
1652
+
1653
+ end
1654
+
1655
+ class SeleniumCommandError < RuntimeError
1656
+ end
1657
+
1658
+ # Defines a mixin module that you can use to write Selenium tests
1659
+ # without typing "@selenium." in front of every command. Every
1660
+ # call to a missing method will be automatically sent to the @selenium
1661
+ # object.
1662
+ module SeleniumHelper
1663
+
1664
+ # Overrides standard "open" method with @selenium.open
1665
+ def open(addr)
1666
+ @selenium.open(addr)
1667
+ end
1668
+
1669
+ # Overrides standard "type" method with @selenium.type
1670
+ def type(inputLocator, value)
1671
+ @selenium.type(inputLocator, value)
1672
+ end
1673
+
1674
+ # Overrides standard "select" method with @selenium.select
1675
+ def select(inputLocator, optionLocator)
1676
+ @selenium.select(inputLocator, optionLocator)
1677
+ end
1678
+
1679
+ # Passes all calls to missing methods to @selenium
1680
+ def method_missing(method_name, *args)
1681
+ if args.empty?
1682
+ @selenium.send(method_name)
1683
+ else
1684
+ @selenium.send(method_name, *args)
1685
+ end
1686
+ end
1687
+ end