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`.

### Methods

add_selection alt_key_down alt_key_up answer_on_next_prompt brake check choose_cancel_on_next_confirmation click click_at close control_key_down control_key_up create_cookie delete_cookie double_click double_click_at drag_and_drop drag_and_drop_to_object echo fire_event go_back highlight include_partial key_down key_press key_up meta_key_down meta_key_up mouse_down mouse_down_at mouse_move mouse_move_at mouse_out mouse_over mouse_up mouse_up_at open open_window pause refresh remove_all_selections remove_selection select select_frame select_window set_context set_cursor_position set_mouse_speed set_timeout setup shift_key_down shift_key_up store submit type type_keys uncheck wait_for_condition wait_for_page_to_load wait_for_popup window_focus window_maximize

### Public Instance methods

add_selection(locator, option_locator)

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.

[Source]

         # 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

alt_key_down()

Simulates the user pressing the alt key and hold it down until do_alt_up() is called or a new page is loaded.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 221
    221:   def alt_key_down
    222:     command 'altKeyDown'
    223:   end

alt_key_up()

Simulates the user releasing the alt key.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 226
    226:   def alt_key_up
    227:     command 'altKeyUp'
    228:   end

answer_on_next_prompt(answer)

Instructs Selenium to return the specified answer string in response to the next JavaScript prompt (`window.prompt()`).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 199
    199:   def answer_on_next_prompt answer
    200:     command 'answerOnNextPrompt', answer
    201:   end

brake()

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()`

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 236
    236:   def brake
    237:     command 'break'
    238:   end

check(locator)

Check a toggle-button (checkbox/radio).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 108
    108:   def check locator
    109:     command 'check', locator
    110:   end

choose_cancel_on_next_confirmation()

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.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 193
    193:   def choose_cancel_on_next_confirmation
    194:     command 'chooseCancelOnNextConfirmation'
    195:   end

click(locator)

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`.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 47
    47:   def click locator
    48:     command 'click', locator
    49:   end

click_at(locator, coord_string)

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.

[Source]

        # 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

close()

Simulates the user clicking the "close" button in the titlebar of a popup window or tab.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 215
    215:   def close
    216:     command 'close'
    217:   end

control_key_down()

Simulates the user pressing the alt key and hold it down until do_control_up() is called or a new page is loaded.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 242
    242:   def control_key_down
    243:     command 'controlKeyDown'
    244:   end

control_key_up()

Simulates the user releasing the control key.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 247
    247:   def control_key_up
    248:     command 'controlKeyUp'
    249:   end

create_cookie(name_value_pair, options_string)

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:

- `name_value_pair` - name and value of the cookie in a format "name=value"
- `options_string` - options for the cookie. Currently supported options include ‘path’ and ‘max_age’. The options_string‘s format is `"path=/path/, max_age=60"`. The order of options are irrelevant, the unit of the value of ‘max_age’ is second.

[Source]

         # 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_cookie(name, path)

Delete a named cookie with specified path.

[Source]

         # 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_click(locator)

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`.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 271
    271:   def double_click locator
    272:     command 'doubleClick', locator
    273:   end

double_click_at(locator, coord_string)

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`.

[Source]

         # 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

drag_and_drop(locator, movements_string)

Drags an element a certain distance and then drops it.

[Source]

         # 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

drag_and_drop_to_object(locator_of_object_to_be_dragged, locator_of_drag_destination_object)

Drags an element and drops it on another element.

[Source]

         # 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

echo(message)

Prints the specified message into the third table cell in your Selenese tables. Useful for debugging.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 294
    294:   def echo message
    295:     command 'echo', message
    296:   end

fire_event(locator, event_name)

Explicitly simulate an event (e.g. `"focus"`, `"blur"`), to trigger the corresponding `"on_event_"` handler.

[Source]

        # 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

go_back()

Simulates the user clicking the "back" button on their browser.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 204
    204:   def go_back
    205:     command 'goBack'
    206:   end

highlight(locator)

Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 300
    300:   def highlight locator
    301:     command 'highlight', locator
    302:   end

include_partial(path, local_assigns = {})

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

[Source]

        # 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

key_down(locator, keycode)

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.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 75
    75:   def key_down locator, keycode
    76:     command 'keyDown', locator, keycode
    77:   end

key_press(locator, keycode)

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.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 67
    67:   def key_press locator, keycode
    68:     command 'keyPress', locator, keycode
    69:   end

key_up(locator, keycode)

Simulates a user releasing a key.

`keycode` is the numeric keycode of the key to be released, normally the ASCII value of that key.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 83
    83:   def key_up locator, keycode
    84:     command 'keyUp', locator, keycode
    85:   end

meta_key_down()

Press the meta key and hold it down until `doMetaUp()` is called or a new page is loaded.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 306
    306:   def meta_key_down
    307:     command 'metaKeyDown'
    308:   end

meta_key_up()

Release the meta key.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 311
    311:   def meta_key_up
    312:     command 'metaKeyUp'
    313:   end

mouse_down(locator)

Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 94
    94:   def mouse_down locator
    95:     command 'mouseDown', locator
    96:   end

mouse_down_at(locator, coord_string)

Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

[Source]

         # 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

mouse_move(locator)

Simulates a user moving the mouse.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 322
    322:   def mouse_move locator
    323:     command 'mouseMove', locator
    324:   end

mouse_move_at(locator, coord_string)

Simulates a user moving the mouse relative to the specified element.

[Source]

         # 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

mouse_out(locator)

Simulates the user moving the mouse off the specified element.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 332
    332:   def mouse_out locator
    333:     command 'mouseOut', locator
    334:   end

mouse_over(locator)

Simulates a user hovering a mouse over the specified element.

[Source]

        # File lib/selenium_on_rails/test_builder_actions.rb, line 88
    88:   def mouse_over locator
    89:     command 'mouseOver', locator
    90:   end

mouse_up(locator)

Simulates the user releasing the mouse button on the specified element.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 337
    337:   def mouse_up locator
    338:     command 'mouseUp', locator
    339:   end

mouse_up_at(locator, coord_string)

Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

[Source]

         # 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

open(url)

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).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 172
    172:   def open url
    173:     command 'open', url_arg(url)
    174:   end

open_window(url, window_id)

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")`.

