rsel 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +22 -8
  3. data/docs/development.md +1 -0
  4. data/docs/history.md +11 -1
  5. data/docs/index.md +1 -0
  6. data/docs/scoping.md +1 -1
  7. data/docs/studying.md +76 -0
  8. data/lib/rsel/selenium_test.rb +505 -90
  9. data/lib/rsel/study_html.rb +198 -0
  10. data/lib/rsel/support.rb +105 -4
  11. data/rsel.gemspec +1 -1
  12. data/spec/spec_helper.rb +4 -22
  13. data/spec/st_alerts.rb +48 -0
  14. data/spec/st_browser_spec.rb +58 -0
  15. data/spec/st_buttons_spec.rb +95 -0
  16. data/spec/st_checkboxes_spec.rb +235 -0
  17. data/spec/st_conditionals_spec.rb +180 -0
  18. data/spec/st_dropdowns_spec.rb +140 -0
  19. data/spec/st_field_equals_among_spec.rb +48 -0
  20. data/spec/st_fields_equal_among_spec.rb +74 -0
  21. data/spec/st_fields_equal_spec.rb +90 -0
  22. data/spec/st_fields_spec.rb +167 -0
  23. data/spec/st_initialization_spec.rb +33 -0
  24. data/spec/st_links_spec.rb +84 -0
  25. data/spec/st_method_missing_spec.rb +59 -0
  26. data/spec/st_navigation_spec.rb +56 -0
  27. data/spec/st_radiobuttons_spec.rb +123 -0
  28. data/spec/st_respond_to_spec.rb +16 -0
  29. data/spec/st_scenario_spec.rb +26 -0
  30. data/spec/st_set_field_among_spec.rb +45 -0
  31. data/spec/st_set_field_spec.rb +842 -0
  32. data/spec/st_set_fields_among_spec.rb +74 -0
  33. data/spec/st_set_fields_spec.rb +97 -0
  34. data/spec/st_spec_helper.rb +43 -0
  35. data/spec/st_stop_on_failure_spec.rb +199 -0
  36. data/spec/st_tables_spec.rb +42 -0
  37. data/spec/st_temporal_visibility_spec.rb +122 -0
  38. data/spec/st_visibility_spec.rb +125 -0
  39. data/spec/st_waiting_spec.rb +37 -0
  40. data/spec/study_html_spec.rb +310 -0
  41. data/spec/support_spec.rb +163 -13
  42. data/test/server/README.txt +3 -0
  43. data/test/views/alert.erb +15 -0
  44. data/test/views/form.erb +6 -1
  45. data/test/views/index.erb +2 -0
  46. data/test/views/slowtext.erb +1 -1
  47. metadata +38 -9
  48. data/spec/selenium_test_spec.rb +0 -2656
