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 139 139: def add_selection locator, option_locator 140: command 'addSelection', locator, option_locator 141: 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 190 190: def answer_on_next_prompt answer 191: command 'answerOnNextPrompt', answer 192: end
Check a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 99 99: def check locator 100: command 'check', locator 101: 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 184 184: def choose_cancel_on_next_confirmation 185: command 'chooseCancelOnNextConfirmation' 186: 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 44 44: def click locator 45: command 'click', locator 46: end
Simulates the user clicking the "close" button in the titlebar of a popup window or tab.
# File lib/selenium_on_rails/test_builder_actions.rb, line 206 206: def close 207: command 'close' 208: 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 50 50: def fire_event locator, event_name 51: command 'fireEvent', locator, event_name 52: end
Simulates the user clicking the "back" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 195 195: def go_back 196: command 'goBack' 197: 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 36 36: def include_partial path, local_assigns = {} 37: partial = @view.render :partial => path, :locals => local_assigns 38: @output << partial 39: 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 66 66: def key_down locator, keycode 67: command 'keyDown', locator, keycode 68: 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 58 58: def key_press locator, keycode 59: command 'keyPress', locator, keycode 60: 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 74 74: def key_up locator, keycode 75: command 'keyUp', locator, keycode 76: 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 85 85: def mouse_down locator 86: command 'mouseDown', locator 87: end
Simulates a user hovering a mouse over the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 79 79: def mouse_over locator 80: command 'mouseOver', locator 81: 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 163 163: def open url 164: command 'open', url_arg(url) 165: end
Simulates the user clicking the "Refresh" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 200 200: def refresh 201: command 'refresh' 202: 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 147 147: def remove_selection locator, option_locator 148: command 'removeSelection', locator, option_locator 149: 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 131 131: def select locator, option_locator 132: command 'select', locator, option_locator 133: 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 169 169: def select_window window_id 170: command 'selectWindow', window_id||'null' 171: 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 216 216: def set_context context, log_level_threshold = nil 217: if log_level_threshold 218: command 'setContext', context, log_level_threshold.to_s 219: else 220: command 'setContext', context 221: end 222: 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 248 248: def set_timeout timeout 249: command 'setTimeout', timeout 250: 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 and :fixtures
setup setup :keep_session setup :fixtures => :all setup :keep_session, :fixtures => [:foo, :bar]
# File lib/selenium_on_rails/test_builder_actions.rb, line 13 13: def setup options = {} 14: options = {options => nil} unless options.is_a? Hash 15: 16: opts = {:controller => 'selenium', :action => 'setup'} 17: opts[:keep_session] = true if options.has_key? :keep_session 18: 19: if (f = options[:fixtures]) 20: f = [f] unless f.is_a? Array 21: opts[:fixtures] = f.join ',' 22: end 23: 24: open opts 25: end
Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms.
# File lib/selenium_on_rails/test_builder_actions.rb, line 153 153: def submit locator 154: command 'submit', locator 155: 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 94 94: def type locator, value 95: command 'type', locator, value 96: end
Uncheck a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 104 104: def uncheck locator 105: command 'uncheck', locator 106: 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 235 235: def wait_for_condition script, timeout 236: command 'waitForCondition', script, timeout 237: 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 265 265: def wait_for_page_to_load timeout 266: command 'waitForPageToLoad', timeout 267: end