[Source]

         # 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

pause(wait_time)

Wait for the specified amount of time (in milliseconds).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 360
    360:   def pause wait_time
    361:     command 'pause', wait_time
    362:   end

refresh()

Simulates the user clicking the "Refresh" button on their browser.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 209
    209:   def refresh
    210:     command 'refresh'
    211:   end

remove_all_selections(locator)

Unselects all of the selected options in a multi-select element.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 365
    365:   def remove_all_selections locator
    366:     command 'removeAllSelections', locator
    367:   end

remove_selection(locator, option_locator)

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.

[Source]

         # 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(locator, option_locator)

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=labelPattern matches options based on their labels, i.e. the visible text. (This is the default.)

        label=regexp:^[Oo]ther

- value=valuePattern matches options based on their values.

        value=other

- id=id matches options based on their ids.

        id=option1

- index=index matches an option based on its index (offset from zero).

        index=2

If no option locator prefix is provided, the default behaviour is to match on label.

[Source]

         # 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

select_frame(locator)

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`

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 375
    375:   def select_frame locator
    376:     command 'selectFrame', locator
    377:   end

select_window(window_id)

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.

[Source]

         # 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

set_context(context, log_level_threshold = nil)

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`.

[Source]

         # 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

set_cursor_position(locator, position)

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.

[Source]

         # 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

set_mouse_speed(pixels)

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.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 393
    393:   def set_mouse_speed pixels
    394:     command 'setMouseSpeed', pixels
    395:   end

set_timeout(timeout)

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.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 480
    480:   def set_timeout timeout
    481:     command 'setTimeout', timeout
    482:   end

setup(options = {})

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]

[Source]

        # 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

shift_key_down()

Press the shift key and hold it down until `doShiftUp()` is called or a new page is loaded.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 399
    399:   def shift_key_down
    400:     command 'shiftKeyDown'
    401:   end

shift_key_up()

Release the shift key.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 404
    404:   def shift_key_up
    405:     command 'shiftKeyUp'
    406:   end

store(expression, variable_name)

This command is a synonym for `store_expression`.

[Source]

         # 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

submit(locator)

Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 162
    162:   def submit locator
    163:     command 'submit', locator
    164:   end

type(locator, value)

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.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 103
    103:   def type locator, value
    104:     command 'type', locator, value
    105:   end

type_keys(locator, value)

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.

[Source]

         # 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(locator)

Uncheck a toggle-button (checkbox/radio).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 113
    113:   def uncheck locator
    114:     command 'uncheck', locator
    115:   end

wait_for_condition(script, timeout)

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.

[Source]

         # 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

wait_for_page_to_load(timeout)

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.

[Source]

         # 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

wait_for_popup(window_id, timeout)

Waits for a popup window to appear and load up.

The `timeout` is specified in milliseconds.

[Source]

         # 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

window_focus(window_name)

Gives focus to a window.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 433
    433:   def window_focus window_name
    434:     command 'windowFocus', window_name
    435:   end

window_maximize(window_name)

Resize window to take up the entire screen.

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 438
    438:   def window_maximize window_name
    439:     command 'windowMaximize', window_name
    440:   end

[Validate]