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 answer_on_next_prompt check choose_cancel_on_next_confirmation click close fire_event go_back include_partial key_down key_press key_up mouse_down mouse_over open refresh remove_selection select select_window set_context set_timeout setup submit type uncheck wait_for_condition wait_for_page_to_load wait_for_popup

### 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 142
    142:   def add_selection locator, option_locator
    143:     command 'addSelection', locator, option_locator
    144:   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 193
    193:   def answer_on_next_prompt answer
    194:     command 'answerOnNextPrompt', answer
    195:   end

check(locator)

Check a toggle-button (checkbox/radio).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 102
    102:   def check locator
    103:     command 'check', locator
    104:   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 187
    187:   def choose_cancel_on_next_confirmation
    188:     command 'chooseCancelOnNextConfirmation'
    189:   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

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 209
    209:   def close
    210:     command 'close'
    211:   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 53
    53:   def fire_event locator, event_name
    54:     command 'fireEvent', locator, event_name
    55:   end

go_back()

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

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 198
    198:   def go_back
    199:     command 'goBack'
    200:   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 69
    69:   def key_down locator, keycode
    70:     command 'keyDown', locator, keycode
    71:   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 61
    61:   def key_press locator, keycode
    62:     command 'keyPress', locator, keycode
    63:   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 77
    77:   def key_up locator, keycode
    78:     command 'keyUp', locator, keycode
    79:   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 88
    88:   def mouse_down locator
    89:     command 'mouseDown', locator
    90:   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 82
    82:   def mouse_over locator
    83:     command 'mouseOver', locator
    84:   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 166
    166:   def open url
    167:     command 'open', url_arg(url)
    168:   end

refresh()

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

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 203
    203:   def refresh
    204:     command 'refresh'
    205:   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 150
    150:   def remove_selection locator, option_locator
    151:     command 'removeSelection', locator, option_locator
    152:   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 134
    134:   def select locator, option_locator
    135:     command 'select', locator, option_locator
    136:   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 172
    172:   def select_window window_id
    173:     command 'selectWindow', window_id||'null'
    174:   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 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

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 251
    251:   def set_timeout timeout
    252:     command 'setTimeout', timeout
    253:   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

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 156
    156:   def submit locator
    157:     command 'submit', locator
    158:   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 97
    97:   def type locator, value
    98:     command 'type', locator, value
    99:   end

uncheck(locator)

Uncheck a toggle-button (checkbox/radio).

[Source]

         # File lib/selenium_on_rails/test_builder_actions.rb, line 107
    107:   def uncheck locator
    108:     command 'uncheck', locator
    109:   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 238
    238:   def wait_for_condition script, timeout
    239:     command 'waitForCondition', script, timeout
    240:   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 268
    268:   def wait_for_page_to_load timeout
    269:     command 'waitForPageToLoad', timeout
    270:   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 179
    179:   def wait_for_popup window_id, timeout
    180:     command 'waitForPopUp', window_id||'null', timeout
    181:   end

[Validate]