public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
Started moving selenium on rails tests over to RSpec stories. See the 
updated README_DEVELOPERS for info on running the new tests.
lukemelia (author)
Wed Jun 18 21:14:04 -0700 2008
sr (committer)
Mon Jun 23 01:02:17 -0700 2008
commit  d7f05fbfd49592f71743dc51696c985bf8e49847
tree    ea693febc7a7b91f9461e205211fef8849b2c098
parent  58974ec1389e18bfd8a7bf5c24cdfca60ef87134
...
10
11
12
13
 
14
15
16
17
18
 
 
19
20
21
...
10
11
12
 
13
14
15
16
17
 
18
19
20
21
22
0
@@ -10,12 +10,13 @@
0
           :title =>"Delete this note",
0
           :class=>"delete_item",
0
           :id => "delete_note_"+note.id.to_s),
0
- :update => dom_id(note),
0
+ {:update => dom_id(note),
0
         :loading => visual_effect(:fade, dom_id(note, 'container')),
0
         :complete => "Element.remove('#{dom_id(note, 'container')}');",
0
         :url => note_path(note),
0
         :method => :delete,
0
- :confirm => "Are you sure that you want to delete the note \'#{note.id.to_s}\'?" ) + " " -%>
0
+ :confirm => "Are you sure that you want to delete the note \'#{note.id.to_s}\'?" },
0
+ { :class => 'delete_note' }) -%> 
0
       <%= link_to_function(image_tag( "blank.png", :title => "Edit item", :class=>"edit_item"),
0
         "Element.toggle('#{dom_id(note)}'); Element.toggle('#{dom_id(note, 'edit')}'); Effect.Appear('#{dom_id(note, 'edit')}'); Form.focusFirstElement('#{dom_id(note, 'edit_form')}');" ) + " | " %>
0
       <%= link_to("In: " + note.project.name, project_path(note.project), :class=>"footer_link" ) %>&nbsp;|&nbsp;
...
12
13
14
15
 
16
 
 
17
18
19
...
24
25
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
12
13
14
 
15
16
17
18
19
20
21
...
26
27
28
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -12,8 +12,10 @@ To avoid showing the migrations as tests are run, add the following to your data
0
 
0
 If you want to run tests using another database, that's fine, too. Just change your database.yml accordingly.
0
 
0
-3. SELENIUM TESTS
0
+3. SELENIUM TESTS (Selenium on Rails)
0
 
