| 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 142
142: def add_selection locator, option_locator
143: command 'addSelection', locator, option_locator
144: 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 193
193: def answer_on_next_prompt answer
194: command 'answerOnNextPrompt', answer
195: end
Check a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 102
102: def check locator
103: command 'check', locator
104: 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 187
187: def choose_cancel_on_next_confirmation
188: command 'chooseCancelOnNextConfirmation'
189: 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
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 209
209: def close
210: command 'close'
211: 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 53
53: def fire_event locator, event_name
54: command 'fireEvent', locator, event_name
55: end
Simulates the user clicking the "back" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 198
198: def go_back
199: command 'goBack'
200: 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 69
69: def key_down locator, keycode
70: command 'keyDown', locator, keycode
71: 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 61
61: def key_press locator, keycode
62: command 'keyPress', locator, keycode
63: 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 77
77: def key_up locator, keycode
78: command 'keyUp', locator, keycode
79: 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 88
88: def mouse_down locator
89: command 'mouseDown', locator
90: end
Simulates a user hovering a mouse over the specified element.
# File lib/selenium_on_rails/test_builder_actions.rb, line 82
82: def mouse_over locator
83: command 'mouseOver', locator
84: 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 166
166: def open url
167: command 'open', url_arg(url)
168: end
Simulates the user clicking the "Refresh" button on their browser.
# File lib/selenium_on_rails/test_builder_actions.rb, line 203
203: def refresh
204: command 'refresh'
205: 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 150
150: def remove_selection locator, option_locator
151: command 'removeSelection', locator, option_locator
152: 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 134
134: def select locator, option_locator
135: command 'select', locator, option_locator
136: 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 172
172: def select_window window_id
173: command 'selectWindow', window_id||'null'
174: 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 219
219: def set_context context, log_level_threshold = nil
220: if log_level_threshold
221: command 'setContext', context, log_level_threshold.to_s
222: else
223: command 'setContext', context
224: end
225: 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 251
251: def set_timeout timeout
252: command 'setTimeout', timeout
253: 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
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 156
156: def submit locator
157: command 'submit', locator
158: 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 97
97: def type locator, value
98: command 'type', locator, value
99: end
Uncheck a toggle-button (checkbox/radio).
# File lib/selenium_on_rails/test_builder_actions.rb, line 107
107: def uncheck locator
108: command 'uncheck', locator
109: 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 238
238: def wait_for_condition script, timeout
239: command 'waitForCondition', script, timeout
240: 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 268
268: def wait_for_page_to_load timeout
269: command 'waitForPageToLoad', timeout
270: end