rsel 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
1
+ require 'spec/spec_helper'
2
2
 
3
3
  require 'xpath'
4
4
 
@@ -32,12 +32,18 @@ describe Rsel::Support do
32
32
  end.should raise_error
33
33
  end
34
34
 
35
- it "requires element kind for Rsel-style locators" do
35
+ it "requires non-empty element kind for Rsel-style locators" do
36
36
  lambda do
37
37
  loc('foo')
38
38
  end.should raise_error
39
39
  end
40
40
 
41
+ it "requires a known element kind for Rsel-style locators" do
42
+ lambda do
43
+ loc('foo', 'bogus_kind')
44
+ end.should raise_error
45
+ end
46
+
41
47
  it "accepts within for css locators" do
42
48
  loc("css=.boss", '', {:within => "employees"}).should == "css=#employees .boss"
43
49
  end
@@ -48,10 +54,14 @@ describe Rsel::Support do
48
54
  end
49
55
 
50
56
  describe "#xpath" do
51
- it "requires a valid kind" do
57
+ it "requires a valid, non-empty kind" do
52
58
  lambda do
53
59
  xpath('junk', 'hello')
54
60
  end.should raise_error
61
+
62
+ lambda do
63
+ xpath('', 'hello')
64
+ end.should raise_error
55
65
  end
56
66
 
57
67
  it "applies within scope" do
@@ -223,12 +233,12 @@ describe Rsel::Support do
223
233
  describe "#selenium_compare" do
224
234
  context "returns true when" do
225
235
  it "gets most identical strings" do
226
- selenium_compare("","").should be_true
227
- selenium_compare("This","This").should be_true
236
+ selenium_compare("", "").should be_true
237
+ selenium_compare("This", "This").should be_true
228
238
  end
229
239
  it "gets exact:ly identical strings" do
230
- selenium_compare("","exact:").should be_true
231
- selenium_compare("This","exact:This").should be_true
240
+ selenium_compare("", "exact:").should be_true
241
+ selenium_compare("This", "exact:This").should be_true
232
242
  end
233
243
  it "gets matching globs" do
234
244
  selenium_compare("", "*").should be_true
@@ -253,14 +263,15 @@ describe Rsel::Support do
253
263
 
254
264
  context "returns false when" do
255
265
  it "gets most differing strings" do
256
- selenium_compare("","!").should be_false
257
- selenium_compare("&","").should be_false
258
- selenium_compare("This","That").should be_false
266
+ selenium_compare("", "!").should be_false
267
+ selenium_compare("&", "").should be_false
268
+ selenium_compare("This", "That").should be_false
259
269
  end
260
270
  it "gets exact:ly different strings" do
261
- selenium_compare("","exact:!").should be_false
262
- selenium_compare("&","exact:").should be_false
263
- selenium_compare("This","exact:That").should be_false
271
+ selenium_compare("", "exact:!").should be_false
272
+ selenium_compare("!!", "exact:!").should be_false
273
+ selenium_compare("&", "exact:").should be_false
274
+ selenium_compare("This", "exact:That").should be_false
264
275
  end
265
276
  it "gets non-matching globs" do
266
277
  selenium_compare("No", "?").should be_false