0
+This testing style is deprecated and are being moved over to Selenium via RSpec stories by lukemelia (See #4 below for the new style).
0
+
0
 To run selenium tests, start Tracks in test mode using
0
 
0
   script/server -e test
0
@@ -24,4 +26,25 @@ Then open a browser to
0
   
0
 and interact with the test runner.
0
 
0
-For more information about Selenium on Rails, see vendor/plugins/selenium-on-rails/README
0
\ No newline at end of file
0
+For more information about Selenium on Rails, see vendor/plugins/selenium-on-rails/README
0
+
0
+4. RSPEC STORY RUNNER TESTS
0
+
0
+To run the stories, which are browser tests using selenium, start Tracks in test mode using
0
+
0
+ rake db:test:prepare
0
+ script/server -e test
0
+
0
+Then start Selenium by running
0
+
0
+ selenium
0
+
0
+which is a script installed with the Selenium gem (sudo gem install Selenium)
0
+
0
+Once the site and selenium server are running, then run all stories with
0
+
0
+ script/story
0
+
0
+or a specific set with
0
+
0
+ script/story stories/login/*.story
...
7
8
9
 
10
11
12
...
47
48
49
 
 
 
 
 
 
 
 
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
...
70
71
72
 
73
74
75
...
79
80
81
82
 
 
83
84
85
86
87
88
89
 
90
91
92
93
94
95
96
 
 
97
98
99
100
101
102
...
7
8
9
10
11
12
13
...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
91
92
93
94
95
96
97
...
101
102
103
 
104
105
106
 
 
107
108
109
110
111
112
113
114
115
116
117
 
118
119
120
 
 
121
122
123
0
@@ -7,6 +7,7 @@ require 'spec'
0
 require 'spec/rails'
0
 require 'spec/story'
0
 require 'webrat/selenium'
0
+require 'action_controller/test_process'
0
 
0
 module Spec
0
   module Story
0
@@ -47,10 +48,30 @@ class SeleniumRailsStory < Test::Unit::TestCase
0
     end
0
   end
0
   
0
+ def should_not_see(text_or_regexp)
0
+ if text_or_regexp.is_a?(Regexp)
0
+ response.should_not have_tag("*", text_or_regexp)
0
+ else
0
+ response.should_not have_tag("*", /#{Regexp.escape(text_or_regexp)}/i)
0
+ end
0
+ end
0
+
0
   def response
0
     webrat_session.response_body
0
   end
0
   
0
+ def logged_in_as(user)
0
+ visits("/selenium_helper/login?as=#{user.login}")
0
+ end
0
+
0
+ def selenium
0
+ SeleniumDriverManager.instance.running_selenium_driver
0
+ end
0
+
0
+ def badge_count_should_show(count)
0
+ response.should have_tag('#badge_count', count.to_s)
0
+ end
0
+
0
   def method_missing(name, *args)
0
     if webrat_session.respond_to?(name)
0
       webrat_session.send(name, *args)
0
@@ -70,6 +91,7 @@ end
0
 
0
 class DatabaseResetListener
0
   include Singleton
0
+
0
   def scenario_started(*args)
0
     if defined?(ActiveRecord::Base)
0
       connection = ActiveRecord::Base.connection
0
@@ -79,24 +101,23 @@ class DatabaseResetListener
0
     end
0
   end
0
 
0
- def scenario_succeeded(*args)
0
+ def method_missing sym, *args, &block
0
+ # ignore all messages you don't care about
0
   end
0
- alias :scenario_pending :scenario_succeeded
0
- alias :scenario_failed :scenario_succeeded
0
 end
0
 
0
 class CookieResetListener
0
   include Singleton
0
+
0
   def scenario_started(*args)
0
     %w[tracks_login auth_token _session_id].each do |cookie_name|
0
       SeleniumDriverManager.instance.running_selenium_driver.get_eval("window.document.cookie = '#{cookie_name}=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';")
0
     end
0
   end
0
   
0
- def scenario_succeeded(*args)
0
+ def method_missing sym, *args, &block
0
+ # ignore all messages you don't care about
0
   end
0
- alias :scenario_pending :scenario_succeeded
0
- alias :scenario_failed :scenario_succeeded
0
 end
0
 
0
 class Spec::Story::Runner::ScenarioRunner
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
 
 
17
18
19
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
0
@@ -1,19 +1,6 @@
0
-steps_for :login do
0
- Given "an admin user Reinier with the password abracadabra" do
0
- @reinier = User.create!(:login => 'reinier', :password => 'abracadabra', :password_confirmation => 'abracadabra', :is_admin => true)
0
- @reinier.create_preference
0
- end
0
-
0
- Given "Reinier is not logged in" do
0
- end
0
-
0
- Given "no users exist" do
0
- User.delete_all
0
- end
0
-
0
- Given "a visitor named Reinier" do
0
- end
0
-
0
+steps_for :login do
0
+ include_steps_for :users
0
+
0
   When "Reinier submits the login form with an incorrect password" do
0
     fills_in 'Login', :with => 'reinier'
0
     fills_in 'Password', :with => 'incorrectpass'
...
11
12
13
14
 
15
16
17
18
19
20
21
 
 
22
23
24
 
25
26
27
28
29
 
 
 
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
...
11
12
13
 
14
15
16
17
18
19
20
 
21
22
23
24
 
25
26
27
 
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -11,24 +11,52 @@ module Webrat
0
     end
0
     
0
     def fills_in(label_text, options)
0
- @selenium.type("webrat=#{Regexp.escape(label_text)}", "#{options[:with]}")
0
+ @selenium.type("webrat=#{label_text}", "#{options[:with]}")
0
     end
0
     
0
     def response_body
0
       @selenium.get_html_source
0
     end
0
     
0
- def clicks_button(button_text = nil)
0
+ def clicks_button(button_text = nil, options = {})
0
+ button_text, options = nil, button_text if button_text.is_a?(Hash) && options == {}
0
       button_text ||= '*'
0
       @selenium.click("button=#{button_text}")
0
- @selenium.wait_for_page_to_load()
0
+ wait_for_result(options[:wait])
0
     end
0
 
0
- def clicks_link(link_text)
0
- @selenium.click("webratlink=#{Regexp.escape(link_text)}")
0
- @selenium.wait_for_page_to_load()
0
+ def clicks_link(link_text, options = {})
0
+ @selenium.click("webratlink=#{link_text}")
0
+ wait_for_result(options[:wait])
0
     end
0
     
0
+ def wait_for_result(wait_type)
0
+ if wait_type == :ajax
0
+ wait_for_ajax
0
+ elsif wait_type == :effects
0
+ wait_for_effects
0
+ else
0
+ wait_for_page_to_load
0
+ end
0
+ end
0
+
0
+ def wait_for_page_to_load(timeout = 15000)
0
+ @selenium.wait_for_page_to_load(timeout)
0
+ end
0
+
0
+ def wait_for_ajax(timeout = 15000)
0
+ @selenium.wait_for_condition "window.Ajax.activeRequestCount == 0", timeout
0
+ end
0
+
0
+ def wait_for_effects(timeout = 15000)
0
+ @selenium.wait_for_condition "window.Effect.Queue.size() == 0", timeout
0
+ end
0
+
0
+ def wait_for_ajax_and_effects
0
+ wait_for_ajax
0
+ wait_for_effects
0
+ end
0
+
0
     def selects(option_text, options = {})
0
       id_or_name_or_label = options[:from]
0
       

Comments

    No one has commented yet.