Introduced user-extensions.js file for selenium to clean up a few selenium tests. This is a powerful concept and could be used to really help the clarity and maintainability of the selenium tests in the future.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@585 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-09-10 05:34:21 +00:00
parent c6b3e1c0b8
commit 5cb42946c1
4 changed files with 54 additions and 4 deletions

View file

@ -1,9 +1,9 @@
setup :fixtures => :users, :clear_tables => [:projects, :contexts, :todos]
login :as => 'admin'
open "/"
store_eval "this.browserbot.getCurrentWindow().$$('.context').length", 'initial_context_count'
store_context_count 'initial_context_count'
type "todo_description", "a new action"
type "todo_context_name", "Brand new context"
click "css=#todo-form-new-action .submit_box button"
store_eval "${initial_context_count} + 1", 'expected_context_count'
wait_for_eval "this.browserbot.getCurrentWindow().$$('.context').length", "${expected_context_count}"
wait_for_context_count "${expected_context_count}"

View file

@ -1,9 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
store_eval "this.browserbot.getCurrentWindow().$$('.context').length", 'initial_context_count'
store_context_count 'initial_context_count'
type "todo_description", "a new action"
type "todo_context_name", "Brand new context"
click "css=#todo-form-new-action .submit_box button"
store_eval "${initial_context_count} + 1", 'expected_context_count'
wait_for_eval "this.browserbot.getCurrentWindow().$$('.context').length", "${expected_context_count}"
wait_for_context_count "${expected_context_count}"

View file

@ -16,3 +16,29 @@ module SeleniumOnRails::TestBuilderActions
open opts
end
end
# The accessors available for SeleniumOnRails::TestBuilder tests.
#
# For each +store_foo+ there's +assert_foo+, +assert_not_foo+, +verify_foo+,
# +verify_not_foo+, +wait_for_foo+, +wait_for_not_foo+.
module SeleniumOnRails::TestBuilderAccessors
# Has an alert occurred?
#
# Related Assertions, automatically generated:
# * +assert_context_count+
# * +assert_not_context_count+
# * +verify_context_count+
# * +verify_not_context_count+
# * +wait_for_context_count+
# * +wait_for_not_context_count+
def store_context_count variable_name
command 'storeContextCount', variable_name
end
each_assertion 'store_context_count' do |assertion_method, command_name|
define_method assertion_method do |expected_count|
command command_name, expected_count
end
end
end

View file

@ -0,0 +1,24 @@
/*
* By default, Selenium looks for a file called "user-extensions.js", and loads and javascript
* code found in that file. This file is a sample of what that file could look like.
*
* user-extensions.js provides a convenient location for adding extensions to Selenium, like
* new actions, checks and locator-strategies.
* By default, this file does not exist. Users can create this file and place their extension code
* in this common location, removing the need to modify the Selenium sources, and hopefully assisting
* with the upgrade process.
*
* You can find contributed extensions at http://wiki.openqa.org/display/SEL/Contributed%20User-Extensions
*/
// All get* methods on the Selenium prototype result in
// store, assert, assertNot, verify, verifyNot, waitFor, and waitForNot commands.
// E.g. add a getTextLength method that returns the length of the text
// of a specified element.
// Will result in support for storeContextCount, assertContextCount, etc.
Selenium.prototype.getContextCount = function() {
return this.browserbot.getCurrentWindow().$$('.context').length;
};