@@ -305,5 +316,144 @@ describe Rsel::Support do
305
316
  result.should == %Q{//tr[contains(., 'abc') and contains(., 'def')]}
306
317
  end
307
318
  end
319
+
320
+ describe "#globify" do
321
+ it "leaves `exact:text` unchanged" do
322
+ globify('exact:text').should == 'exact:text'
323
+ end
324
+
325
+ it "leaves `regexp:text` unchanged" do
326
+ globify('regexp:text').should == 'regexp:text'
327
+ end
328
+
329
+ it "leaves `regexpi:text` unchanged" do
330
+ globify('regexpi:text').should == 'regexpi:text'
331
+ end
332
+
333
+ it "converts `glob:text` to `*text*`" do
334
+ globify('glob:text').should == '*text*'
335
+ end
336
+
337
+ it "adds *...* to text" do
338
+ globify('text').should == '*text*'
339
+ end
340
+ end
341
+
342
+ describe "#result_within" do
343
+ context "returns the result when" do
344
+ it "block evaluates to true immediately" do
345
+ result_within(3) do
346
+ true
347
+ end.should == true
348
+ end
349
+
350
+ it "block evaluates to a non-false value immediately" do
351
+ result_within(3) do
352
+ foo = 'foo'
353
+ end.should == 'foo'
354
+ end
355
+
356
+ it "block evaluates to false initially, but true within the timeout" do
357
+ @first_run = true
358
+ result_within(3) do
359
+ if @first_run
360
+ @first_run = false
361
+ false
362
+ else
363
+ true
364
+ end
365
+ end.should == true
366
+ end
367
+
368
+ it "block raises an exception, but evaluates true within the timeout" do
369
+ @first_run = true
370
+ result_within(3) do
371
+ if @first_run
372
+ @first_run = false
373
+ raise RuntimeError
374
+ else
375
+ true
376
+ end
377
+ end.should == true
378
+ end
379
+ end
380
+
381
+ context "returns false when" do
382
+ it "block evaluates as false every time" do
383
+ result_within(3) do
384
+ false
385
+ end.should be_nil
386
+ end
387
+
388
+ it "block evaluates as nil every time" do
389
+ result_within(3) do
390
+ nil
391
+ end.should be_nil
392
+ end
393
+
394
+ it "block raises an exception every time" do
395
+ result_within(3) do
396
+ raise RuntimeError
397
+ end.should be_nil
398
+ end
399
+
400
+ it "block does not return within the timeout"
401
+ end
402
+ end
403
+
404
+
405
+ describe "#failed_within" do
406
+ context "returns true when" do
407
+ it "block evaluates to false immediately" do
408
+ failed_within(3) do
409
+ false
410
+ end.should be_true
411
+ end
412
+
413
+ it "block evaluates to nil immediately" do
414
+ failed_within(3) do
415
+ nil
416
+ end.should be_true
417
+ end
418
+
419
+ it "block evaluates to true initially, but false within the timeout" do
420
+ @first_run = true
421
+ failed_within(3) do
422
+ if @first_run
423
+ @first_run = false
424
+ true
425
+ else
426
+ false
427
+ end
428
+ end.should be_true
429
+ end
430
+
431
+ it "block evaluates to true initially, but raises an exception within the timeout" do
432
+ @first_run = true
433
+ failed_within(3) do
434
+ if @first_run
435
+ @first_run = false
436
+ true
437
+ else
438
+ raise RuntimeError
439
+ end
440
+ end.should be_true
441
+ end
442
+ end
443
+
444
+ context "returns false when" do
445
+ it "block evaluates as true every time" do
446
+ failed_within(3) do
447
+ true
448
+ end.should be_false
449
+ end
450
+
451
+ it "block evaluates as true-ish every time" do
452
+ failed_within(3) do
453
+ 'foo'
454
+ end.should be_false
455
+ end
456
+ end
457
+ end
308
458
  end
309
459
 
@@ -0,0 +1,3 @@
1
+ The selenium-server .jar file goes in this directory. If you don't see a .jar
2
+ file in this directory, run `rake selenium:download` to fetch it.
3
+
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head><title>Alert page</title>
3
+ <script>
4
+ function doalert() {
5
+ alert("Ruby alert! Automate your workstations!");
6
+ }
7
+ </script>
8
+ </head>
9
+ <body>
10
+ <h1>Alert page</h1>
11
+ <p><button value="alert_now" onclick="doalert();">Alert me now</button></p>
12
+ <p><button value="alert_soon" onclick="setTimeout(doalert, 3000);">Alert me soon</button></p>
13
+ </body>
14
+ </html>
15
+
@@ -15,6 +15,9 @@
15
15
  <label for="last_name">Last name</label>
16
16
  <input id="last_name" type="text" />
17
17
  </p>
18
+ <p>
19
+ <input id="secret" type="hidden" value="psst" />
20
+ </p>
18
21
  <p>
19
22
  <label for="biography">Life story</label>
20
23
  <textarea id="biography" cols="80" rows="10">
@@ -106,6 +109,7 @@
106
109
  <label for="message">Message</label>
107
110
  <input id="message" type="text" value="Your message goes here" />
108
111
  </p>
112
+ <p>Duplicate textbox <input id="duplicate" name="first_duplicate" type="text" /></p>
109
113
  <p><input type="submit" value="Save preferences" /></p>
110
114
  </form>
111
115
  </div>
@@ -121,10 +125,11 @@
121
125
  </select>
122
126
  </p>
123
127
  <p><input id="readonly" type="text" disabled="disabled" /></p>
128
+ <p>Duplicate textbox <input id="duplicate" name="second_duplicate" type="text" /></p>
124
129
  <p><input type="submit" value="Save is disabled" disabled="disabled" /></p>
125
130
  </form>
126
131
  </div>
127
-
132
+ <a href="/">Home</a>
128
133
  </body>
129
134
  </html>
130
135
 
@@ -6,6 +6,7 @@
6
6
  <p>This is a Sinatra webapp for unit testing Rsel.</p>
7
7
 
8
8
  <div id="header">
9
+ <p style="display:none">But some things are better left unseen.</p>
9
10
  <ul>
10
11
  <li><a href="/about">About this site</a></li>
11
12
  </ul>
@@ -18,6 +19,7 @@
18
19
  <li><a href="/table">Table test</a></li>
19
20
  <li><a href="/slow">Slow page</a></li>
20
21
  <li><a href="/slowtext">Late text page</a></li>
22
+ <li><a href="/alert">Alert page</a></li>
21
23
  </ul>
22
24
  </div>
23
25
 
@@ -20,7 +20,7 @@
20
20
  </head>
21
21
  <body onload="setTimeout(createtext, 2000);">
22
22
  <h1>Late text page</h1>
23
- <p>The text is coming...</p>
23
+ <p id="oldtext">The text is coming...</p>
24
24
  </body>
25
25
  </html>
26
26
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcus French
@@ -17,8 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-01-04 00:00:00 -07:00
21
- default_executable:
20
+ date: 2012-04-02 00:00:00 Z
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
23
  name: rubyslim-unofficial
@@ -193,19 +192,50 @@ files:
193
192
  - docs/rsel_components.svg
194
193
  - docs/scenarios.md
195
194
  - docs/scoping.md
195
+ - docs/studying.md
196
196
  - docs/todo.md
197
197
  - docs/usage.md
198
198
  - lib/rsel.rb
199
199
  - lib/rsel/exceptions.rb
200
200
  - lib/rsel/selenium_test.rb
201
+ - lib/rsel/study_html.rb
201
202
  - lib/rsel/support.rb
202
203
  - rsel.gemspec
203
- - spec/selenium_test_spec.rb
204
204
  - spec/spec_helper.rb
205
+ - spec/st_alerts.rb
206
+ - spec/st_browser_spec.rb
207
+ - spec/st_buttons_spec.rb
208
+ - spec/st_checkboxes_spec.rb
209
+ - spec/st_conditionals_spec.rb
210
+ - spec/st_dropdowns_spec.rb
211
+ - spec/st_field_equals_among_spec.rb
212
+ - spec/st_fields_equal_among_spec.rb
213
+ - spec/st_fields_equal_spec.rb
214
+ - spec/st_fields_spec.rb
215
+ - spec/st_initialization_spec.rb
216
+ - spec/st_links_spec.rb
217
+ - spec/st_method_missing_spec.rb
218
+ - spec/st_navigation_spec.rb
219
+ - spec/st_radiobuttons_spec.rb
220
+ - spec/st_respond_to_spec.rb
221
+ - spec/st_scenario_spec.rb
222
+ - spec/st_set_field_among_spec.rb
223
+ - spec/st_set_field_spec.rb
224
+ - spec/st_set_fields_among_spec.rb
225
+ - spec/st_set_fields_spec.rb
226
+ - spec/st_spec_helper.rb
227
+ - spec/st_stop_on_failure_spec.rb
228
+ - spec/st_tables_spec.rb
229
+ - spec/st_temporal_visibility_spec.rb
230
+ - spec/st_visibility_spec.rb
231
+ - spec/st_waiting_spec.rb
232
+ - spec/study_html_spec.rb
205
233
  - spec/support_spec.rb
206
234
  - test/app.rb
207
235
  - test/config.ru
236
+ - test/server/README.txt
208
237
  - test/views/about.erb
238
+ - test/views/alert.erb
209
239
  - test/views/edit_eric.erb
210
240
  - test/views/edit_marcus.erb
211
241
  - test/views/favicon.ico.erb
@@ -216,7 +246,6 @@ files:
216
246
  - test/views/slowtext.erb
217
247
  - test/views/table.erb
218
248
  - test/views/thanks.erb
219
- has_rdoc: true
220
249
  homepage: http://github.com/a-e/rsel
221
250
  licenses: []
222
251
 
@@ -246,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
275
  requirements: []
247
276
 
248
277
  rubyforge_project:
249
- rubygems_version: 1.3.7
278
+ rubygems_version: 1.8.17
250
279
  signing_key:
251
280
  specification_version: 3
252
281
  summary: Runs Selenium tests from FitNesse
@@ -1,2656 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
-
3
- describe Rsel::SeleniumTest do
4
- before(:all) do
5
- @st = Rsel::SeleniumTest.new('http://localhost:8070/')
6
- @st.open_browser
7
- end
8
-
9
- after(:all) do
10
- @st.close_browser('without showing errors')
11
- end
12
-
13
- context "initialization" do
14
- before(:each) do
15
- @st.visit("/")
16
- end
17
-
18
- it "sets correct default configuration" do
19
- @st.url.should == "http://localhost:8070/"
20
- @st.browser.host.should == "localhost"
21
- @st.browser.port.should == 4444
22
- @st.stop_on_failure.should == false
23
- @st.found_failure.should == false
24
- end
25
-
26
- context "stop_on_failure option" do
27
- it "can be initialized with a string" do
28
- st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => 'true')
29
- st.stop_on_failure.should be_true
30
- st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => 'FALSE')
31
- st.stop_on_failure.should be_false
32
- end
33
-
34
- it "can be initialized with a boolean" do
35
- st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => true)
36
- st.stop_on_failure.should be_true
37
- st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => false)
38
- st.stop_on_failure.should be_false
39
- end
40
- end
41
-
42
- end
43
-
44
- context "opening, closing, and maximizing" do
45
- describe "#open_browser" do
46
- # FIXME: This blows up for some unknown reason
47
- #it "raises StopTestCannotConnect if the connection fails" do
48
- #st = Rsel::SeleniumTest.new('bogus_host')
49
- #lambda do
50
- #st.open_browser
51
- #end.should raise(Rsel::StopTestCannotConnect)
52
- #end
53
-
54
- # TODO: Find a cross-platform way of testing this
55
- #it "uses the javascript-xpath library for *iexplore" do
56
- #st = Rsel::SeleniumTest.new('localhost', :browser => '*iexplore')
57
- #st.open_browser
58
- #end
59
- end
60
-
61
- describe "#maximize_browser" do
62
- it "returns true" do
63
- st = Rsel::SeleniumTest.new('http://localhost:8070')
64
- st.open_browser
65
- st.maximize_browser.should be_true
66
- st.close_browser
67
- end
68
- end
69
-
70
- describe "#close_browser" do
71
- before(:each) do
72
- @st_temp = Rsel::SeleniumTest.new('http://localhost:8070')
73
- @st_temp.open_browser
74
- end
75
-
76
- it "returns true if there are no errors" do
77
- @st_temp.close_browser('and show errors').should be_true
78
- end
79
-
80
- it "returns true if there are errors, but show_errors is unset" do
81
- @st_temp.see("Nonexistent words")
82
- @st_temp.close_browser('').should be_true
83
- end
84
-
85
- # FIXME: Figure out why this fails. All rspec says is:
86
- # Failure/Error: end.should raise(Rsel::StopTestStepFailed)
87
- # Rsel::StopTestStepFailed:
88
- # Rsel::StopTestStepFailed
89
- #it "raises StopTestStepFailed if there are errors and show_errors is set" do
90
- #@st_temp.see("Nonexistent words")
91
- #lambda do
92
- #@st_temp.close_browser('and show errors')
93
- #end.should raise(Rsel::StopTestStepFailed)
94
- #end
95
- end
96
- end
97
-
98
-
99
- context "navigation" do
100
- before(:each) do
101
- @st.visit("/").should be_true
102
- end
103
-
104
- describe "#visit" do
105
- context "passes when" do
106
- it "page exists" do
107
- @st.visit("/about").should be_true
108
- end
109
- end
110
-
111
- # FIXME: Selenium server 2.3.0 and 2.4.0 no longer fail
112
- # when a 404 or 500 error is raised
113
- #context "fails when" do
114
- #it "page gets a 404 error" do
115
- #@st.visit("/404").should be_false
116
- #end
117
- #it "page gets a 500 error" do
118
- #@st.visit("/500").should be_false
119
- #end
120
- #end
121
- end
122
-
123
- context "reload the current page" do
124
- # TODO
125
- end
126
-
127
- describe "#click_back" do
128
- it "passes and loads the correct URL" do
129
- @st.visit("/about")
130
- @st.visit("/")
131
- @st.click_back.should be_true
132
- @st.see_title("About this site").should be_true
133
- end
134
-
135
- #it "fails when there is no previous page in the history" do
136
- # TODO: No obvious way to test this, since everything is running in the
137
- # same session
138
- #end
139
- end
140
- end # navigation
141
-
142
-
143
- context "visibility" do
144
- before(:each) do
145
- @st.visit("/").should be_true
146
- end
147
-
148
- describe "#see" do
149
- context "passes when" do
150
- it "text is present" do
151
- @st.see("Welcome").should be_true
152
- @st.see("This is a Sinatra webapp").should be_true
153
- end
154
- end
155
-
156
- context "fails when" do
157
- it "text is absent" do
158
- @st.errors
159
- @st.see("Nonexistent").should be_false
160
- @st.see("Some bogus text").should be_false
161
- @st.errors.should eq('')
162
- end
163
- end
164
-
165
- it "is case-sensitive" do
166
- @st.see("Sinatra webapp").should be_true
167
- @st.see("sinatra Webapp").should be_false
168
- end
169
- end
170
-
171
- describe "#do_not_see" do
172
- context "passes when" do
173
- it "text is absent" do
174
- @st.do_not_see("Nonexistent").should be_true
175
- @st.do_not_see("Some bogus text").should be_true
176
- end
177
- end
178
-
179
- context "fails when" do
180
- it "text is present" do
181
- @st.errors
182
- @st.do_not_see("Welcome").should be_false
183
- @st.do_not_see("This is a Sinatra webapp").should be_false
184
- @st.errors.should eq('')
185
- end
186
- end
187
-
188
- it "is case-sensitive" do
189
- @st.do_not_see("Sinatra webapp").should be_false
190
- @st.do_not_see("sinatra Webapp").should be_true
191
- end
192
- end
193
- end # visibility
194
-
195
-
196
- context "links" do
197
- before(:each) do
198
- @st.visit("/").should be_true
199
- end
200
-
201
- describe "#click" do
202
- context "passes when" do
203
- it "link exists" do
204
- @st.click("About this site").should be_true
205
- end
206
- end
207
-
208
- context "fails when" do
209
- it "link does not exist" do
210
- @st.click("Bogus link").should be_false
211
- end
212
- end
213
- end
214
-
215
-
216
- describe "#click_link" do
217
- context "passes when" do
218
- it "link exists" do
219
- @st.click_link("About this site").should be_true
220
- end
221
-
222
- it "link exists within scope" do
223
- @st.click_link("About this site", :within => "header").should be_true
224
- end
225
-
226
- it "link exists in table row" do
227
- @st.visit("/table")
228
- @st.click_link("Edit", :in_row => "Marcus").should be_true
229
- @st.see_title("Editing Marcus").should be_true
230
- end
231
- end
232
-
233
- context "fails when" do
234
- it "link does not exist" do
235
- @st.click_link("Bogus link").should be_false
236
- end
237
-
238
- it "link exists, but not within scope" do
239
- @st.click_link("About this site", :within => "footer").should be_false
240
- end
241
-
242
- it "link exists, but not in table row" do
243
- @st.visit("/table")
244
- @st.click_link("Edit", :in_row => "Ken").should be_false
245
- end
246
- end
247
- end
248
-
249
- describe "#link_exists" do
250
- context "passes when" do
251
- it "link with the given text exists" do
252
- @st.link_exists("About this site").should be_true
253
- @st.link_exists("Form test").should be_true
254
- end
255
-
256
- it "link with the given text exists within scope" do
257
- @st.link_exists("About this site", :within => "header").should be_true
258
- @st.link_exists("Form test", :within => "footer").should be_true
259
- @st.link_exists("Table test", :within => "footer").should be_true
260
- end
261
- end
262
-
263
- context "fails when" do
264
- it "no such link exists" do
265
- @st.link_exists("Welcome").should be_false
266
- @st.link_exists("Don't click here").should be_false
267
- end
268
-
269
- it "link exists, but not within scope" do
270
- @st.link_exists("About this site", :within => "footer").should be_false
271
- @st.link_exists("Form test", :within => "header").should be_false
272
- @st.link_exists("Table test", :within => "header").should be_false
273
- end
274
- end
275
- end
276
- end # links
277
-
278
-
279
- context "temporal visibility" do
280
- before(:each) do
281
- @st.visit("/slowtext").should be_true
282
- end
283
-
284
- describe "#see_within_seconds" do
285
- context "passes when" do
286
- it "text is already present" do
287
- @st.see("Late text page").should be_true
288
- @st.see_within_seconds("The text is coming...", 10).should be_true
289
- end
290
- it "text appears in time" do
291
- @st.see("The text is coming...").should be_true
292
- @st.do_not_see("The text is here!").should be_true
293
- @st.see_within_seconds("The text is here!", "10").should be_true
294
- @st.see("The text is here!").should be_true
295
- end
296
- it "text appears within default time" do
297
- @st.see("The text is coming...").should be_true
298
- @st.do_not_see("The text is here!").should be_true
299
- @st.see_within_seconds("The text is here!").should be_true
300
- @st.see("The text is here!").should be_true
301
- end
302
- end
303
-
304
- context "fails when" do
305
- it "text appears too late" do
306
- @st.see("The text is coming...").should be_true
307
- @st.do_not_see("The text is here!").should be_true
308
- @st.see_within_seconds("The text is here!", 1).should be_false
309
- end
310
- it "text never appears" do
311
- @st.see_within_seconds("Nonexistent", 5).should be_false
312
- end
313
- end
314
-
315
- it "is case-sensitive" do
316
- @st.see_within_seconds("The text is here!", 5).should be_true
317
- @st.see_within_seconds("The text IS HERE!", 5).should be_false
318
- end
319
- end
320
-
321
- describe "#do_not_see_within_seconds" do
322
- context "passes when" do
323
- it "text is already absent" do
324
- @st.see("Late text page").should be_true
325
- @st.do_not_see_within_seconds("Some absent text", 10).should be_true
326
- end
327
- it "text disappears in time" do
328
- @st.see_within_seconds("The text is here!", 10).should be_true
329
- @st.do_not_see_within_seconds("The text is here!", "10").should be_true
330
- @st.do_not_see("The text is here!").should be_true
331
- end
332
- it "text disappears within default time" do
333
- @st.see_within_seconds("The text is here!", 10).should be_true
334
- @st.do_not_see_within_seconds("The text is here!").should be_true
335
- @st.do_not_see("The text is here!").should be_true
336
- end
337
- end
338
-
339
- context "fails when" do
340
- it "text disappears too late" do
341
- @st.see_within_seconds("The text is here!", 10).should be_true
342
- @st.do_not_see_within_seconds("The text is here!", 1).should be_false
343
- end
344
- it "text never disappears" do
345
- @st.do_not_see_within_seconds("The text is coming...", 5).should be_false
346
- end
347
- end
348
- end
349
- end # temporal visibility
350
-
351
-
352
- context "conditionals" do
353
- before(:each) do
354
- @st.visit("/").should be_true
355
- end
356
-
357
- describe "#if_i_see" do
358
- context "passes when" do
359
- it "sees text" do
360
- @st.if_i_see("About this site").should be_true
361
- @st.click("About this site").should be_true
362
- @st.end_if.should be_true
363
- end
364
-
365
- it "is inside a passed block" do
366
- @st.if_i_see("About this site").should be_true
367
- @st.click("About this site").should be_true
368
- @st.page_loads_in_seconds_or_less(10).should be_true
369
- @st.if_i_see("This site is").should be_true
370
- @st.see("is really cool.").should be_true
371
- @st.end_if.should be_true
372
- @st.end_if.should be_true
373
- end
374
- end
375
-
376
- context "skips when" do
377
- it "does not see text" do
378
- @st.if_i_see("Bogus link").should be_nil
379
- @st.click("Bogus link").should be_nil
380
- @st.end_if.should be_true
381
- end
382
-
383
- it "is inside a skipped block" do
384
- @st.if_i_see("Bogus link").should be_nil
385
- @st.click("Bogus link").should be_nil
386
- @st.if_i_see("About this site").should be_nil
387
- @st.click("About this site").should be_nil
388
- @st.end_if.should be_nil
389
- @st.end_if.should be_true
390
- end
391
- end
392
- end
393
-
394
- describe "#if_parameter" do
395
- context "passes when" do
396
- it "sees yes" do
397
- @st.if_parameter("yes").should be_true
398
- @st.click("About this site").should be_true
399
- @st.end_if.should be_true
400
- end
401
-
402
- it "sees true" do
403
- @st.if_parameter("true").should be_true
404
- @st.click("About this site").should be_true
405
- @st.end_if.should be_true
406
- end
407
-
408
- it "sees YES" do
409
- @st.if_parameter("YES").should be_true
410
- @st.click("About this site").should be_true
411
- @st.end_if.should be_true
412
- end
413
-
414
- it "sees TRUE" do
415
- @st.if_parameter("TRUE").should be_true
416
- @st.click("About this site").should be_true
417
- @st.end_if.should be_true
418
- end
419
-
420
- it "is inside a passed block" do
421
- @st.if_i_see("About this site").should be_true
422
- @st.click("About this site").should be_true
423
- @st.page_loads_in_seconds_or_less(10).should be_true
424
- @st.if_parameter("True").should be_true
425
- @st.see("is really cool.").should be_true
426
- @st.end_if.should be_true
427
- @st.end_if.should be_true
428
- end
429
- end
430
-
431
- context "skips when" do
432
- it "sees something other than yes or true" do
433
- @st.if_parameter("Bogus").should be_nil
434
- @st.click("Bogus link").should be_nil
435
- @st.end_if.should be_true
436
- end
437
-
438
- it "is inside a skipped block" do
439
- @st.if_parameter("Bogus link").should be_nil
440
- @st.click("Bogus link").should be_nil
441
- @st.if_parameter("TRUE").should be_nil
442
- @st.click("About this site").should be_nil
443
- @st.end_if.should be_nil
444
- @st.end_if.should be_true
445
- end
446
- end
447
- end
448
-
449
- # TODO: if_is
450
- describe "#if_is" do
451
- context "passes when" do
452
- it "sees the same string" do
453
- @st.if_is("yes", 'yes').should be_true
454
- @st.click("About this site").should be_true
455
- @st.end_if.should be_true
456
- end
457
-
458
- it "sees a matching empty string" do
459
- @st.if_is("",'').should be_true
460
- @st.click("About this site").should be_true
461
- @st.end_if.should be_true
462
- end
463
-
464
- it "is inside a passed block" do
465
- @st.if_i_see("About this site").should be_true
466
- @st.click("About this site").should be_true
467
- @st.page_loads_in_seconds_or_less(10).should be_true
468
- @st.if_is("True", "True").should be_true
469
- @st.see("is really cool.").should be_true
470
- @st.end_if.should be_true
471
- @st.end_if.should be_true
472
- end
473
- end
474
-
475
- context "skips when" do
476
- it "sees different strings" do
477
- @st.if_is("Ken", "Bogus").should be_nil
478
- @st.click("Bogus link").should be_nil
479
- @st.end_if.should be_true
480
- end
481
-
482
- it "is inside a skipped block" do
483
- @st.if_is("Ken", "Bogus").should be_nil
484
- @st.click("Bogus link").should be_nil
485
- @st.if_is("True", "True").should be_nil
486
- @st.click("About this site").should be_nil
487
- @st.end_if.should be_nil
488
- @st.end_if.should be_true
489
- end
490
- end
491
- end
492
-
493
- describe "#otherwise" do
494
- context "skips when" do
495
- it "its if was true" do
496
- @st.if_i_see("About this site").should be_true
497
- @st.click("About this site").should be_true
498
- @st.otherwise.should be_nil
499
- @st.click("Bogus link").should be_nil
500
- @st.end_if.should be_true
501
- end
502
- end
503
- context "passes when" do
504
- it "its if was false" do
505
- @st.if_i_see("Bogus link").should be_nil
506
- @st.click("Bogus link").should be_nil
507
- @st.otherwise.should be_true
508
- @st.click("About this site").should be_true
509
- @st.end_if.should be_true
510
- end
511
- end
512
-
513
- context "fails when" do
514
- it "does not have a matching if" do
515
- @st.otherwise.should be_false
516
- end
517
- end
518
- end
519
-
520
- describe "#end_if" do
521
- context "fails when" do
522
- it "does not have a matching if" do
523
- @st.end_if.should be_false
524
- end
525
- end
526
- end
527
- end # conditionals
528
-
529
-
530
- context "buttons" do
531
- before(:each) do
532
- @st.visit("/form").should be_true
533
- end
534
-
535
- describe "#click_button" do
536
- context "passes when" do
537
- it "button exists and is enabled" do
538
- @st.click_button("Submit person form").should be_true
539
- end
540
-
541
- it "button exists within scope" do
542
- @st.click_button("Submit person form", :within => "person_form").should be_true
543
- end
544
-
545
- it "button exists in table row" do
546
- # TODO
547
- end
548
- end
549
-
550
- context "fails when" do
551
- it "button does not exist" do
552
- @st.click_button("No such button").should be_false
553
- end
554
-
555
- it "button exists, but not within scope" do
556
- @st.click_button("Submit person form", :within => "spouse_form").should be_false
557
- end
558
-
559
- it "button exists, but not in table row" do
560
- # TODO
561
- end
562
-
563
- it "button exists, but is read-only" do
564
- @st.visit("/readonly_form").should be_true
565
- @st.click_button("Submit person form").should be_false
566
- end
567
- end
568
- end
569
-
570
-
571
- describe "#button_exists" do
572
- context "passes when" do
573
- context "button with text" do
574
- it "exists" do
575
- @st.button_exists("Submit person form").should be_true
576
- @st.button_exists("Save preferences").should be_true
577
- end
578
-
579
- it "exists within scope" do
580
- @st.button_exists("Submit person form", :within => "person_form").should be_true
581
- @st.button_exists("Submit spouse form", :within => "spouse_form").should be_true
582
- end
583
-
584
- it "exists in table row" do
585
- # TODO
586
- end
587
- end
588
- end
589
-
590
- context "fails when" do
591
- it "no such button exists" do
592
- @st.button_exists("Apple").should be_false
593
- @st.button_exists("Big Red").should be_false
594
- end
595
-
596
- it "button exists, but not within scope" do
597
- @st.button_exists("Submit spouse form", :within => "person_form").should be_false
598
- @st.button_exists("Submit person form", :within => "spouse_form").should be_false
599
- end
600
-
601
- it "button exists, but not in table row" do
602
- # TODO
603
- end
604
- end
605
- end
606
- end # buttons
607
-
608
-
609
- context "fields" do
610
- before(:each) do
611
- @st.visit("/form").should be_true
612
- end
613
-
614
- describe "#type_into_field" do
615
- context "passes when" do
616
- context "text field with label" do
617
- it "exists" do
618
- @st.type_into_field("Eric", "First name").should be_true
619
- @st.fill_in_with("Last name", "Pierce").should be_true
620
- end
621
- it "exists within scope" do
622
- @st.type_into_field("Eric", "First name", :within => 'person_form').should be_true
623
- @st.type_into_field("Andrea", "First name", :within => 'spouse_form').should be_true
624
- end
625
- end
626
-
627
- context "text field with id" do
628
- it "exists" do
629
- @st.type_into_field("Eric", "first_name").should be_true
630
- @st.fill_in_with("last_name", "Pierce").should be_true
631
- end
632
- end
633
-
634
- context "textarea with label" do
635
- it "exists" do
636
- @st.type_into_field("Blah blah blah", "Life story").should be_true
637
- @st.fill_in_with("Life story", "Jibber jabber").should be_true
638
- end
639
- end
640
-
641
- context "textarea with id" do
642
- it "exists" do
643
- @st.type_into_field("Blah blah blah", "biography").should be_true
644
- @st.fill_in_with("biography", "Jibber jabber").should be_true
645
- end
646
- end
647
- end
648
-
649
- context "fails when" do
650
- it "no field with the given label or id exists" do
651
- @st.type_into_field("Matthew", "Middle name").should be_false
652
- @st.fill_in_with("middle_name", "Matthew").should be_false
653
- end
654
-
655
- it "field exists, but not within scope" do
656
- @st.type_into_field("Long story", "Life story",
657
- :within => 'spouse_form').should be_false
658
- end
659
-
660
- it "field exists, but is read-only" do
661
- @st.visit("/readonly_form").should be_true
662
- @st.type_into_field("Eric", "First name").should be_false
663
- end
664
- end
665
- end
666
-
667
- describe "#field_contains" do
668
- context "passes when" do
669
- context "text field with label" do
670
- it "equals the text" do
671
- @st.fill_in_with("First name", "Marcus")
672
- @st.field_contains("First name", "Marcus").should be_true
673
- end
674
-
675
- it "contains the text" do
676
- @st.fill_in_with("First name", "Marcus")
677
- @st.field_contains("First name", "Marc").should be_true
678
- end
679
- end
680
-
681
- context "textarea with label" do
682
- it "contains the text" do
683
- @st.fill_in_with("Life story", "Blah dee blah")
684
- @st.field_contains("Life story", "blah").should be_true
685
- end
686
- end
687
- end
688
-
689
- context "fails when" do
690
- context "text field with label" do
691
- it "does not exist" do
692
- @st.field_contains("Third name", "Smith").should be_false
693
- end
694
-
695
- it "does not contain the text" do
696
- @st.fill_in_with("First name", "Marcus")
697
- @st.field_contains("First name", "Eric").should be_false
698
- end
699
- end
700
-
701
- context "textarea with label" do
702
- it "does not contain the text" do
703
- @st.fill_in_with("Life story", "Blah dee blah")
704
- @st.field_contains("Life story", "spam").should be_false
705
- end
706
- end
707
- end
708
- end
709
-
710
- describe "#field_equals" do
711
- context "passes when" do
712
- context "text field with label" do
713
- it "equals the text" do
714
- @st.fill_in_with("First name", "Ken")
715
- @st.field_equals("First name", "Ken").should be_true
716
- end
717
-
718
- it "equals the text, and is within scope" do
719
- @st.fill_in_with("First name", "Eric", :within => "person_form")
720
- @st.field_equals("First name", "Eric", :within => "person_form")
721
- end
722
- end
723
-
724
- context "textarea with label" do
725
- it "equals the text" do
726
- @st.fill_in_with("Life story", "Blah dee blah")
727
- @st.field_equals("Life story", "Blah dee blah").should be_true
728
- end
729
-
730
- it "equals the text, and is within scope" do
731
- @st.fill_in_with("Life story", "Blah dee blah",
732
- :within => "person_form")
733
- @st.field_equals("Life story", "Blah dee blah",
734
- :within => "person_form").should be_true
735
- end
736
-
737
- it "equals the text, and is in table row" do
738
- # TODO
739
- end
740
- end
741
- end
742
-
743
- context "fails when" do
744
- context "text field with label" do
745
- it "does not exactly equal the text" do
746
- @st.fill_in_with("First name", "Marcus")
747
- @st.field_equals("First name", "Marc").should be_false
748
- end
749
- end
750
-
751
- context "textarea with label" do
752
- it "does not exist" do
753
- @st.field_equals("Third name", "Smith").should be_false
754
- end
755
-
756
- it "does not exactly equal the text" do
757
- @st.fill_in_with("Life story", "Blah dee blah")
758
- @st.field_equals("Life story", "Blah dee").should be_false
759
- end
760
-
761
- it "exactly equals the text, but is not within scope" do
762
- @st.fill_in_with("First name", "Eric", :within => "person_form")
763
- @st.field_equals("First name", "Eric", :within => "spouse_form").should be_false
764
- end
765
-
766
- it "exactly equals the text, but is not in table row" do
767
- # TODO
768
- end
769
- end
770
- end
771
- end
772
- end # fields
773
-
774
-
775
- context "checkboxes" do
776
- before(:each) do
777
- @st.visit("/form").should be_true
778
- end
779
-
780
- describe "#enable_checkbox" do
781
- context "passes when" do
782
- context "checkbox with label" do
783
- it "exists" do
784
- @st.enable_checkbox("I like cheese").should be_true
785
- @st.enable_checkbox("I like salami").should be_true
786
- end
787
-
788
- it "exists and is already checked" do
789
- @st.enable_checkbox("I like cheese")
790
- @st.enable_checkbox("I like cheese").should be_true
791
- end
792
-
793
- it "exists within scope" do
794
- @st.enable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
795
- @st.enable_checkbox("I like salami", :within => "salami_checkbox").should be_true
796
- end
797
-
798
- it "exists in table row" do
799
- @st.visit("/table")
800
- @st.enable_checkbox("Like", :in_row => "Marcus").should be_true
801
- end
802
- end
803
-
804
- context "checkbox with id=" do
805
- it "exists" do
806
- @st.enable_checkbox("id=like_cheese").should be_true
807
- end
808
- end
809
-
810
- context "checkbox with xpath=" do
811
- it "exists" do
812
- @st.enable_checkbox("xpath=//input[@id='like_cheese']").should be_true
813
- end
814
- end
815
- end
816
-
817
- context "fails when" do
818
- context "checkbox with label" do
819
- it "does not exist" do
820
- @st.enable_checkbox("I dislike bacon").should be_false
821
- @st.enable_checkbox("I like broccoli").should be_false
822
- end
823
-
824
- it "exists, but not within scope" do
825
- @st.enable_checkbox("I like cheese", :within => "salami_checkbox").should be_false
826
- @st.enable_checkbox("I like salami", :within => "cheese_checkbox").should be_false
827
- end
828
-
829
- it "exists, but not in table row" do
830
- @st.visit("/table")
831
- @st.enable_checkbox("Like", :in_row => "Eric").should be_false
832
- end
833
-
834
- it "exists, but is read-only" do
835
- @st.visit("/readonly_form").should be_true
836
- @st.enable_checkbox("I like salami").should be_false
837
- end
838
- end
839
- end
840
- end
841
-
842
- describe "#disable_checkbox" do
843
- context "passes when" do
844
- context "checkbox with label" do
845
- it "exists" do
846
- @st.disable_checkbox("I like cheese").should be_true
847
- @st.disable_checkbox("I like salami").should be_true
848
- end
849
-
850
- it "exists and is already unchecked" do
851
- @st.disable_checkbox("I like cheese")
852
- @st.disable_checkbox("I like cheese").should be_true
853
- end
854
-
855
- it "exists within scope" do
856
- @st.disable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
857
- @st.disable_checkbox("I like salami", :within => "preferences_form").should be_true
858
- end
859
-
860
- it "exists in table row" do
861
- @st.visit("/table")
862
- @st.disable_checkbox("Like", :in_row => "Marcus").should be_true
863
- end
864
- end
865
-
866
- context "checkbox with id=" do
867
- it "exists" do
868
- @st.disable_checkbox("id=like_cheese").should be_true
869
- end
870
- end
871
-
872
- context "checkbox with xpath=" do
873
- it "exists" do
874
- @st.disable_checkbox("xpath=//input[@id='like_cheese']").should be_true
875
- end
876
- end
877
- end
878
-
879
- context "fails when" do
880
- context "checkbox with label" do
881
- it "does not exist" do
882
- @st.disable_checkbox("I dislike bacon").should be_false
883
- @st.disable_checkbox("I like broccoli").should be_false
884
- end
885
-
886
- it "exists, but not within scope" do
887
- @st.disable_checkbox("I like cheese", :within => "salami_checkbox").should be_false
888
- @st.disable_checkbox("I like salami", :within => "cheese_checkbox").should be_false
889
- end
890
-
891
- it "exists, but not in table row" do
892
- @st.visit("/table")
893
- @st.disable_checkbox("Like", :in_row => "Eric").should be_false
894
- end
895
-
896
- it "exists, but is read-only" do
897
- @st.visit("/readonly_form").should be_true
898
- @st.disable_checkbox("I like cheese").should be_false
899
- end
900
- end
901
- end
902
- end
903
-
904
- describe "#checkbox_is_enabled" do
905
- context "passes when" do
906
- context "checkbox with label" do
907
- it "exists and is checked" do
908
- @st.enable_checkbox("I like cheese").should be_true
909
- @st.checkbox_is_enabled("I like cheese").should be_true
910
- end
911
-
912
- it "exists within scope and is checked" do
913
- @st.enable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
914
- @st.checkbox_is_enabled("I like cheese", :within => "cheese_checkbox").should be_true
915
- end
916
-
917
- it "exists in table row and is checked" do
918
- @st.visit("/table")
919
- @st.enable_checkbox("Like", :in_row => "Ken").should be_true
920
- @st.checkbox_is_enabled("Like", :in_row => "Ken").should be_true
921
- end
922
-
923
- it "exists and is checked, but read-only" do
924
- @st.visit("/readonly_form").should be_true
925
- @st.checkbox_is_enabled("I like cheese").should be_true
926
- end
927
- end
928
- end
929
-
930
- context "fails when" do
931
- context "checkbox with label" do
932
- it "does not exist" do
933
- @st.checkbox_is_enabled("I dislike bacon").should be_false
934
- end
935
-
936
- it "exists but is unchecked" do
937
- @st.disable_checkbox("I like cheese").should be_true
938
- @st.checkbox_is_enabled("I like cheese").should be_false
939
- end
940
-
941
- it "exists and is checked, but not within scope" do
942
- @st.enable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
943
- @st.checkbox_is_enabled("I like cheese", :within => "salami_checkbox").should be_false
944
- end
945
-
946
- it "exists and is checked, but not in table row" do
947
- @st.visit("/table")
948
- @st.enable_checkbox("Like", :in_row => "Marcus").should be_true
949
- @st.checkbox_is_enabled("Like", :in_row => "Eric").should be_false
950
- end
951
- end
952
- end
953
- end
954
-
955
- describe "#checkbox_is_disabled" do
956
- context "passes when" do
957
- context "checkbox with label" do
958
- it "exists and is unchecked" do
959
- @st.disable_checkbox("I like cheese").should be_true
960
- @st.checkbox_is_disabled("I like cheese").should be_true
961
- end
962
-
963
- it "exists within scope and is unchecked" do
964
- @st.disable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
965
- @st.checkbox_is_disabled("I like cheese", :within => "cheese_checkbox").should be_true
966
- end
967
-
968
- it "exists in table row and is unchecked" do
969
- @st.visit("/table")
970
- @st.disable_checkbox("Like", :in_row => "Ken").should be_true
971
- @st.checkbox_is_disabled("Like", :in_row => "Ken").should be_true
972
- end
973
-
974
- it "exists and is unchecked, but read-only" do
975
- @st.visit("/readonly_form").should be_true
976
- @st.checkbox_is_disabled("I like salami").should be_true
977
- end
978
- end
979
- end
980
-
981
- context "fails when" do
982
- context "checkbox with label" do
983
- it "does not exist" do
984
- @st.checkbox_is_disabled("I dislike bacon").should be_false
985
- end
986
-
987
- it "exists but is checked" do
988
- @st.enable_checkbox("I like cheese").should be_true
989
- @st.checkbox_is_disabled("I like cheese").should be_false
990
- end
991
-
992
- it "exists and is unchecked, but not within scope" do
993
- @st.disable_checkbox("I like cheese", :within => "cheese_checkbox").should be_true
994
- @st.checkbox_is_disabled("I like cheese", :within => "salami_checkbox").should be_false
995
- end
996
-
997
- it "exists and is unchecked, but not in table row" do
998
- @st.visit("/table")
999
- @st.disable_checkbox("Like", :in_row => "Marcus").should be_true
1000
- @st.checkbox_is_disabled("Like", :in_row => "Eric").should be_false
1001
- end
1002
- end
1003
- end
1004
- end
1005
- end # checkboxes
1006
-
1007
-
1008
- context "radiobuttons" do
1009
- before(:each) do
1010
- @st.visit("/form").should be_true
1011
- end
1012
-
1013
- context "#select_radio" do
1014
- context "passes when" do
1015
- context "radiobutton with label" do
1016
- it "exists" do
1017
- @st.select_radio("Briefs").should be_true
1018
- end
1019
-
1020
- it "exists within scope" do
1021
- @st.select_radio("Briefs", :within => "clothing").should be_true
1022
- end
1023
-
1024
- it "exists in table row" do
1025
- # TODO
1026
- end
1027
- end
1028
- end
1029
-
1030
- context "fails when" do
1031
- context "radiobutton with label" do
1032
- it "does not exist" do
1033
- @st.select_radio("Naked").should be_false
1034
- end
1035
-
1036
- it "exists, but not within scope" do
1037
- @st.select_radio("Briefs", :within => "food").should be_false
1038
- end
1039
-
1040
- it "exists, but is read-only" do
1041
- @st.visit("/readonly_form").should be_true
1042
- @st.select_radio("Boxers").should be_false
1043
- end
1044
-
1045
- it "exists, but not in table row" do
1046
- # TODO
1047
- end
1048
- end
1049
- end
1050
- end
1051
-
1052
- describe "#radio_is_enabled" do
1053
- context "passes when" do
1054
- context "radiobutton with label" do
1055
- it "exists, and is enabled" do
1056
- @st.select_radio("Briefs")
1057
- @st.radio_is_enabled("Briefs").should be_true
1058
- end
1059
-
1060
- it "exists within scope, and is enabled" do
1061
- @st.select_radio("Briefs", :within => "clothing")
1062
- @st.radio_is_enabled("Briefs", :within => "clothing").should be_true
1063
- end
1064
-
1065
- it "exists in table row, and is enabled" do
1066
- # TODO
1067
- end
1068
- end
1069
- end
1070
-
1071
- context "fails when" do
1072
- context "radiobutton with label" do
1073
- it "does not exist" do
1074
- @st.radio_is_enabled("Naked").should be_false
1075
- end
1076
-
1077
- it "exists, but is not enabled" do
1078
- @st.select_radio("Briefs")
1079
- @st.radio_is_enabled("Boxers").should be_false
1080
- end
1081
-
1082
- it "exists and is enabled, but not within scope" do
1083
- @st.select_radio("Briefs", :within => "clothing")
1084
- @st.radio_is_enabled("Briefs", :within => "food").should be_false
1085
- end
1086
- end
1087
- end
1088
- end
1089
-
1090
- describe "#radio_is_disabled" do
1091
- context "passes when" do
1092
- context "radiobutton with label" do
1093
- it "exists, and is disabled" do
1094
- @st.select_radio("Briefs")
1095
- @st.radio_is_disabled("Boxers").should be_true
1096
- end
1097
-
1098
- it "exists within scope, and is disabled" do
1099
- @st.select_radio("Briefs", :within => "clothing")
1100
- @st.radio_is_disabled("Boxers", :within => "clothing").should be_true
1101
- end
1102
-
1103
- it "exists in table row, and is disabled" do
1104
- # TODO
1105
- end
1106
- end
1107
- end
1108
-
1109
- context "fails when" do
1110
- context "radiobutton with label" do
1111
- it "does not exist" do
1112
- @st.radio_is_disabled("Naked").should be_false
1113
- end
1114
-
1115
- it "exists, but is enabled" do
1116
- @st.select_radio("Briefs")
1117
- @st.radio_is_disabled("Briefs").should be_false
1118
- end
1119
-
1120
- it "exists and is disabled, but not within scope" do
1121
- @st.select_radio("Briefs", :within => "clothing")
1122
- @st.radio_is_disabled("Briefs", :within => "food").should be_false
1123
- end
1124
- end
1125
- end
1126
- end
1127
- end # radiobuttons
1128
-
1129
-
1130
- context "dropdowns" do
1131
- before(:each) do
1132
- @st.visit("/form").should be_true
1133
- end
1134
-
1135
- context "#select_from_dropdown" do
1136
- context "passes when" do
1137
- it "option exists in the dropdown" do
1138
- @st.select_from_dropdown("Tall", "Height").should be_true
1139
- @st.select_from_dropdown("Medium", "Weight").should be_true
1140
- end
1141
-
1142
- it "option exists in the dropdown within scope" do
1143
- @st.select_from_dropdown("Tall", "Height", :within => "spouse_form").should be_true
1144
- end
1145
-
1146
- it "option exists in the dropdown in table row" do
1147
- @st.visit("/table")
1148
- @st.select_from_dropdown("Male", "Gender", :in_row => "Eric").should be_true
1149
- end
1150
- end
1151
-
1152
- context "fails when" do
1153
- it "no such dropdown exists" do
1154
- @st.select_from_dropdown("Over easy", "Eggs").should be_false
1155
- end
1156
-
1157
- it "dropdown exists, but the option doesn't" do
1158
- @st.select_from_dropdown("Giant", "Height").should be_false
1159
- @st.select_from_dropdown("Obese", "Weight").should be_false
1160
- end
1161
-
1162
- it "dropdown exists, but is read-only" do
1163
- @st.visit("/readonly_form").should be_true
1164
- @st.select_from_dropdown("Tall", "Height").should be_false
1165
- end
1166
-
1167
- it "dropdown exists, but not within scope" do
1168
- @st.select_from_dropdown("Medium", "Weight", :within => "spouse_form").should be_false
1169
- end
1170
-
1171
- it "dropdown exists, but not in table row" do
1172
- @st.visit("/table")
1173
- @st.select_from_dropdown("Female", "Gender", :in_row => "First name").should be_false
1174
- end
1175
- end
1176
- end
1177
-
1178
- context "#dropdown_includes" do
1179
- context "passes when" do
1180
- it "option exists in the dropdown" do
1181
- @st.dropdown_includes("Height", "Tall").should be_true
1182
- @st.dropdown_includes("Weight", "Medium").should be_true
1183
- end
1184
-
1185
- it "option exists in a read-only dropdown" do
1186
- @st.visit("/readonly_form").should be_true
1187
- @st.dropdown_includes("Height", "Tall").should be_true
1188
- end
1189
- end
1190
-
1191
- context "fails when" do
1192
- it "dropdown exists, but the option doesn't" do
1193
- @st.dropdown_includes("Height", "Giant").should be_false
1194
- @st.dropdown_includes("Weight", "Obese").should be_false
1195
- end
1196
-
1197
- it "no such dropdown exists" do
1198
- @st.dropdown_includes("Eggs", "Over easy").should be_false
1199
- end
1200
- end
1201
- end
1202
-
1203
- context "#dropdown_equals" do
1204
- context "passes when" do
1205
- it "option is selected in the dropdown" do
1206
- ["Short", "Average", "Tall"].each do |height|
1207
- @st.select_from_dropdown(height, "Height")
1208
- @st.dropdown_equals("Height", height).should be_true
1209
- end
1210
- end
1211
-
1212
- it "option is selected in a read-only dropdown" do
1213
- @st.visit("/readonly_form").should be_true
1214
- @st.dropdown_equals("Height", "Average").should be_true
1215
- end
1216
-
1217
- it "option is selected in the dropdown, within scope" do
1218
- ["Short", "Average", "Tall"].each do |height|
1219
- @st.select_from_dropdown(height, "Height", :within => "spouse_form")
1220
- @st.dropdown_equals("Height", height, :within => "spouse_form").should be_true
1221
- end
1222
- end
1223
-
1224
- it "option is selected in the dropdown, in table row" do
1225
- @st.visit("/table")
1226
- ["Male", "Female"].each do |gender|
1227
- @st.select_from_dropdown(gender, "Gender", :in_row => "Eric")
1228
- @st.dropdown_equals("Gender", gender, :in_row => "Eric")
1229
- end
1230
- end
1231
- end
1232
-
1233
- context "fails when" do
1234
- it "no such dropdown exists" do
1235
- @st.dropdown_equals("Eggs", "Over easy").should be_false
1236
- end
1237
-
1238
- it "dropdown exists, but the option is not selected" do
1239
- @st.select_from_dropdown("Short", "Height")
1240
- @st.dropdown_equals("Height", "Average").should be_false
1241
- @st.dropdown_equals("Height", "Tall").should be_false
1242
-
1243
- @st.select_from_dropdown("Average", "Height")
1244
- @st.dropdown_equals("Height", "Short").should be_false
1245
- @st.dropdown_equals("Height", "Tall").should be_false
1246
-
1247
- @st.select_from_dropdown("Tall", "Height")
1248
- @st.dropdown_equals("Height", "Short").should be_false
1249
- @st.dropdown_equals("Height", "Average").should be_false
1250
- end
1251
-
1252
- it "dropdown exists, and option is selected, but not within scope" do
1253
- @st.select_from_dropdown("Tall", "Height", :within => "person_form")
1254
- @st.select_from_dropdown("Short", "Height", :within => "spouse_form")
1255
- @st.dropdown_equals("Height", "Tall", :within => "spouse_form").should be_false
1256
- end
1257
-
1258
- it "dropdown exists, and option is selected, but not in table row" do
1259
- @st.visit("/table")
1260
- @st.select_from_dropdown("Female", "Gender", :in_row => "Eric")
1261
- @st.select_from_dropdown("Male", "Gender", :in_row => "Marcus")
1262
- @st.dropdown_equals("Gender", "Female", :in_row => "Marcus").should be_false
1263
- end
1264
- end
1265
- end
1266
- end # dropdowns
1267
-
1268
- # The same field operations, but with the generic set_field function...
1269
- context "generic_fields" do
1270
- # TODO: Remove entries that don't use "set_field" in the next 600 or so lines.
1271
- describe "#set_field" do
1272
- context "fields" do
1273
- before(:each) do
1274
- @st.visit("/form").should be_true
1275
- end
1276
-
1277
- context "#set_field with #type_into_field" do
1278
- context "passes when" do
1279
- context "text field with label" do
1280
- it "exists" do
1281
- @st.set_field("First name", "Eric").should be_true
1282
- @st.set_field("Last name", "Pierce").should be_true
1283
- end
1284
- it "exists within scope" do
1285
- @st.set_field("First name", "Eric", :within => 'person_form').should be_true
1286
- @st.set_field("First name", "Andrea", :within => 'spouse_form').should be_true
1287
- end
1288
- end
1289
-
1290
- context "text field with id" do
1291
- it "exists" do
1292
- @st.set_field("first_name", "Eric").should be_true
1293
- @st.set_field("last_name", "Pierce").should be_true
1294
- end
1295
- end
1296
-
1297
- context "textarea with label" do
1298
- it "exists" do
1299
- @st.set_field("Life story", "Blah blah blah").should be_true
1300
- @st.set_field("Life story", "Jibber jabber").should be_true
1301
- end
1302
- end
1303
-
1304
- context "textarea with id" do
1305
- it "exists" do
1306
- @st.set_field("biography", "Blah blah blah").should be_true
1307
- @st.set_field("biography", "Jibber jabber").should be_true
1308
- end
1309
- end
1310
- end
1311
-
1312
- context "fails when" do
1313
- it "no field with the given label or id exists" do
1314
- @st.set_field("Middle name", "Matthew").should be_false
1315
- @st.set_field("middle_name", "Matthew").should be_false
1316
- end
1317
-
1318
- it "field exists, but not within scope" do
1319
- @st.set_field("Life story", "Long story",
1320
- :within => 'spouse_form').should be_false
1321
- end
1322
-
1323
- it "field exists, but is read-only" do
1324
- @st.visit("/readonly_form").should be_true
1325
- @st.set_field("First name", "Eric").should be_false
1326
- end
1327
- end
1328
- end
1329
-
1330
- context "#set_field with #field_contains" do
1331
- context "passes when" do
1332
- context "text field with label" do
1333
- it "equals the text" do
1334
- @st.set_field("First name", "Marcus")
1335
- @st.field_contains("First name", "Marcus").should be_true
1336
- end
1337
-
1338
- it "contains the text" do
1339
- @st.set_field("First name", "Marcus")
1340
- @st.field_contains("First name", "Marc").should be_true
1341
- end
1342
- end
1343
-
1344
- context "textarea with label" do
1345
- it "contains the text" do
1346
- @st.set_field("Life story", "Blah dee blah")
1347
- @st.field_contains("Life story", "blah").should be_true
1348
- end
1349
- end
1350
- end
1351
-
1352
- context "fails when" do
1353
- context "text field with label" do
1354
- it "does not contain the text" do
1355
- @st.set_field("First name", "Marcus")
1356
- @st.field_contains("First name", "Eric").should be_false
1357
- end
1358
- end
1359
-
1360
- context "textarea with label" do
1361
- it "does not contain the text" do
1362
- @st.set_field("Life story", "Blah dee blah")
1363
- @st.field_contains("Life story", "spam").should be_false
1364
- end
1365
- end
1366
- end
1367
- end
1368
-
1369
- context "#set_field with #generic_field_equals" do
1370
- context "passes when" do
1371
- context "text field with label" do
1372
- it "equals the text" do
1373
- @st.set_field("First name", "Ken")
1374
- @st.generic_field_equals("First name", "Ken").should be_true
1375
- end
1376
-
1377
- it "equals the text, and is within scope" do
1378
- @st.set_field("First name", "Eric", :within => "person_form")
1379
- @st.generic_field_equals("First name", "Eric", :within => "person_form")
1380
- end
1381
- end
1382
-
1383
- context "textarea with label" do
1384
- it "equals the text" do
1385
- @st.set_field("Life story", "Blah dee blah")
1386
- @st.generic_field_equals("Life story", "Blah dee blah").should be_true
1387
- end
1388
-
1389
- it "equals the text, and is within scope" do
1390
- @st.set_field("Life story", "Blah dee blah",
1391
- :within => "person_form")
1392
- @st.generic_field_equals("Life story", "Blah dee blah",
1393
- :within => "person_form").should be_true
1394
- end
1395
-
1396
- it "equals the text, and is in table row" do
1397
- # TODO
1398
- end
1399
- end
1400
- end
1401
-
1402
- context "fails when" do
1403
- context "text field with label" do
1404
- it "does not exactly equal the text" do
1405
- @st.set_field("First name", "Marcus")
1406
- @st.generic_field_equals("First name", "Marc").should be_false
1407
- end
1408
- end
1409
-
1410
- context "textarea with label" do
1411
- it "does not exist" do
1412
- @st.generic_field_equals("Third name", "Smith").should be_false
1413
- end
1414
-
1415
- it "does not exactly equal the text" do
1416
- @st.set_field("Life story", "Blah dee blah")
1417
- @st.generic_field_equals("Life story", "Blah dee").should be_false
1418
- end
1419
-
1420
- it "exactly equals the text, but is not within scope" do
1421
- @st.set_field("First name", "Eric", :within => "person_form")
1422
- @st.generic_field_equals("First name", "Eric", :within => "spouse_form").should be_false
1423
- end
1424
-
1425
- it "exactly equals the text, but is not in table row" do
1426
- # TODO
1427
- end
1428
- end
1429
- end
1430
- end
1431
- end # fields
1432
-
1433
-
1434
- context "checkboxes" do
1435
- before(:each) do
1436
- @st.visit("/form").should be_true
1437
- end
1438
-
1439
- context "#set_field with #enable_checkbox" do
1440
- context "passes when" do
1441
- context "checkbox with label" do
1442
- it "exists" do
1443
- @st.set_field("I like cheese", "on").should be_true
1444
- @st.set_field("I like salami", "on").should be_true
1445
- @st.generic_field_equals("I like cheese", "on").should be_true
1446
- @st.generic_field_equals("I like salami", "on").should be_true
1447
- end
1448
-
1449
- it "exists and is already checked" do
1450
- @st.set_field("I like cheese", "on").should be_true
1451
- @st.set_field("I like cheese", "on").should be_true
1452
- @st.generic_field_equals("I like cheese", "on").should be_true
1453
- end
1454
-
1455
- it "exists within scope" do
1456
- @st.set_field("I like cheese", "on", :within => "cheese_checkbox").should be_true
1457
- @st.set_field("I like salami", "on", :within => "salami_checkbox").should be_true
1458
- @st.generic_field_equals("I like cheese", "on", :within => "cheese_checkbox").should be_true
1459
- @st.generic_field_equals("I like salami", "on", :within => "salami_checkbox").should be_true
1460
- end
1461
-
1462
- it "exists in table row" do
1463
- @st.visit("/table")
1464
- @st.set_field("Like", "on", :in_row => "Marcus").should be_true
1465
- @st.generic_field_equals("Like", "on", :in_row => "Marcus").should be_true
1466
- end
1467
- end
1468
-
1469
- context "checkbox with id=" do
1470
- it "exists" do
1471
- @st.set_field("id=like_cheese", "on").should be_true
1472
- @st.generic_field_equals("id=like_cheese", "on").should be_true
1473
- end
1474
- end
1475
-
1476
- context "checkbox with xpath=" do
1477
- it "exists" do
1478
- @st.set_field("xpath=//input[@id='like_cheese']", "on").should be_true
1479
- @st.generic_field_equals("xpath=//input[@id='like_cheese']", "on").should be_true
1480
- end
1481
- end
1482
- end
1483
-
1484
- context "fails when" do
1485
- context "checkbox with label" do
1486
- it "does not exist" do
1487
- @st.set_field("I dislike bacon", "on").should be_false
1488
- @st.set_field("I like broccoli", "on").should be_false
1489
- end
1490
-
1491
- it "exists, but not within scope" do
1492
- @st.set_field("I like cheese", "on", :within => "salami_checkbox").should be_false
1493
- @st.set_field("I like salami", "on", :within => "cheese_checkbox").should be_false
1494
- end
1495
-
1496
- it "exists, but not in table row" do
1497
- @st.visit("/table")
1498
- @st.set_field("Like", "on", :in_row => "Eric").should be_false
1499
- end
1500
-
1501
- it "exists, but is read-only" do
1502
- @st.visit("/readonly_form").should be_true
1503
- @st.set_field("I like salami", "on").should be_false
1504
- end
1505
- end
1506
- end
1507
- end
1508
-
1509
- context "#set_field with #disable_checkbox" do
1510
- context "passes when" do
1511
- context "checkbox with label" do
1512
- it "exists" do
1513
- @st.set_field("I like cheese", "off").should be_true
1514
- @st.set_field("I like salami", "off").should be_true
1515
- @st.generic_field_equals("I like cheese", "off").should be_true
1516
- @st.generic_field_equals("I like salami", "off").should be_true
1517
- end
1518
-
1519
- it "exists and is already unchecked" do
1520
- @st.set_field("I like cheese", "off").should be_true
1521
- @st.set_field("I like cheese", "off").should be_true
1522
- @st.generic_field_equals("I like cheese", "off").should be_true
1523
- end
1524
-
1525
- it "exists within scope" do
1526
- @st.set_field("I like cheese", "off", :within => "cheese_checkbox").should be_true
1527
- @st.set_field("I like salami", "off", :within => "preferences_form").should be_true
1528
- @st.generic_field_equals("I like cheese", "off", :within => "cheese_checkbox").should be_true
1529
- @st.generic_field_equals("I like salami", "off", :within => "preferences_form").should be_true
1530
- end
1531
-
1532
- it "exists in table row" do
1533
- @st.visit("/table")
1534
- @st.set_field("Like", "off", :in_row => "Marcus").should be_true
1535
- @st.generic_field_equals("Like", "off", :in_row => "Marcus").should be_true
1536
- end
1537
- end
1538
-
1539
- context "checkbox with id=" do
1540
- it "exists" do
1541
- @st.set_field("id=like_cheese", "off").should be_true
1542
- @st.generic_field_equals("id=like_cheese", "off").should be_true
1543
- end
1544
- end
1545
-
1546
- context "checkbox with xpath=" do
1547
- it "exists" do
1548
- @st.set_field("xpath=//input[@id='like_cheese']", "off").should be_true
1549
- @st.generic_field_equals("xpath=//input[@id='like_cheese']", "off").should be_true
1550
- end
1551
- end
1552
- end
1553
-
1554
- context "fails when" do
1555
- context "checkbox with label" do
1556
- it "does not exist" do
1557
- @st.set_field("I dislike bacon", "off").should be_false
1558
- @st.set_field("I like broccoli", "off").should be_false
1559
- end
1560
-
1561
- it "exists, but not within scope" do
1562
- @st.set_field("I like cheese", "off", :within => "salami_checkbox").should be_false
1563
- @st.set_field("I like salami", "off", :within => "cheese_checkbox").should be_false
1564
- end
1565
-
1566
- it "exists, but not in table row" do
1567
- @st.visit("/table")
1568
- @st.set_field("Like", "off", :in_row => "Eric").should be_false
1569
- end
1570
-
1571
- it "exists, but is read-only" do
1572
- @st.visit("/readonly_form").should be_true
1573
- @st.set_field("I like cheese", "off").should be_false
1574
- end
1575
- end
1576
- end
1577
- end
1578
-
1579
- context "#set_field with #checkbox_is_enabled" do
1580
- context "passes when" do
1581
- context "checkbox with label" do
1582
- it "exists and is checked" do
1583
- @st.set_field("I like cheese", "on").should be_true
1584
- @st.checkbox_is_enabled("I like cheese").should be_true
1585
- end
1586
-
1587
- it "exists within scope and is checked" do
1588
- @st.set_field("I like cheese", "on", :within => "cheese_checkbox").should be_true
1589
- @st.checkbox_is_enabled("I like cheese", :within => "cheese_checkbox").should be_true
1590
- end
1591
-
1592
- it "exists in table row and is checked" do
1593
- @st.visit("/table")
1594
- @st.set_field("Like", "on", :in_row => "Ken").should be_true
1595
- @st.checkbox_is_enabled("Like", :in_row => "Ken").should be_true
1596
- end
1597
-
1598
- it "exists and is checked, but read-only" do
1599
- @st.visit("/readonly_form").should be_true
1600
- @st.checkbox_is_enabled("I like cheese").should be_true
1601
- end
1602
- end
1603
- end
1604
-
1605
- context "fails when" do
1606
- context "checkbox with label" do
1607
- it "does not exist" do
1608
- @st.checkbox_is_enabled("I dislike bacon").should be_false
1609
- end
1610
-
1611
- it "exists but is unchecked" do
1612
- @st.set_field("I like cheese", "off").should be_true
1613
- @st.checkbox_is_enabled("I like cheese").should be_false
1614
- end
1615
-
1616
- it "exists and is checked, but not within scope" do
1617
- @st.set_field("I like cheese", "on", :within => "cheese_checkbox").should be_true
1618
- @st.checkbox_is_enabled("I like cheese", :within => "salami_checkbox").should be_false
1619
- end
1620
-
1621
- it "exists and is checked, but not in table row" do
1622
- @st.visit("/table")
1623
- @st.set_field("Like", "on", :in_row => "Marcus").should be_true
1624
- @st.checkbox_is_enabled("Like", :in_row => "Eric").should be_false
1625
- end
1626
- end
1627
- end
1628
- end
1629
-
1630
- context "#set_field with #checkbox_is_disabled" do
1631
- context "passes when" do
1632
- context "checkbox with label" do
1633
- it "exists and is unchecked" do
1634
- @st.set_field("I like cheese", "off").should be_true
1635
- @st.checkbox_is_disabled("I like cheese").should be_true
1636
- end
1637
-
1638
- it "exists within scope and is unchecked" do
1639
- @st.set_field("I like cheese", "off", :within => "cheese_checkbox").should be_true
1640
- @st.checkbox_is_disabled("I like cheese", :within => "cheese_checkbox").should be_true
1641
- end
1642
-
1643
- it "exists in table row and is unchecked" do
1644
- @st.visit("/table")
1645
- @st.set_field("Like", "off", :in_row => "Ken").should be_true
1646
- @st.checkbox_is_disabled("Like", :in_row => "Ken").should be_true
1647
- end
1648
-
1649
- it "exists and is unchecked, but read-only" do
1650
- @st.visit("/readonly_form").should be_true
1651
- @st.checkbox_is_disabled("I like salami").should be_true
1652
- end
1653
- end
1654
- end
1655
-
1656
- context "fails when" do
1657
- context "checkbox with label" do
1658
- it "does not exist" do
1659
- @st.checkbox_is_disabled("I dislike bacon").should be_false
1660
- end
1661
-
1662
- it "exists but is checked" do
1663
- @st.set_field("I like cheese", "on").should be_true
1664
- @st.checkbox_is_disabled("I like cheese").should be_false
1665
- end
1666
-
1667
- it "exists and is unchecked, but not within scope" do
1668
- @st.set_field("I like cheese", "off", :within => "cheese_checkbox").should be_true
1669
- @st.checkbox_is_disabled("I like cheese", :within => "salami_checkbox").should be_false
1670
- end
1671
-
1672
- it "exists and is unchecked, but not in table row" do
1673
- @st.visit("/table")
1674
- @st.set_field("Like", "off", :in_row => "Marcus").should be_true
1675
- @st.checkbox_is_disabled("Like", :in_row => "Eric").should be_false
1676
- end
1677
- end
1678
- end
1679
- end
1680
- end # checkboxes
1681
-
1682
-
1683
- context "radiobuttons" do
1684
- before(:each) do
1685
- @st.visit("/form").should be_true
1686
- end
1687
-
1688
- context "#set_field with #select_radio" do
1689
- context "passes when" do
1690
- context "radiobutton with label" do
1691
- it "exists" do
1692
- @st.set_field("Briefs").should be_true
1693
- end
1694
-
1695
- it "exists within scope" do
1696
- @st.set_field("Briefs", "", :within => "clothing").should be_true
1697
- end
1698
-
1699
- it "exists in table row" do
1700
- # TODO
1701
- end
1702
- end
1703
- end
1704
-
1705
- context "fails when" do
1706
- context "radiobutton with label" do
1707
- it "does not exist" do
1708
- @st.set_field("Naked", "").should be_false
1709
- end
1710
-
1711
- it "exists, but not within scope" do
1712
- @st.set_field("Briefs", "", :within => "food").should be_false
1713
- end
1714
-
1715
- it "exists, but is read-only" do
1716
- @st.visit("/readonly_form").should be_true
1717
- @st.set_field("Boxers", "").should be_false
1718
- end
1719
-
1720
- it "exists, but not in table row" do
1721
- # TODO
1722
- end
1723
- end
1724
- end
1725
- end
1726
-
1727
- context "#set_field with #radio_is_enabled" do
1728
- context "passes when" do
1729
- context "radiobutton with label" do
1730
- it "exists, and is enabled" do
1731
- @st.set_field("Briefs")
1732
- @st.radio_is_enabled("Briefs").should be_true
1733
- end
1734
-
1735
- it "exists within scope, and is enabled" do
1736
- @st.set_field("Briefs", "", :within => "clothing")
1737
- @st.radio_is_enabled("Briefs", :within => "clothing").should be_true
1738
- end
1739
-
1740
- it "exists in table row, and is enabled" do
1741
- # TODO
1742
- end
1743
- end
1744
- end
1745
-
1746
- context "fails when" do
1747
- context "radiobutton with label" do
1748
- it "does not exist" do
1749
- @st.radio_is_enabled("Naked").should be_false
1750
- end
1751
-
1752
- it "exists, but is not enabled" do
1753
- @st.set_field("Briefs", "")
1754
- @st.radio_is_enabled("Boxers").should be_false
1755
- end
1756
-
1757
- it "exists and is enabled, but not within scope" do
1758
- @st.set_field("Briefs", "", :within => "clothing")
1759
- @st.radio_is_enabled("Briefs", :within => "food").should be_false
1760
- end
1761
- end
1762
- end
1763
-
1764
- context "#set_field with #generic_field_equals for #radio_is_enabled" do
1765
- context "passes when" do
1766
- context "radiobutton with label" do
1767
- it "exists, and is enabled" do
1768
- @st.set_field("Briefs")
1769
- @st.generic_field_equals("Briefs", "on").should be_true
1770
- end
1771
-
1772
- it "exists within scope, and is enabled" do
1773
- @st.set_field("Briefs", "", :within => "clothing")
1774
- @st.generic_field_equals("Briefs", "on", :within => "clothing").should be_true
1775
- end
1776
-
1777
- it "exists in table row, and is enabled" do
1778
- # TODO
1779
- end
1780
- end
1781
- end
1782
-
1783
- context "fails when" do
1784
- context "radiobutton with label" do
1785
- it "does not exist" do
1786
- @st.generic_field_equals("Naked", "on").should be_false
1787
- end
1788
-
1789
- it "exists, but is not enabled" do
1790
- @st.set_field("Briefs", "")
1791
- @st.generic_field_equals("Boxers", "on").should be_false
1792
- end
1793
-
1794
- it "exists and is enabled, but not within scope" do
1795
- @st.set_field("Briefs", "", :within => "clothing")
1796
- @st.generic_field_equals("Briefs", "on", :within => "food").should be_false
1797
- end
1798
- end
1799
- end
1800
- end
1801
- end # radiobuttons
1802
-
1803
-
1804
- context "dropdowns" do
1805
- before(:each) do
1806
- @st.visit("/form").should be_true
1807
- end
1808
-
1809
- context "#set_field with #select_from_dropdown" do
1810
- context "passes when" do
1811
- it "option exists in the dropdown" do
1812
- @st.set_field("Height", "Tall").should be_true
1813
- @st.set_field("Weight", "Medium").should be_true
1814
- end
1815
-
1816
- it "option exists in the dropdown within scope" do
1817
- @st.set_field("Height", "Tall", :within => "spouse_form").should be_true
1818
- end
1819
-
1820
- it "option exists in the dropdown in table row" do
1821
- @st.visit("/table")
1822
- @st.set_field("Gender", "Male", :in_row => "Eric").should be_true
1823
- end
1824
- end
1825
-
1826
- context "fails when" do
1827
- it "no such dropdown exists" do
1828
- @st.set_field("Eggs", "Over easy").should be_false
1829
- end
1830
-
1831
- it "dropdown exists, but the option doesn't" do
1832
- @st.set_field("Height", "Giant").should be_false
1833
- @st.set_field("Weight", "Obese").should be_false
1834
- end
1835
-
1836
- it "dropdown exists, but is read-only" do
1837
- @st.visit("/readonly_form").should be_true
1838
- @st.set_field("Height", "Tall").should be_false
1839
- end
1840
-
1841
- it "dropdown exists, but not within scope" do
1842
- @st.set_field("Weight", "Medium", :within => "spouse_form").should be_false
1843
- end
1844
-
1845
- it "dropdown exists, but not in table row" do
1846
- @st.visit("/table")
1847
- @st.set_field("Gender", "Female", :in_row => "First name").should be_false
1848
- end
1849
- end
1850
- end
1851
-
1852
- context "#set_field with #dropdown_includes" do
1853
- context "passes when" do
1854
- it "option exists in the dropdown" do
1855
- @st.dropdown_includes("Height", "Tall").should be_true
1856
- @st.dropdown_includes("Weight", "Medium").should be_true
1857
- end
1858
-
1859
- it "option exists in a read-only dropdown" do
1860
- @st.visit("/readonly_form").should be_true
1861
- @st.dropdown_includes("Height", "Tall").should be_true
1862
- end
1863
- end
1864
-
1865
- context "fails when" do
1866
- it "dropdown exists, but the option doesn't" do
1867
- @st.dropdown_includes("Height", "Giant").should be_false
1868
- @st.dropdown_includes("Weight", "Obese").should be_false
1869
- end
1870
-
1871
- it "no such dropdown exists" do
1872
- @st.dropdown_includes("Eggs", "Over easy").should be_false
1873
- end
1874
- end
1875
- end
1876
-
1877
- context "#set_field with #dropdown_equals" do
1878
- context "passes when" do
1879
- it "option is selected in the dropdown" do
1880
- ["Short", "Average", "Tall"].each do |height|
1881
- @st.set_field("Height", height)
1882
- @st.dropdown_equals("Height", height).should be_true
1883
- end
1884
- end
1885
-
1886
- it "option is selected in a read-only dropdown" do
1887
- @st.visit("/readonly_form").should be_true
1888
- @st.dropdown_equals("Height", "Average").should be_true
1889
- end
1890
-
1891
- it "option is selected in the dropdown, within scope" do
1892
- ["Short", "Average", "Tall"].each do |height|
1893
- @st.set_field("Height", height, :within => "spouse_form")
1894
- @st.dropdown_equals("Height", height, :within => "spouse_form").should be_true
1895
- end
1896
- end
1897
-
1898
- it "option is selected in the dropdown, in table row" do
1899
- @st.visit("/table")
1900
- ["Male", "Female"].each do |gender|
1901
- @st.set_field("Gender", gender, :in_row => "Eric")
1902
- @st.dropdown_equals("Gender", gender, :in_row => "Eric")
1903
- end
1904
- end
1905
- end
1906
-
1907
- context "fails when" do
1908
- it "no such dropdown exists" do
1909
- @st.dropdown_equals("Eggs", "Over easy").should be_false
1910
- end
1911
-
1912
- it "dropdown exists, but the option is not selected" do
1913
- @st.set_field("Height", "Short")
1914
- @st.dropdown_equals("Height", "Average").should be_false
1915
- @st.dropdown_equals("Height", "Tall").should be_false
1916
-
1917
- @st.set_field("Height", "Average")
1918
- @st.dropdown_equals("Height", "Short").should be_false
1919
- @st.dropdown_equals("Height", "Tall").should be_false
1920
-
1921
- @st.set_field("Height", "Tall")
1922
- @st.dropdown_equals("Height", "Short").should be_false
1923
- @st.dropdown_equals("Height", "Average").should be_false
1924
- end
1925
-
1926
- it "dropdown exists, and option is selected, but not within scope" do
1927
- @st.set_field("Height", "Tall", :within => "person_form")
1928
- @st.set_field("Height", "Short", :within => "spouse_form")
1929
- @st.dropdown_equals("Height", "Tall", :within => "spouse_form").should be_false
1930
- end
1931
-
1932
- it "dropdown exists, and option is selected, but not in table row" do
1933
- @st.visit("/table")
1934
- @st.set_field("Gender", "Female", :in_row => "Eric")
1935
- @st.set_field("Gender", "Male", :in_row => "Marcus")
1936
- @st.dropdown_equals("Gender", "Female", :in_row => "Marcus").should be_false
1937
- end
1938
- end
1939
- end
1940
-
1941
- context "#set_field with #generic_field_equals for #dropdown_equals" do
1942
- context "passes when" do
1943
- it "option is selected in the dropdown" do
1944
- ["Short", "Average", "Tall"].each do |height|
1945
- @st.set_field("Height", height)
1946
- @st.generic_field_equals("Height", height).should be_true
1947
- end
1948
- end
1949
-
1950
- it "option is selected in a read-only dropdown" do
1951
- @st.visit("/readonly_form").should be_true
1952
- @st.generic_field_equals("Height", "Average").should be_true
1953
- end
1954
-
1955
- it "option is selected in the dropdown, within scope" do
1956
- ["Short", "Average", "Tall"].each do |height|
1957
- @st.set_field("Height", height, :within => "spouse_form")
1958
- @st.generic_field_equals("Height", height, :within => "spouse_form").should be_true
1959
- end
1960
- end
1961
-
1962
- it "option is selected in the dropdown, in table row" do
1963
- @st.visit("/table")
1964
- ["Male", "Female"].each do |gender|
1965
- @st.set_field("Gender", gender, :in_row => "Eric")
1966
- @st.generic_field_equals("Gender", gender, :in_row => "Eric")
1967
- end
1968
- end
1969
- end
1970
-
1971
- context "fails when" do
1972
- it "no such dropdown exists" do
1973
- @st.generic_field_equals("Eggs", "Over easy").should be_false
1974
- end
1975
-
1976
- it "dropdown exists, but the option is not selected" do
1977
- @st.set_field("Height", "Short")
1978
- @st.generic_field_equals("Height", "Average").should be_false
1979
- @st.generic_field_equals("Height", "Tall").should be_false
1980
-
1981
- @st.set_field("Height", "Average")
1982
- @st.generic_field_equals("Height", "Short").should be_false
1983
- @st.generic_field_equals("Height", "Tall").should be_false
1984
-
1985
- @st.set_field("Height", "Tall")
1986
- @st.generic_field_equals("Height", "Short").should be_false
1987
- @st.generic_field_equals("Height", "Average").should be_false
1988
- end
1989
-
1990
- it "dropdown exists, and option is selected, but not within scope" do
1991
- @st.set_field("Height", "Tall", :within => "person_form")
1992
- @st.set_field("Height", "Short", :within => "spouse_form")
1993
- @st.generic_field_equals("Height", "Tall", :within => "spouse_form").should be_false
1994
- end
1995
-
1996
- it "dropdown exists, and option is selected, but not in table row" do
1997
- @st.visit("/table")
1998
- @st.set_field("Gender", "Female", :in_row => "Eric")
1999
- @st.set_field("Gender", "Male", :in_row => "Marcus")
2000
- @st.generic_field_equals("Gender", "Female", :in_row => "Marcus").should be_false
2001
- end
2002
- end
2003
- end
2004
- end # dropdowns
2005
- end # set_field
2006
-
2007
-
2008
- # TODO: Add test cases with scopes to the next three functions described.
2009
- describe "#set_field_among" do
2010
- before(:each) do
2011
- @st.visit("/form").should be_true
2012
- end
2013
- context "passes when" do
2014
- context "text field with label" do
2015
- it "equals the page text" do
2016
- @st.set_field_among("First name", "Marcus", "Last name" => "nowhere").should be_true
2017
- @st.field_contains("First name", "Marcus").should be_true
2018
- end
2019
-
2020
- it "equals the page text and has no ids" do
2021
- @st.set_field_among("First name", "Marcus", "").should be_true
2022
- @st.field_contains("First name", "Marcus").should be_true
2023
- end
2024
-
2025
- it "equals the hash text" do
2026
- @st.set_field_among("Last name", "Marcus", "Last name" => "First name").should be_true
2027
- @st.field_contains("First name", "Marcus").should be_true
2028
- end
2029
-
2030
- it "equals the escaped hash text" do
2031
- @st.set_field_among("Last:name", "Marcus", "Last\\;name" => "First name").should be_true
2032
- @st.field_contains("First name", "Marcus").should be_true
2033
- end
2034
- end
2035
- end
2036
-
2037
- context "fails when" do
2038
- context "text field with label" do
2039
- it "does not exist" do
2040
- @st.set_field_among("Third name", "Smith").should be_false
2041
- end
2042
-
2043
- it "has a hash value that does not exist" do
2044
- @st.set_field_among("Last name", "Smith", "Last name" => "Third name").should be_false
2045
- end
2046
- end
2047
- end
2048
- end # set_field_among
2049
-
2050
- describe "#field_equals_among" do
2051
- before(:each) do
2052
- @st.visit("/form").should be_true
2053
- end
2054
- context "passes when" do
2055
- context "text field with label" do
2056
- it "equals the page text" do
2057
- @st.set_field_among("First name", "Marcus", "Last name" => "nowhere").should be_true
2058
- @st.field_equals_among("First name", "Marcus", "Last name" => "nowhere").should be_true
2059
- end
2060
-
2061
- it "equals the page text and has no ids" do
2062
- @st.set_field_among("First name", "Marcus", "").should be_true
2063
- @st.field_equals_among("First name", "Marcus", "").should be_true
2064
- end
2065
-
2066
- it "equals the hash text" do
2067
- @st.set_field_among("Last name", "Marcus", "Last name" => "First name").should be_true
2068
- @st.field_equals_among("Last name", "Marcus", "Last name" => "First name").should be_true
2069
- end
2070
-
2071
- it "equals the escaped hash text" do
2072
- @st.set_field_among("Last:name", "Marcus", "Last\\;name" => "First name").should be_true
2073
- @st.field_equals_among("Last:name", "Marcus", "Last\\;name" => "First name").should be_true
2074
- end
2075
- end
2076
- end
2077
-
2078
- context "fails when" do
2079
- context "text field with label" do
2080
- it "does not exist" do
2081
- @st.field_equals_among("Third name", "").should be_false
2082
- end
2083
-
2084
- it "has a hash value that does not exist" do
2085
- @st.field_equals_among("Last name", "", "Last name" => "Third name").should be_false
2086
- end
2087
-
2088
- it "does not equal the expected text" do
2089
- @st.field_equals_among("Last name", "Marcus", "Last name" => "First name").should be_false
2090
- end
2091
- end
2092
- end
2093
- end # field_equals_among
2094
-
2095
- describe "#set_fields" do
2096
- before(:each) do
2097
- @st.visit("/form").should be_true
2098
- end
2099
- context "passes when" do
2100
- context "text fields with labels" do
2101
- it "sets one field" do
2102
- @st.set_fields("First name" => "Marcus").should be_true
2103
- @st.field_contains("First name", "Marcus").should be_true
2104
- end
2105
-
2106
- it "sets zero fields" do
2107
- @st.set_fields("").should be_true
2108
- end
2109
-
2110
- it "sets several fields" do
2111
- @st.set_fields("First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot.").should be_true
2112
- @st.field_contains("First name", "Ken").should be_true
2113
- @st.field_contains("Last name", "Brazier").should be_true
2114
- @st.field_contains("Life story", "story: I get testy").should be_true
2115
- end
2116
- end
2117
- end
2118
-
2119
- context "fails when" do
2120
- context "text fields with labels" do
2121
- it "cant find the first field" do
2122
- @st.set_fields("Faust name" => "Ken", "Last name" => "Brazier").should be_false
2123
- end
2124
-
2125
- it "cant find the last field" do
2126
- @st.set_fields("First name" => "Ken", "Lost name" => "Brazier").should be_false
2127
- end
2128
- end
2129
- end
2130
- end # set_fields
2131
-
2132
- describe "#fields_equal" do
2133
- before(:each) do
2134
- @st.visit("/form").should be_true
2135
- end
2136
- context "passes when" do
2137
- context "text fields with labels" do
2138
- it "sets one field" do
2139
- @st.set_fields("First name" => "Marcus").should be_true
2140
- @st.fields_equal("First name" => "Marcus").should be_true
2141
- end
2142
-
2143
- it "sets zero fields" do
2144
- @st.fields_equal("").should be_true
2145
- end
2146
-
2147
- it "sets several fields" do
2148
- @st.set_fields("First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot.").should be_true
2149
- @st.fields_equal("First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot.").should be_true
2150
- end
2151
- end
2152
- end
2153
-
2154
- context "fails when" do
2155
- context "text fields with labels" do
2156
- it "cant find the first field" do
2157
- @st.fields_equal("Faust name" => "", "Last name" => "").should be_false
2158
- end
2159
-
2160
- it "cant find the last field" do
2161
- @st.fields_equal("First name" => "", "Lost name" => "").should be_false
2162
- end
2163
-
2164
- it "fields are not equal" do
2165
- @st.fields_equal("First name" => "Ken", "Last name" => "Brazier").should be_false
2166
- end
2167
- end
2168
- end
2169
- end # fields_equal
2170
-
2171
-
2172
- describe "#set_fields_among" do
2173
- before(:each) do
2174
- @st.visit("/form").should be_true
2175
- end
2176
- context "passes when" do
2177
- context "text fields with labels" do
2178
- it "sets one field" do
2179
- @st.set_fields_among({"First name" => "Marcus"}).should be_true
2180
- @st.field_contains("First name", "Marcus").should be_true
2181
- end
2182
-
2183
- it "sets one field with string ids" do
2184
- @st.set_fields_among({"First name" => "Marcus"}, "").should be_true
2185
- @st.field_contains("First name", "Marcus").should be_true
2186
- end
2187
-
2188
- it "does nothing, but has ids" do
2189
- @st.set_fields_among("", {"First name" => "Marcus"}).should be_true
2190
- end
2191
-
2192
- it "sets several fields" do
2193
- @st.set_fields_among({"First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot."})
2194
- @st.field_contains("First name", "Ken").should be_true
2195
- @st.field_contains("Last name", "Brazier").should be_true
2196
- @st.field_contains("Life story", "story: I get testy").should be_true
2197
- end
2198
- end
2199
- context "text fields with labels in a hash" do
2200
- it "sets one field from a hash" do
2201
- @st.set_fields_among({"Faust name" => "Marcus"}, {"Faust Name" => "First name", "LOST name" => "Last name"}).should be_true
2202
- @st.field_contains("First name", "Marcus").should be_true
2203
- end
2204
-
2205
- it "sets many fields, some from a hash" do
2206
- @st.set_fields_among({"Faust\\;name" => "Ken", :Lost => "Brazier", "Life story" => "I get testy a lot."},
2207
- {"Faust\\;Name" => "First name", :LOST => "Last name"}).should be_true
2208
- @st.field_contains("First name", "Ken").should be_true
2209
- @st.field_contains("Last name", "Brazier").should be_true
2210
- @st.field_contains("Life story", "testy").should be_true
2211
- end
2212
- end
2213
- end
2214
-
2215
- context "fails when" do
2216
- context "text fields with labels" do
2217
- it "cant find the first field" do
2218
- @st.set_fields_among({"Faust name" => "Ken", "Last name" => "Brazier"}).should be_false
2219
- end
2220
-
2221
- it "cant find the last field" do
2222
- @st.set_fields_among({"First name" => "Ken", "Lost name" => "Brazier"}).should be_false
2223
- end
2224
- end
2225
- context "text fields with labels in a hash" do
2226
- it "cant find the first field" do
2227
- @st.set_fields_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
2228
- {"Faust Name" => "Lost name", "Lost name" => "Last name"}).should be_false
2229
- end
2230
-
2231
- it "cant find the last field" do
2232
- @st.set_fields_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
2233
- {"Faust Name" => "First name", "Lost name" => "Faust name"}).should be_false
2234
- end
2235
- end
2236
- end
2237
- end # set_fields_among
2238
- end # generic_fields
2239
-
2240
-
2241
- describe "#fields_equal_among" do
2242
- before(:each) do
2243
- @st.visit("/form").should be_true
2244
- end
2245
- context "passes when" do
2246
- context "text fields with labels" do
2247
- it "sets one field" do
2248
- @st.set_fields_among({"First name" => "Marcus"}).should be_true
2249
- @st.fields_equal_among({"First name" => "Marcus"}).should be_true
2250
- end
2251
-
2252
- it "sets one field with string ids" do
2253
- @st.set_fields_among({"First name" => "Marcus"}, "").should be_true
2254
- @st.fields_equal_among({"First name" => "Marcus"}, "").should be_true
2255
- end
2256
-
2257
- it "does nothing, but has ids" do
2258
- @st.fields_equal_among("", {"First name" => "Marcus"}).should be_true
2259
- end
2260
-
2261
- it "sets several fields" do
2262
- @st.set_fields_among({"First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot."}).should be_true
2263
- @st.fields_equal_among({"First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot."}).should be_true
2264
- end
2265
- end
2266
- context "text fields with labels in a hash" do
2267
- it "sets one field from a hash" do
2268
- @st.set_fields_among({"Faust name" => "Marcus"}, {"Faust Name" => "First name", "LOST name" => "Last name"}).should be_true
2269
- @st.fields_equal_among({"Faust name" => "Marcus"}, {"Faust Name" => "First name", "LOST name" => "Last name"}).should be_true
2270
- end
2271
-
2272
- it "sets many fields, some from a hash" do
2273
- @st.set_fields_among({"Faust\\;name" => "Ken", :Lost => "Brazier", "Life story" => "I get testy a lot."},
2274
- {"Faust\\;Name" => "First name", :LOST => "Last name"}).should be_true
2275
- @st.fields_equal_among({"Faust\\;name" => "Ken", :Lost => "Brazier", "Life story" => "I get testy a lot."},
2276
- {"Faust\\;Name" => "First name", :LOST => "Last name"}).should be_true
2277
- end
2278
- end
2279
- end
2280
-
2281
- context "fails when" do
2282
- context "text fields with labels" do
2283
- it "cant find the first field" do
2284
- @st.fields_equal_among({"Faust name" => "Ken", "Last name" => "Brazier"}).should be_false
2285
- end
2286
-
2287
- it "cant find the last field" do
2288
- @st.fields_equal_among({"First name" => "Ken", "Lost name" => "Brazier"}).should be_false
2289
- end
2290
- it "does not equal the expected values" do
2291
- @st.fields_equal_among({"First name" => "Ken", "Last name" => "Brazier", "Life story" => "My story\\; I get testy a lot."}).should be_false
2292
- end
2293
- end
2294
- context "text fields with labels in a hash" do
2295
- it "cant find the first field" do
2296
- @st.fields_equal_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
2297
- {"Faust Name" => "Lost name", "Lost name" => "Last name"}).should be_false
2298
- end
2299
-
2300
- it "cant find the last field" do
2301
- @st.fields_equal_among({"Faust name" => "Ken", "Lost name" => "Brazier"},
2302
- {"Faust Name" => "First name", "Lost name" => "Faust name"}).should be_false
2303
- end
2304
- it "does not equal the expected values" do
2305
- @st.fields_equal_among({"Faust\\;name" => "Ken", :Lost => "Brazier", "Life story" => "I get testy a lot."},
2306
- {"Faust\\;Name" => "First name", :LOST => "Last name"}).should be_false
2307
- end
2308
- end
2309
- end
2310
- end # set_fields_among
2311
- end # generic_fields
2312
-
2313
-
2314
-
2315
- context "tables" do
2316
- before(:each) do
2317
- @st.visit("/table").should be_true
2318
- end
2319
-
2320
- describe "#row_exists" do
2321
- context "passes when" do
2322
- it "full row of headings exists" do
2323
- @st.row_exists("First name, Last name, Email").should be_true
2324
- end
2325
-
2326
- it "partial row of headings exists" do
2327
- @st.row_exists("First name, Last name").should be_true
2328
- @st.row_exists("Last name, Email").should be_true
2329
- end
2330
-
2331
- it "full row of cells exists" do
2332
- @st.row_exists("Eric, Pierce, epierce@example.com").should be_true
2333
- end
2334
-
2335
- it "partial row of cells exists" do
2336
- @st.row_exists("Eric, Pierce").should be_true
2337
- @st.row_exists("Pierce, epierce@example.com").should be_true
2338
- end
2339
-
2340
- it "cell values are not consecutive" do
2341
- @st.row_exists("First name, Email").should be_true
2342
- @st.row_exists("Eric, epierce@example.com").should be_true
2343
- end
2344
- end
2345
-
2346
- context "fails when" do
2347
- it "no row exists" do
2348
- @st.row_exists("Middle name, Maiden name, Email").should be_false
2349
- end
2350
- end
2351
- end
2352
-
2353
- end # tables
2354
-
2355
-
2356
- context "waiting" do
2357
- before(:each) do
2358
- @st.visit("/").should be_true
2359
- end
2360
-
2361
- describe "#page_loads_in_seconds_or_less" do
2362
- context "passes when" do
2363
- it "page is already loaded" do
2364
- @st.click_link("About this site").should be_true
2365
- sleep 1
2366
- @st.page_loads_in_seconds_or_less(10).should be_true
2367
- end
2368
- it "page loads before the timeout" do
2369
- @st.click_link("Slow page").should be_true
2370
- @st.page_loads_in_seconds_or_less(10).should be_true
2371
- @st.see("This page takes a few seconds to load").should be_true
2372
- end
2373
- end
2374
-
2375
- context "fails when" do
2376
- it "slow page does not load before the timeout" do
2377
- @st.click_link("Slow page").should be_true
2378
- @st.page_loads_in_seconds_or_less(1).should be_false
2379
- end
2380
- end
2381
- end
2382
-
2383
- describe "#pause_seconds" do
2384
- it "returns true" do
2385
- @st.pause_seconds(0).should == true
2386
- @st.pause_seconds(1).should == true
2387
- end
2388
- end
2389
- end # waiting
2390
-
2391
-
2392
- context "method inspection" do
2393
- describe "respond_to?" do
2394
- it "returns true if a method is explicitly defined" do
2395
- @st.respond_to?('see').should == true
2396
- end
2397
-
2398
- it "returns true if the Selenium::Client::Driver defines the method" do
2399
- @st.respond_to?('is_element_present').should == true
2400
- end
2401
-
2402
- it "returns false if the method isn't defined" do
2403
- @st.respond_to?('junk').should == false
2404
- end
2405
- end
2406
- end
2407
-
2408
-
2409
- context "stop on failure" do
2410
- before(:each) do
2411
- @st.visit("/").should be_true
2412
- @st.stop_on_failure = true
2413
- @st.found_failure = false
2414
- end
2415
-
2416
- after(:each) do
2417
- @st.stop_on_failure = false
2418
- end
2419
-
2420
- context "causes subsequent steps to fail" do
2421
- it "when #see fails" do
2422
- @st.see("Nonexistent").should be_false
2423
- # Would pass, but previous step failed
2424
- @st.see("Welcome").should be_false
2425
- end
2426
-
2427
- it "when #do_not_see fails" do
2428
- @st.do_not_see("Welcome").should be_false
2429
- # Would pass, but previous step failed
2430
- @st.do_not_see("Nonexistent").should be_false
2431
- end
2432
-
2433
- it "when #see_title fails" do
2434
- @st.errors # clear errors
2435
- @st.see_title("Wrong Title").should be_false
2436
- # Would pass, but previous step failed
2437
- @st.see_title("Rsel Test Site").should be_false
2438
- # Should see one and only one error.
2439
- @st.errors.should eq("Page title is 'Rsel Test Site', not 'Wrong Title'")
2440
- end
2441
-
2442
- it "when #do_not_see_title fails" do
2443
- @st.do_not_see_title("Rsel Test Site").should be_false
2444
- # Would pass, but previous step failed
2445
- @st.do_not_see_title("Wrong title").should be_false
2446
- end
2447
-
2448
- it "when #link_exists fails" do
2449
- @st.link_exists("Bogus Link").should be_false
2450
- # Would pass, but previous step failed
2451
- @st.link_exists("About this site").should be_false
2452
- end
2453
-
2454
- it "when #button_exists fails" do
2455
- @st.visit("/form").should be_true
2456
- @st.button_exists("Bogus Button").should be_false
2457
- # Would pass, but previous step failed
2458
- @st.button_exists("Submit person form").should be_false
2459
- end
2460
-
2461
- it "when #row_exists fails" do
2462
- @st.visit("/table").should be_true
2463
- @st.row_exists("No, Such, Row").should be_false
2464
- # Would pass, but previous step failed
2465
- @st.row_exists("First name, Last name, Email").should be_false
2466
- end
2467
-
2468
- it "when #type_into_field fails" do
2469
- @st.visit("/form").should be_true
2470
- @st.type_into_field("Hello", "Bad Field").should be_false
2471
- # Would pass, but previous step failed
2472
- @st.type_into_field("Eric", "First name").should be_false
2473
- end
2474
-
2475
- it "when #field_contains fails" do
2476
- @st.visit("/form").should be_true
2477
- @st.field_contains("Bad Field", "Hello").should be_false
2478
- # Would pass, but previous step failed
2479
- @st.field_contains("First name", "Marcus").should be_false
2480
- end
2481
-
2482
- it "when #field_equals fails" do
2483
- @st.visit("/form").should be_true
2484
- @st.fill_in_with("First name", "Ken")
2485
- @st.field_equals("First name", "Eric").should be_false
2486
- # Would pass, but previous step failed
2487
- @st.field_equals("First name", "Ken").should be_false
2488
- end
2489
-
2490
- it "when #click fails" do
2491
- @st.click("No Such Link").should be_false
2492
- # Would pass, but previous step failed
2493
- @st.click("About this site").should be_false
2494
- end
2495
-
2496
- it "when #click_link fails" do
2497
- @st.click_link("No Such Link").should be_false
2498
- # Would pass, but previous step failed
2499
- @st.click_link("About this site").should be_false
2500
- end
2501
-
2502
- it "when #click_button fails" do
2503
- @st.visit("/form").should be_true
2504
- @st.click_button("No Such Link").should be_false
2505
- # Would pass, but previous step failed
2506
- @st.click_button("Submit person form").should be_false
2507
- end
2508
-
2509
- it "when #enable_checkbox fails" do
2510
- @st.visit("/form").should be_true
2511
- @st.enable_checkbox("No Such Checkbox").should be_false
2512
- # Would pass, but previous step failed
2513
- @st.enable_checkbox("I like cheese").should be_false
2514
- end
2515
-
2516
- it "when #disable_checkbox fails" do
2517
- @st.visit("/form").should be_true
2518
- @st.disable_checkbox("No Such Checkbox").should be_false
2519
- # Would pass, but previous step failed
2520
- @st.disable_checkbox("I like cheese").should be_false
2521
- end
2522
-
2523
- it "when #checkbox_is_enabled fails" do
2524
- @st.visit("/form").should be_true
2525
- @st.enable_checkbox("I like cheese").should be_true
2526
- @st.checkbox_is_enabled("No Such Checkbox").should be_false
2527
- # Would pass, but previous step failed
2528
- @st.checkbox_is_enabled("I like cheese").should be_false
2529
- end
2530
-
2531
- it "when #checkbox_is_disabled fails" do
2532
- @st.visit("/form").should be_true
2533
- @st.checkbox_is_disabled("No Such Checkbox").should be_false
2534
- # Would pass, but previous step failed
2535
- @st.checkbox_is_disabled("I like cheese").should be_false
2536
- end
2537
-
2538
- it "when #radio_is_enabled fails" do
2539
- @st.visit("/form").should be_true
2540
- @st.select_radio("Briefs").should be_true
2541
- @st.radio_is_enabled("No Such Radio").should be_false
2542
- # Would pass, but previous step failed
2543
- @st.radio_is_enabled("Briefs").should be_false
2544
- end
2545
-
2546
- it "when #radio_is_disabled fails" do
2547
- @st.visit("/form").should be_true
2548
- @st.select_radio("Boxers").should be_true
2549
- @st.radio_is_disabled("No Such Radio").should be_false
2550
- # Would pass, but previous step failed
2551
- @st.radio_is_disabled("Briefs").should be_false
2552
- end
2553
-
2554
- it "when #select_radio fails" do
2555
- @st.visit("/form").should be_true
2556
- @st.select_radio("No Such Radio").should be_false
2557
- # Would pass, but previous step failed
2558
- @st.select_radio("Boxers").should be_false
2559
- end
2560
-
2561
- it "when #select_from_dropdown fails" do
2562
- @st.visit("/form").should be_true
2563
- @st.select_from_dropdown("Junk", "No Such Dropdown").should be_false
2564
- # Would pass, but previous step failed
2565
- @st.select_from_dropdown("Tall", "Height").should be_false
2566
- end
2567
-
2568
- it "when #dropdown_includes fails" do
2569
- @st.visit("/form").should be_true
2570
- @st.dropdown_includes("No Such Dropdown", "Junk").should be_false
2571
- # Would pass, but previous step failed
2572
- @st.dropdown_includes("Height", "Tall").should be_false
2573
- end
2574
-
2575
- it "when #dropdown_equals fails" do
2576
- @st.visit("/form").should be_true
2577
- @st.select_from_dropdown("Tall", "Height").should be_true
2578
- @st.dropdown_equals("No Such Dropdown", "Junk").should be_false
2579
- # Would pass, but previous step failed
2580
- @st.dropdown_equals("Tall", "Height").should be_false
2581
- end
2582
- end
2583
-
2584
- context "can be reset with #begin_scenario" do
2585
- it "when #see fails" do
2586
- @st.see("Nonexistent").should be_false
2587
- # Would pass, but previous step failed
2588
- @st.see("Welcome").should be_false
2589
- # Starting a new scenario allows #see to pass
2590
- @st.begin_scenario
2591
- @st.see("Welcome").should be_true
2592
- end
2593
-
2594
- it "when #do_not_see fails" do
2595
- @st.do_not_see("Welcome").should be_false
2596
- # Would pass, but previous step failed
2597
- @st.do_not_see("Nonexistent").should be_false
2598
- # Starting a new scenario allows #do_not_see to pass
2599
- @st.begin_scenario
2600
- @st.do_not_see("Nonexistent").should be_true
2601
- end
2602
- end
2603
-
2604
- end # stop on failure
2605
-
2606
-
2607
- describe "#method_missing" do
2608
- context "method is defined in Selenium::Client::Driver" do
2609
- before(:each) do
2610
- @st.visit("/form").should be_true
2611
- end
2612
-
2613
- context "method returning Boolean" do
2614
- it "passes if method returns true" do
2615
- @st.is_element_present("id=first_name").should be_true
2616
- @st.is_visible("id=first_name").should be_true
2617
- @st.is_text_present("This page has some random forms").should be_true
2618
- end
2619
-
2620
- it "fails if method returns false" do
2621
- @st.is_element_present("id=bogus_id").should be_false
2622
- @st.is_visible("id=bogus_id").should be_false
2623
- @st.is_text_present("This text is not there").should be_false
2624
- end
2625
- end
2626
-
2627
- context "method returning String" do
2628
- it "returns the String" do
2629
- @st.get_text("id=salami_checkbox").should eq("I like salami")
2630
- end
2631
- end
2632
-
2633
- context "method not returning Boolean or String" do
2634
- it "passes if method doesn't raise an exception" do
2635
- @st.get_title.should be_true
2636
- @st.mouse_over("id=first_name").should be_true
2637
- end
2638
-
2639
- it "fails if method raises an exception" do
2640
- @st.double_click("id=bogus_id").should be_false
2641
- @st.mouse_over("id=bogus_id").should be_false
2642
- end
2643
- end
2644
- end # Selenium::Client::Driver
2645
-
2646
- context "method is not defined in Selenium::Client::Driver" do
2647
- it "raises an exception" do
2648
- lambda do
2649
- @st.really_undefined_method
2650
- end.should raise_error
2651
- end
2652
- end
2653
- end # method_missing
2654
-
2655
- end
2656
-