Module | SeleniumOnRails::TestBuilderActions |
In: |
lib/selenium_on_rails/test_builder_actions.rb
|
The actions available for SeleniumOnRails::TestBuilder tests.
For each action foo there‘s also an action foo_and_wait.
Add a selection to the set of selected options in a multi-select element using an option locator.
See the select command for more information about option locators.
# File lib/selenium_on_rails/test_builder_actions.rb, line 148 148: def add_selection locator, option_locator 149: command 'addSelection', locator, option_locator 150: end
Simulates the user pressing the alt key and hold it down until do_alt_up() is called or a new page is loaded.
# File lib/selenium_on_rails/test_builder_actions.rb, line 221 221: def alt_key_down 222: command 'altKeyDown' 223: end
Simulates the user releasing the alt key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 226 226: def alt_key_up 227: command 'altKeyUp' 228: end
Instructs Selenium to return the specified answer string in response to the next JavaScript prompt (window.prompt()).
# File lib/selenium_on_rails/test_builder_actions.rb, line 199 199: def answer_on_next_prompt answer 200: command 'answerOnNextPrompt', answer 201: end
Halt the currently running test, and wait for the user to press the Continue button. This command is useful for debugging, but be careful when using it, because it will force automated tests to hang until a user intervenes manually.
NOTE: break is a reserved word in Ruby, so we have to simulate Selenium core‘s break() with brake()
# File lib/selenium_on_rails/test_builder_actions.rb, line 236 236: def brake 237: command 'break' 238: end
Check a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 108 108: def check locator 109: command 'check', locator 110: end
By default, Selenium‘s overridden window.confirm() function will return true, as if the user had manually clicked OK. After running this command, the next call to confirm() will return false, as if the user had clicked Cancel.
# File lib/selenium_on_rails/test_builder_actions.rb, line 193 193: def choose_cancel_on_next_confirmation 194: command 'chooseCancelOnNextConfirmation' 195: end
Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call wait_for_page_to_load.
# File lib/selenium_on_rails/test_builder_actions.rb, line 47 47: def click locator 48: command 'click', locator 49: end
Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call wait_for_page_to_load.
# File lib/selenium_on_rails/test_builder_actions.rb, line 53 53: def click_at locator, coord_string 54: command 'clickAt', locator, coord_string 55: end
Simulates the user pressing the alt key and hold it down until do_control_up() is called or a new page is loaded.
# File lib/selenium_on_rails/test_builder_actions.rb, line 242 242: def control_key_down 243: command 'controlKeyDown' 244: end
Simulates the user releasing the control key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 247 247: def control_key_up 248: command 'controlKeyUp' 249: end
Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.
Arguments:
# File lib/selenium_on_rails/test_builder_actions.rb, line 260 260: def create_cookie name_value_pair, options_string 261: command 'createCookie', name_value_pair, options_string 262: end
Delete a named cookie with specified path.
# File lib/selenium_on_rails/test_builder_actions.rb, line 265 265: def delete_cookie name, path 266: command 'deleteCookie', name, path 267: end
Double clicks on a link, button, checkbox or radio button. If the double click action causes a new page to load (like a link usually does), call wait_for_page_to_load.
# File lib/selenium_on_rails/test_builder_actions.rb, line 271 271: def double_click locator 272: command 'doubleClick', locator 273: end
Doubleclicks on a link, button, checkbox or radio button. If the action causes a new page to load (like a link usually does), call wait_for_page_to_load.
# File lib/selenium_on_rails/test_builder_actions.rb, line 277 277: def double_click_at locator, coord_string 278: command 'doubleClickAt', locator, coord_string 279: end
Drags an element a certain distance and then drops it.
# File lib/selenium_on_rails/test_builder_actions.rb, line 282 282: def drag_and_drop locator, movements_string 283: command 'dragAndDrop', locator, movements_string 284: end
Drags an element and drops it on another element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 287 287: def drag_and_drop_to_object locator_of_object_to_be_dragged, locator_of_drag_destination_object 288: command 'dragAndDropToObject', locator_of_object_to_be_dragged, locator_of_drag_destination_object 289: end
Explicitly simulate an event (e.g. "focus", "blur"), to trigger the corresponding "on_event_" handler.
# File lib/selenium_on_rails/test_builder_actions.rb, line 59 59: def fire_event locator, event_name 60: command 'fireEvent', locator, event_name 61: end
Simulates the user clicking the "back" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 204 204: def go_back 205: command 'goBack' 206: end
Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
# File lib/selenium_on_rails/test_builder_actions.rb, line 300 300: def highlight locator 301: command 'highlight', locator 302: end
Includes a partial. The path is relative to the Selenium tests root. The starting _ and the file extension don‘t have to be specified.
#include test/selenium/_partial.* include_partial 'partial' #include test/selenium/suite/_partial.* include_partial 'suite/partial' #include test/selenium/suite/_partial.* and provide local assigns include_partial 'suite/partial', :foo => bar
# File lib/selenium_on_rails/test_builder_actions.rb, line 39 39: def include_partial path, local_assigns = {} 40: partial = @view.render :partial => path, :locals => local_assigns 41: @output << partial 42: end
Simulates a user pressing a key (without releasing it yet).
keycode is the numeric keycode of the key to be pressed, normally the ASCII value of that key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 75 75: def key_down locator, keycode 76: command 'keyDown', locator, keycode 77: end
Simulates a user pressing and releasing a key.
keycode is the numeric keycode of the key to be pressed, normally the ASCII value of that key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 67 67: def key_press locator, keycode 68: command 'keyPress', locator, keycode 69: end
Simulates a user releasing a key.
keycode is the numeric keycode of the key to be released, normally the ASCII value of that key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 83 83: def key_up locator, keycode 84: command 'keyUp', locator, keycode 85: end
Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
# File lib/selenium_on_rails/test_builder_actions.rb, line 306 306: def meta_key_down 307: command 'metaKeyDown' 308: end
Release the meta key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 311 311: def meta_key_up 312: command 'metaKeyUp' 313: end
Simulates a user pressing the mouse button (without releasing it yet) on the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 94 94: def mouse_down locator 95: command 'mouseDown', locator 96: end
Simulates a user pressing the mouse button (without releasing it yet) on the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 317 317: def mouse_down_at locator, coord_string 318: command 'mouseDownAt', locator, coord_string 319: end
Simulates a user moving the mouse.
# File lib/selenium_on_rails/test_builder_actions.rb, line 322 322: def mouse_move locator 323: command 'mouseMove', locator 324: end
Simulates a user moving the mouse relative to the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 327 327: def mouse_move_at locator, coord_string 328: command 'mouseMoveAt', locator, coord_string 329: end
Simulates the user moving the mouse off the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 332 332: def mouse_out locator 333: command 'mouseOut', locator 334: end
Simulates a user hovering a mouse over the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 88 88: def mouse_over locator 89: command 'mouseOver', locator 90: end
Simulates the user releasing the mouse button on the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 337 337: def mouse_up locator 338: command 'mouseUp', locator 339: end
Simulates a user pressing the mouse button (without releasing it yet) on the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 343 343: def mouse_up_at locator, coord_string 344: command 'mouseUpAt', locator, coord_string 345: end
Opens an URL in the test frame. This accepts both relative and absolute URLs. The open command waits for the page to load before proceeding, i.e. you don‘t have to call wait_for_page_to_load.
Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy).
# File lib/selenium_on_rails/test_builder_actions.rb, line 172 172: def open url 173: command 'open', url_arg(url) 174: end
Opens a popup window (if a window with that ID isn‘t already open). After opening the window, you‘ll need to select it using the select_window command.
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). In those cases, you can force Selenium to notice the open window‘s name by using the Selenium openWindow command, using an empty (blank) url, like this: open_window("", "myFunnyWindow").
# File lib/selenium_on_rails/test_builder_actions.rb, line 355 355: def open_window url, window_id 356: command 'openWindow', url, window_id 357: end
Wait for the specified amount of time (in milliseconds).
# File lib/selenium_on_rails/test_builder_actions.rb, line 360 360: def pause wait_time 361: command 'pause', wait_time 362: end
Simulates the user clicking the "Refresh" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 209 209: def refresh 210: command 'refresh' 211: end
Remove a selection from the set of selected options in a multi-select element using an option locator.
See the select command for more information about option locators.
# File lib/selenium_on_rails/test_builder_actions.rb, line 156 156: def remove_selection locator, option_locator 157: command 'removeSelection', locator, option_locator 158: end
Select an option from a drop-down using an option locator.
Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
label=regexp:^[Oo]ther
value=other
id=option1
index=2
If no option locator prefix is provided, the default behaviour is to match on label.
# File lib/selenium_on_rails/test_builder_actions.rb, line 140 140: def select locator, option_locator 141: command 'select', locator, option_locator 142: end
Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top".
You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames
# File lib/selenium_on_rails/test_builder_actions.rb, line 375 375: def select_frame locator 376: command 'selectFrame', locator 377: end
Selects a popup window; once a popup window has been selected, all commands go to that window. To select the main window again, use nil as the target.
# File lib/selenium_on_rails/test_builder_actions.rb, line 178 178: def select_window window_id 179: command 'selectWindow', window_id||'null' 180: end
Writes a message to the status bar and adds a note to the browser-side log.
context is the message sent to the browser.
log_level_threshold can be nil, :debug, :info, :warn or :error.
# File lib/selenium_on_rails/test_builder_actions.rb, line 448 448: def set_context context, log_level_threshold = nil 449: if log_level_threshold 450: command 'setContext', context, log_level_threshold.to_s 451: else 452: command 'setContext', context 453: end 454: end
Moves the text cursor to the specified position in the given input element or textarea. This method will fail if the specified element isn‘t an input element or textarea.
# File lib/selenium_on_rails/test_builder_actions.rb, line 381 381: def set_cursor_position locator, position 382: command 'setCursorPosition', locator, position 383: end
Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10). Setting this value to 0 means that we‘ll send a "mousemove" event to every single pixel in between the start location and the end location; that can be very slow, and may cause some browsers to force the JavaScript to timeout.
If the mouse speed is greater than the distance between the two dragged objects, we‘ll just send one "mousemove" at the start location and then one final one at the end location.
# File lib/selenium_on_rails/test_builder_actions.rb, line 393 393: def set_mouse_speed pixels 394: command 'setMouseSpeed', pixels 395: end
Specifies the amount of time that Selenium will wait for actions to complete.
Actions that require waiting include open and the wait_for* actions.
The default timeout is 30 seconds.
timeout is specified in milliseconds.
# File lib/selenium_on_rails/test_builder_actions.rb, line 480 480: def set_timeout timeout 481: command 'setTimeout', timeout 482: end
Tell Selenium on Rails to clear the session and load any fixtures. DO NOT CALL THIS AGAINST NON-TEST DATABASES. The supported options are :keep_session, :fixtures and :clear_tables
setup setup :keep_session setup :fixtures => :all setup :keep_session, :fixtures => [:foo, :bar] setup :clear_tables => [:foo, :bar]
# File lib/selenium_on_rails/test_builder_actions.rb, line 14 14: def setup options = {} 15: options = {options => nil} unless options.is_a? Hash 16: 17: opts = {:controller => 'selenium', :action => 'setup'} 18: opts[:keep_session] = true if options.has_key? :keep_session 19: 20: [:fixtures, :clear_tables].each do |key| 21: if (f = options[key]) 22: f = [f] unless f.is_a? Array 23: opts[key] = f.join ',' 24: end 25: end 26: 27: open opts 28: end
Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
# File lib/selenium_on_rails/test_builder_actions.rb, line 399 399: def shift_key_down 400: command 'shiftKeyDown' 401: end
Release the shift key.
# File lib/selenium_on_rails/test_builder_actions.rb, line 404 404: def shift_key_up 405: command 'shiftKeyUp' 406: end
This command is a synonym for store_expression.
# File lib/selenium_on_rails/test_builder_actions.rb, line 409 409: def store expression, variable_name 410: command 'store', expression, variable_name 411: end
Sets the value of an input field, as though you typed it in.
Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.
# File lib/selenium_on_rails/test_builder_actions.rb, line 103 103: def type locator, value 104: command 'type', locator, value 105: end
Simulates keystroke events on the specified element, as though you typed the value key-by-key.
This is a convenience method for calling key_down, key_up, key_press for every character in the specified string; this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
Unlike the simple "type" command, which forces the specified value into the page directly, this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. For example, if you use "type_keys" on a form element, you may or may not see the results of what you typed in the field.
In some cases, you may need to use the simple "type" command to set the value of the field and then the "type_keys" command to send the keystroke events corresponding to what you just typed.
# File lib/selenium_on_rails/test_builder_actions.rb, line 428 428: def type_keys locator, value 429: command 'typeKeys', locator, value 430: end
Uncheck a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 113 113: def uncheck locator 114: command 'uncheck', locator 115: end
Runs the specified JavaScript snippet repeatedly until it evaluates to true. The snippet may have multiple lines, but only the result of the last line will be considered.
Note that, by default, the snippet will be run in the runner‘s test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there.
timeout is specified in milliseconds.
# File lib/selenium_on_rails/test_builder_actions.rb, line 467 467: def wait_for_condition script, timeout 468: command 'waitForCondition', script, timeout 469: end
Waits for a new page to load.
You can use this command instead of the and_wait suffixes, click_and_wait, select_and_wait, type_and_wait etc. (which are only available in the JS API).
Selenium constantly keeps track of new pages loading, and sets a newPageLoaded flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load.
timeout is specified in milliseconds.
# File lib/selenium_on_rails/test_builder_actions.rb, line 497 497: def wait_for_page_to_load timeout 498: command 'waitForPageToLoad', timeout 499: end
Waits for a popup window to appear and load up.
The timeout is specified in milliseconds.
# File lib/selenium_on_rails/test_builder_actions.rb, line 185 185: def wait_for_popup window_id, timeout 186: command 'waitForPopUp', window_id||'null', timeout 187: end
Gives focus to a window.
# File lib/selenium_on_rails/test_builder_actions.rb, line 433 433: def window_focus window_name 434: command 'windowFocus', window_name 435: end