Added a set of Selenium helper classes and methods, to provide automatic login capabilities, to speed up selenium tests.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@482 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-03-23 06:08:36 +00:00
parent 5a878b3e84
commit cd25d7e278
26 changed files with 62 additions and 39 deletions

View file

@ -22,3 +22,7 @@ config.action_mailer.delivery_method = :test
# config.instantiated_fixtures = false
# config.pre_loaded_fixtures = false
SALT = "change-me" unless defined?( SALT ).nil?
config.after_initialize do
require 'test/selenium_helper'
end

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the context 'email'?"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"

View file

@ -1,4 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open '/'
click "xpath=//div[@id='c1'] //div[@id='todo_9'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_9']"

View file

@ -1,5 +1,6 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open '/'
click "xpath=//div[@id='c5'] //div[@id='todo_5'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_5']"
wait_for_not_visible 'c5'

View file

@ -1,4 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'jane', :password => 'sesame'
login :as => 'jane'
open '/'
click_and_wait "xpath=//div[@id='c10'] //div[@id='todo_16'] //input[@class='item-checkbox']"
assert_title "TRACKS::Project: Attend RailsConf"

View file

@ -1,5 +1,6 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open '/'
click "xpath=//div[@id='completed'] //div[@id='todo_3'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='c4'] //div[@id='todo_3']"
assert_not_visible "c4empty-nd"

View file

@ -1,8 +1,8 @@
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "incorrect_password"
click_and_wait "login"
assert_title 'exact:TRACKS::Login'
verify_text_present 'Login unsuccessful'
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "incorrect_password"
click_and_wait "login"
assert_title 'exact:TRACKS::Login'
verify_text_present 'Login unsuccessful'

View file

@ -1,8 +1,7 @@
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "abracadabra"
click_and_wait "login"
assert_title 'exact:TRACKS::List tasks'
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "abracadabra"
click_and_wait "login"
assert_title 'exact:TRACKS::List tasks'

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
click_and_wait "css=#note_1 .link_to_notes"
assert_element_present "note_1"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/notes/"
assert_element_present "note_1"
assert_element_present "note_2"

View file

@ -1,6 +1,6 @@
setup :fixtures => :all
next_available_todo_id = 18
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
include_partial 'project_detail/add_deferred_todo'
open "/projects/Build_a_working_time_machine"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
click "edit_icon_todo_15"
wait_for_element_present "show_from_todo_15"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open '/projects/Build_a_working_time_machine'
assert_checked 'project_state_active', 'ignored'
assert_attribute 'css=#project_status .active span', 'class', 'active_state'

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Make_more_money_than_Billy_Gates"
include_partial 'project_detail/add_deferred_todo'
assert_not_visible "tickler-empty-nd"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
click "edit_icon_todo_5"
wait_for_element_present "show_from_todo_5"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
include_partial 'project_detail/add_deferred_todo'
click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects/Build_a_working_time_machine"
click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']"
wait_for_visible "tickler-empty-nd"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the project 'Make more money than Billy Gates'?"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/todos/tag/foo"
wait_for_element_present "xpath=//div[@id='c1'] //h2"
wait_for_text 'badge_count', '2'

View file

@ -1,4 +1,4 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
login :as => 'admin'
open "/tickler/"
assert_element_present "todo_15"

View file

@ -0,0 +1,18 @@
class SeleniumHelperController < ActionController::Base
def login
if params[:as]
session['user_id'] = User.find_by_login(params[:as].to_s)
end
render :text => "Logged in as #{params[:as]}"
end
end
ActionController::Routing::Routes.add_route '/selenium_helper/login', :controller => 'selenium_helper', :action => 'login'
module SeleniumOnRails::TestBuilderActions
def login options = {}
options = {options => nil} unless options.is_a? Hash
opts = {:controller => 'selenium_helper', :action => 'login'}.merge(options)
open opts
end
end

View file

@ -111,6 +111,4 @@ class ActionController::IntegrationTest
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
end
end