@@ -0,0 +1,74 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe "#set_fields_among" do
4
+ before(:each) do
5
+ @st.visit("/form").should be_true
6
+ end
7
+
8
+ context "passes when" do
9
+ context "text fields with labels" do
10
+ it "sets one field" do
11
+ @st.set_fields_among({"First name" => "Marcus"}).should be_true
12
+ @st.field_contains("First name", "Marcus").should be_true
13
+ end
14
+
15
+ it "sets one field with string ids" do
16
+ @st.set_fields_among({"First name" => "Marcus"}, "").should be_true
17
+ @st.field_contains("First name", "Marcus").should be_true
18
+ end
19
+
20
+ it "does nothing, but has ids" do
21
+ @st.set_fields_among("", {"First name" => "Marcus"}).should be_true
22
+ end
23
+
24
+ it "sets several fields" do
25
+ @st.set_fields_among({"First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot."})
26
+ @st.field_contains("First name", "Ken").should be_true
27
+ @st.field_contains("Last name", "Brazier").should be_true
28
+ @st.field_contains("Life story", "story: I get testy").should be_true
29
+ end
30
+ end
31
+ context "text fields with labels in a hash" do
32
+ it "sets one field from a hash" do
33
+ @st.set_fields_among({"Faust name" => "Marcus"}, {"Faust Name" => "First name", "LOST name" => "Last name"}).should be_true
34
+ @st.field_contains("First name", "Marcus").should be_true
35
+ end
36
+
37
+ it "sets many fields, some from a hash" do
38
+ @st.set_fields_among({"Faust\\;name" => "Ken", :Lost => "Brazier", "Life story" => "I get testy a lot."},
39
+ {"Faust\\;Name" => "First name", :LOST => "Last name"}).should be_true
40
+ @st.field_contains("First name", "Ken").should be_true
41
+ @st.field_contains("Last name", "Brazier").should be_true
42
+ @st.field_contains("Life story", "testy").should be_true
43
+ end
44
+ end
45
+ it "clears a field" do
46
+ @st.set_fields_among({"message" => ""},"").should be_true
47
+ @st.field_contains("message", "").should be_true
48
+ end
49
+ end
50
+
51
+ context "fails when" do
52
+ context "text fields with labels" do
53
+ it "cant find the first field" do
54
+ @st.set_fields_among({"Faust name" => "Ken", "Last name" => "Brazier"}).should be_false
55
+ end
56
+
57
+ it "cant find the last field" do
58
+ @st.set_fields_among({"First name" => "Ken", "Lost name" => "Brazier"}).should be_false
59
+ end
60
+ end
61
+ context "text fields with labels in a hash" do
62
+ it "cant find the first field" do
63
+ @st.set_fields_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
64
+ {"Faust Name" => "Lost name", "Lost name" => "Last name"}).should be_false
65
+ end
66
+
67
+ it "cant find the last field" do
68
+ @st.set_fields_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
69
+ {"Faust Name" => "First name", "Lost name" => "Faust name"}).should be_false
70
+ end
71
+ end
72
+ end
73
+ end # set_fields_among
74
+
@@ -0,0 +1,97 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe "#set_fields" do
4
+ context "without studying" do
5
+ before(:each) do
6
+ @st.visit("/form").should be_true
7
+ end
8
+
9
+ context "passes when" do
10
+ context "text fields with labels" do
11
+ it "sets one field" do
12
+ @st.set_fields("First name" => "Marcus").should be_true
13
+ @st.field_contains("First name", "Marcus").should be_true
14
+ end
15
+
16
+ it "sets zero fields" do
17
+ @st.set_fields("").should be_true
18
+ end
19
+
20
+ it "sets several fields" do
21
+ @st.set_fields("First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot.").should be_true
22
+ @st.field_contains("First name", "Ken").should be_true
23
+ @st.field_contains("Last name", "Brazier").should be_true
24
+ @st.field_contains("Life story", "story: I get testy").should be_true
25
+ end
26
+
27
+ it "clears a field" do
28
+ @st.set_fields("message" => "").should be_true
29
+ @st.field_contains("message", "").should be_true
30
+ end
31
+ end
32
+ end
33
+
34
+ context "fails when" do
35
+ context "text fields with labels" do
36
+ it "cant find the first field" do
37
+ @st.set_fields("Faust name" => "Ken", "Last name" => "Brazier").should be_false
38
+ end
39
+
40
+ it "cant find the last field" do
41
+ @st.set_fields("First name" => "Ken", "Lost name" => "Brazier").should be_false
42
+ end
43
+ end
44
+ end
45
+ end # set_fields
46
+
47
+
48
+ context "with studying" do
49
+ before(:all) do
50
+ @st.set_fields_study_min('always')
51
+ end
52
+ before(:each) do
53
+ @st.visit("/form").should be_true
54
+ end
55
+
56
+ context "passes when" do
57
+ context "text fields with labels" do
58
+ it "sets one field" do
59
+ @st.set_fields("First name" => "Marcus").should be_true
60
+ @st.field_contains("First name", "Marcus").should be_true
61
+ end
62
+
63
+ it "sets zero fields" do
64
+ @st.set_fields("").should be_true
65
+ end
66
+
67
+ it "sets several fields" do
68
+ @st.set_fields("First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot.").should be_true
69
+ @st.field_contains("First name", "Ken").should be_true
70
+ @st.field_contains("Last name", "Brazier").should be_true
71
+ @st.field_contains("Life story", "story: I get testy").should be_true
72
+ end
73
+
74
+ it "clears a field" do
75
+ @st.set_fields("message" => "").should be_true
76
+ @st.field_contains("message", "").should be_true
77
+ end
78
+ end
79
+ end
80
+
81
+ context "fails when" do
82
+ context "text fields with labels" do
83
+ it "cant find the first field" do
84
+ @st.set_fields("Faust name" => "Ken", "Last name" => "Brazier").should be_false
85
+ end
86
+
87
+ it "cant find the last field" do
88
+ @st.set_fields("First name" => "Ken", "Lost name" => "Brazier").should be_false
89
+ end
90
+ end
91
+ end
92
+ after(:all) do
93
+ @st.set_fields_study_min('default')
94
+ end
95
+ end
96
+ end # set_fields
97
+
@@ -0,0 +1,43 @@
1
+ # This file includes RSpec configuration that is only needed when testing the
2
+ # SeleniumTest class. Include this file in your spec test if you need to use
3
+ # a SeleniumTest browser session (@st).
4
+
5
+ require 'spec/spec_helper'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:suite) do
9
+ # For some reason, RSpec runs this twice; work around possible duplicate
10
+ # browser windows by only intializing @@st if it hasn't been already
11
+ @@st ||= Rsel::SeleniumTest.new('http://localhost:8070')
12
+ @@st.open_browser
13
+ end
14
+
15
+ config.after(:suite) do
16
+ @@st.close_browser('without showing errors')
17
+ end
18
+
19
+ config.before(:all) do
20
+ @st = @@st
21
+ end
22
+ end
23
+
24
+ # Monkeypatch the Selenium::Client::Protocol module,
25
+ # to prevent http_post from spewing out a bunch of `puts`es on failure.
26
+ # (It's really distracting when running spec tests)
27
+ module Selenium
28
+ module Client
29
+ module Protocol
30
+ def http_post(data)
31
+ start = Time.now
32
+ called_from = caller.detect{|line| line !~ /(selenium-client|vendor|usr\/lib\/ruby|\(eval\))/i}
33
+ http = Net::HTTP.new(@host, @port)
34
+ http.open_timeout = default_timeout_in_seconds
35
+ http.read_timeout = default_timeout_in_seconds
36
+ response = http.post('/selenium-server/driver/', data, HTTP_HEADERS)
37
+ # <-- Here is where all the puts statements were -->
38
+ [ response.body[0..1], response.body ]
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,199 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'stop on failure' do
4
+ before(:each) do
5
+ @st.visit("/").should be_true
6
+ @st.stop_on_failure = true
7
+ @st.found_failure = false
8
+ end
9
+
10
+ after(:each) do
11
+ @st.stop_on_failure = false
12
+ end
13
+
14
+ context "causes subsequent steps to fail" do
15
+ it "when #see fails" do
16
+ @st.see("Nonexistent").should be_false
17
+ # Would pass, but previous step failed
18
+ @st.see("Welcome").should be_false
19
+ end
20
+
21
+ it "when #do_not_see fails" do
22
+ @st.do_not_see("Welcome").should be_false
23
+ # Would pass, but previous step failed
24
+ @st.do_not_see("Nonexistent").should be_false
25
+ end
26
+
27
+ it "when #see_title fails" do
28
+ @st.errors # clear errors
29
+ @st.see_title("Wrong Title").should be_false
30
+ # Would pass, but previous step failed
31
+ @st.see_title("Rsel Test Site").should be_false
32
+ # Should see one and only one error.
33
+ @st.errors.should eq("Page title is 'Rsel Test Site', not 'Wrong Title'")
34
+ end
35
+
36
+ it "when #do_not_see_title fails" do
37
+ @st.do_not_see_title("Rsel Test Site").should be_false
38
+ # Would pass, but previous step failed
39
+ @st.do_not_see_title("Wrong title").should be_false
40
+ end
41
+
42
+ it "when #link_exists fails" do
43
+ @st.link_exists("Bogus Link").should be_false
44
+ # Would pass, but previous step failed
45
+ @st.link_exists("About this site").should be_false
46
+ end
47
+
48
+ it "when #button_exists fails" do
49
+ @st.visit("/form").should be_true
50
+ @st.button_exists("Bogus Button").should be_false
51
+ # Would pass, but previous step failed
52
+ @st.button_exists("Submit person form").should be_false
53
+ end
54
+
55
+ it "when #row_exists fails" do
56
+ @st.visit("/table").should be_true
57
+ @st.row_exists("No, Such, Row").should be_false
58
+ # Would pass, but previous step failed
59
+ @st.row_exists("First name, Last name, Email").should be_false
60
+ end
61
+
62
+ it "when #type_into_field fails" do
63
+ @st.visit("/form").should be_true
64
+ @st.type_into_field("Hello", "Bad Field").should be_false
65
+ # Would pass, but previous step failed
66
+ @st.type_into_field("Eric", "First name").should be_false
67
+ end
68
+
69
+ it "when #field_contains fails" do
70
+ @st.visit("/form").should be_true
71
+ @st.field_contains("Bad Field", "Hello").should be_false
72
+ # Would pass, but previous step failed
73
+ @st.field_contains("First name", "Marcus").should be_false
74
+ end
75
+
76
+ it "when #field_equals fails" do
77
+ @st.visit("/form").should be_true
78
+ @st.fill_in_with("First name", "Ken")
79
+ @st.field_equals("First name", "Eric").should be_false
80
+ # Would pass, but previous step failed
81
+ @st.field_equals("First name", "Ken").should be_false
82
+ end
83
+
84
+ it "when #click fails" do
85
+ @st.click("No Such Link").should be_false
86
+ # Would pass, but previous step failed
87
+ @st.click("About this site").should be_false
88
+ end
89
+
90
+ it "when #click_link fails" do
91
+ @st.click_link("No Such Link").should be_false
92
+ # Would pass, but previous step failed
93
+ @st.click_link("About this site").should be_false
94
+ end
95
+
96
+ it "when #click_button fails" do
97
+ @st.visit("/form").should be_true
98
+ @st.click_button("No Such Link").should be_false
99
+ # Would pass, but previous step failed
100
+ @st.click_button("Submit person form").should be_false
101
+ end
102
+
103
+ it "when #enable_checkbox fails" do
104
+ @st.visit("/form").should be_true
105
+ @st.enable_checkbox("No Such Checkbox").should be_false
106
+ # Would pass, but previous step failed
107
+ @st.enable_checkbox("I like cheese").should be_false
108
+ end
109
+
110
+ it "when #disable_checkbox fails" do
111
+ @st.visit("/form").should be_true
112
+ @st.disable_checkbox("No Such Checkbox").should be_false
113
+ # Would pass, but previous step failed
114
+ @st.disable_checkbox("I like cheese").should be_false
115
+ end
116
+
117
+ it "when #checkbox_is_enabled fails" do
118
+ @st.visit("/form").should be_true
119
+ @st.enable_checkbox("I like cheese").should be_true
120
+ @st.checkbox_is_enabled("No Such Checkbox").should be_false
121
+ # Would pass, but previous step failed
122
+ @st.checkbox_is_enabled("I like cheese").should be_false
123
+ end
124
+
125
+ it "when #checkbox_is_disabled fails" do
126
+ @st.visit("/form").should be_true
127
+ @st.checkbox_is_disabled("No Such Checkbox").should be_false
128
+ # Would pass, but previous step failed
129
+ @st.checkbox_is_disabled("I like cheese").should be_false
130
+ end
131
+
132
+ it "when #radio_is_enabled fails" do
133
+ @st.visit("/form").should be_true
134
+ @st.select_radio("Briefs").should be_true
135
+ @st.radio_is_enabled("No Such Radio").should be_false
136
+ # Would pass, but previous step failed
137
+ @st.radio_is_enabled("Briefs").should be_false
138
+ end
139
+
140
+ it "when #radio_is_disabled fails" do
141
+ @st.visit("/form").should be_true
142
+ @st.select_radio("Boxers").should be_true
143
+ @st.radio_is_disabled("No Such Radio").should be_false
144
+ # Would pass, but previous step failed
145
+ @st.radio_is_disabled("Briefs").should be_false
146
+ end
147
+
148
+ it "when #select_radio fails" do
149
+ @st.visit("/form").should be_true
150
+ @st.select_radio("No Such Radio").should be_false
151
+ # Would pass, but previous step failed
152
+ @st.select_radio("Boxers").should be_false
153
+ end
154
+
155
+ it "when #select_from_dropdown fails" do
156
+ @st.visit("/form").should be_true
157
+ @st.select_from_dropdown("Junk", "No Such Dropdown").should be_false
158
+ # Would pass, but previous step failed
159
+ @st.select_from_dropdown("Tall", "Height").should be_false
160
+ end
161
+
162
+ it "when #dropdown_includes fails" do
163
+ @st.visit("/form").should be_true
164
+ @st.dropdown_includes("No Such Dropdown", "Junk").should be_false
165
+ # Would pass, but previous step failed
166
+ @st.dropdown_includes("Height", "Tall").should be_false
167
+ end
168
+
169
+ it "when #dropdown_equals fails" do
170
+ @st.visit("/form").should be_true
171
+ @st.select_from_dropdown("Tall", "Height").should be_true
172
+ @st.dropdown_equals("No Such Dropdown", "Junk").should be_false
173
+ # Would pass, but previous step failed
174
+ @st.dropdown_equals("Tall", "Height").should be_false
175
+ end
176
+ end
177
+
178
+ context "can be reset with #begin_scenario" do
179
+ it "when #see fails" do
180
+ @st.see("Nonexistent").should be_false
181
+ # Would pass, but previous step failed
182
+ @st.see("Welcome").should be_false
183
+ # Starting a new scenario allows #see to pass
184
+ @st.begin_scenario
185
+ @st.see("Welcome").should be_true
186
+ end
187
+
188
+ it "when #do_not_see fails" do
189
+ @st.do_not_see("Welcome").should be_false
190
+ # Would pass, but previous step failed
191
+ @st.do_not_see("Nonexistent").should be_false
192
+ # Starting a new scenario allows #do_not_see to pass
193
+ @st.begin_scenario
194
+ @st.do_not_see("Nonexistent").should be_true
195
+ end
196
+ end
197
+
198
+ end
199
+
@@ -0,0 +1,42 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'tables' do
4
+ before(:each) do
5
+ @st.visit("/table").should be_true
6
+ end
7
+
8
+ describe "#row_exists" do
9
+ context "passes when" do
10
+ it "full row of headings exists" do
11
+ @st.row_exists("First name, Last name, Email").should be_true
12
+ end
13
+
14
+ it "partial row of headings exists" do
15
+ @st.row_exists("First name, Last name").should be_true
16
+ @st.row_exists("Last name, Email").should be_true
17
+ end
18
+
19
+ it "full row of cells exists" do
20
+ @st.row_exists("Eric, Pierce, epierce@example.com").should be_true
21
+ end
22
+
23
+ it "partial row of cells exists" do
24
+ @st.row_exists("Eric, Pierce").should be_true
25
+ @st.row_exists("Pierce, epierce@example.com").should be_true
26
+ end
27
+
28
+ it "cell values are not consecutive" do
29
+ @st.row_exists("First name, Email").should be_true
30
+ @st.row_exists("Eric, epierce@example.com").should be_true
31
+ end
32
+ end
33
+
34
+ context "fails when" do
35
+ it "no row exists" do
36
+ @st.row_exists("Middle name, Maiden name, Email").should be_false
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+