diabolo-webrat 0.4.3 → 0.4.4

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 (81) hide show
  1. data/History.txt +8 -0
  2. data/Rakefile +5 -1
  3. data/lib/webrat/core/locators/field_labeled_locator.rb +1 -1
  4. data/lib/webrat/core/locators/label_locator.rb +1 -1
  5. data/lib/webrat/core_extensions/tcp_socket.rb +27 -0
  6. data/lib/webrat/selenium/application_server.rb +71 -0
  7. data/lib/webrat/selenium/merb_application_server.rb +48 -0
  8. data/lib/webrat/selenium/rails_application_server.rb +42 -0
  9. data/lib/webrat/selenium/selenium_rc_server.rb +80 -0
  10. data/lib/webrat/selenium/sinatra_application_server.rb +35 -0
  11. data/spec/fakes/test_session.rb +34 -0
  12. data/spec/integration/merb/app/controllers/application.rb +2 -0
  13. data/spec/integration/merb/app/controllers/exceptions.rb +13 -0
  14. data/spec/integration/merb/app/controllers/testing.rb +18 -0
  15. data/spec/integration/merb/config/environments/development.rb +15 -0
  16. data/spec/integration/merb/config/environments/rake.rb +11 -0
  17. data/spec/integration/merb/config/environments/test.rb +14 -0
  18. data/spec/integration/merb/config/init.rb +25 -0
  19. data/spec/integration/merb/config/rack.rb +11 -0
  20. data/spec/integration/merb/config/router.rb +33 -0
  21. data/spec/integration/merb/spec/spec_helper.rb +24 -0
  22. data/spec/integration/merb/spec/webrat_spec.rb +32 -0
  23. data/spec/integration/merb/tasks/merb.thor/app_script.rb +31 -0
  24. data/spec/integration/merb/tasks/merb.thor/common.rb +64 -0
  25. data/spec/integration/merb/tasks/merb.thor/gem_ext.rb +124 -0
  26. data/spec/integration/merb/tasks/merb.thor/ops.rb +93 -0
  27. data/spec/integration/merb/tasks/merb.thor/utils.rb +40 -0
  28. data/spec/integration/rails/app/controllers/application.rb +15 -0
  29. data/spec/integration/rails/app/controllers/webrat_controller.rb +39 -0
  30. data/spec/integration/rails/config/boot.rb +109 -0
  31. data/spec/integration/rails/config/environment.rb +12 -0
  32. data/spec/integration/rails/config/environments/development.rb +17 -0
  33. data/spec/integration/rails/config/environments/selenium.rb +22 -0
  34. data/spec/integration/rails/config/environments/test.rb +22 -0
  35. data/spec/integration/rails/config/initializers/inflections.rb +10 -0
  36. data/spec/integration/rails/config/initializers/mime_types.rb +5 -0
  37. data/spec/integration/rails/config/initializers/new_rails_defaults.rb +17 -0
  38. data/spec/integration/rails/config/routes.rb +14 -0
  39. data/spec/integration/rails/test/integration/webrat_test.rb +80 -0
  40. data/spec/integration/rails/test/test_helper.rb +25 -0
  41. data/spec/integration/sinatra/classic_app.rb +64 -0
  42. data/spec/integration/sinatra/modular_app.rb +16 -0
  43. data/spec/integration/sinatra/test/classic_app_test.rb +37 -0
  44. data/spec/integration/sinatra/test/modular_app_test.rb +18 -0
  45. data/spec/integration/sinatra/test/test_helper.rb +16 -0
  46. data/spec/private/core/configuration_spec.rb +104 -0
  47. data/spec/private/core/field_spec.rb +67 -0
  48. data/spec/private/core/link_spec.rb +24 -0
  49. data/spec/private/core/logging_spec.rb +10 -0
  50. data/spec/private/core/session_spec.rb +198 -0
  51. data/spec/private/mechanize/mechanize_session_spec.rb +81 -0
  52. data/spec/private/merb/merb_session_spec.rb +42 -0
  53. data/spec/private/nokogiri_spec.rb +77 -0
  54. data/spec/private/rails/attaches_file_spec.rb +81 -0
  55. data/spec/private/rails/rails_session_spec.rb +110 -0
  56. data/spec/public/basic_auth_spec.rb +24 -0
  57. data/spec/public/check_spec.rb +191 -0
  58. data/spec/public/choose_spec.rb +118 -0
  59. data/spec/public/click_area_spec.rb +106 -0
  60. data/spec/public/click_button_spec.rb +502 -0
  61. data/spec/public/click_link_spec.rb +541 -0
  62. data/spec/public/fill_in_spec.rb +209 -0
  63. data/spec/public/locators/field_by_xpath_spec.rb +19 -0
  64. data/spec/public/locators/field_labeled_spec.rb +172 -0
  65. data/spec/public/locators/field_with_id_spec.rb +16 -0
  66. data/spec/public/matchers/contain_spec.rb +114 -0
  67. data/spec/public/matchers/have_selector_spec.rb +135 -0
  68. data/spec/public/matchers/have_tag_spec.rb +39 -0
  69. data/spec/public/matchers/have_xpath_spec.rb +123 -0
  70. data/spec/public/reload_spec.rb +10 -0
  71. data/spec/public/save_and_open_spec.rb +51 -0
  72. data/spec/public/select_date_spec.rb +112 -0
  73. data/spec/public/select_datetime_spec.rb +137 -0
  74. data/spec/public/select_spec.rb +261 -0
  75. data/spec/public/select_time_spec.rb +100 -0
  76. data/spec/public/set_hidden_field_spec.rb +5 -0
  77. data/spec/public/submit_form_spec.rb +5 -0
  78. data/spec/public/visit_spec.rb +58 -0
  79. data/spec/public/within_spec.rb +177 -0
  80. data/spec/spec_helper.rb +50 -0
  81. metadata +90 -25
@@ -0,0 +1,541 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "click_link" do
4
+ it "should click links with ampertands" do
5
+ with_html <<-HTML
6
+ <html>
7
+ <a href="/page">Save &amp; go back</a>
8
+ </html>
9
+ HTML
10
+ webrat_session.should_receive(:get).with("/page", {})
11
+ click_link "Save & go back"
12
+ end
13
+
14
+ it "should use get by default" do
15
+ with_html <<-HTML
16
+ <html>
17
+ <a href="/page">Link text</a>
18
+ </html>
19
+ HTML
20
+ webrat_session.should_receive(:get).with("/page", {})
21
+ click_link "Link text"
22
+ end
23
+
24
+ it "should click get links" do
25
+ with_html <<-HTML
26
+ <html>
27
+ <a href="/page">Link text</a>
28
+ </html>
29
+ HTML
30
+ webrat_session.should_receive(:get).with("/page", {})
31
+ click_link "Link text", :method => :get
32
+ end
33
+
34
+ it "should click link on substring" do
35
+ with_html <<-HTML
36
+ <html>
37
+ <a href="/page">Link text</a>
38
+ </html>
39
+ HTML
40
+ webrat_session.should_receive(:get).with("/page", {})
41
+ click_link "ink tex", :method => :get
42
+ end
43
+
44
+ it "should click delete links" do
45
+ with_html <<-HTML
46
+ <html>
47
+ <a href="/page">Link text</a>
48
+ </html>
49
+ HTML
50
+ webrat_session.should_receive(:delete).with("/page", {})
51
+ click_link "Link text", :method => :delete
52
+ end
53
+
54
+
55
+ it "should click post links" do
56
+ with_html <<-HTML
57
+ <html>
58
+ <a href="/page">Link text</a>
59
+ </html>
60
+ HTML
61
+ webrat_session.should_receive(:post).with("/page", {})
62
+ click_link "Link text", :method => :post
63
+ end
64
+
65
+ it "should click put links" do
66
+ with_html <<-HTML
67
+ <html>
68
+ <a href="/page">Link text</a>
69
+ </html>
70
+ HTML
71
+ webrat_session.should_receive(:put).with("/page", {})
72
+ click_link "Link text", :method => :put
73
+ end
74
+
75
+ it "should click links by regexp" do
76
+ with_html <<-HTML
77
+ <html>
78
+ <a href="/page">Link text</a>
79
+ </html>
80
+ HTML
81
+ webrat_session.should_receive(:get).with("/page", {})
82
+ click_link /link [a-z]/i
83
+ end
84
+
85
+ it "should click links by id" do
86
+ with_html <<-HTML
87
+ <html>
88
+ <a id="link_text_link" href="/page">Link text</a>
89
+ </html>
90
+ HTML
91
+ webrat_session.should_receive(:get).with("/page", {})
92
+ click_link "link_text_link"
93
+ end
94
+
95
+ it "should click links by id regexp" do
96
+ with_html <<-HTML
97
+ <html>
98
+ <a id="link_text_link" href="/page">Link text</a>
99
+ </html>
100
+ HTML
101
+ webrat_session.should_receive(:get).with("/page", {})
102
+ click_link /_text_/
103
+ end
104
+
105
+ it "should click links by title" do
106
+ with_html <<-HTML
107
+ <html>
108
+ <a title="piddle" href="/page">Link text</a>
109
+ </html>
110
+ HTML
111
+ webrat_session.should_receive(:get).with("/page", {})
112
+ click_link 'piddle'
113
+ end
114
+
115
+ it "should click links by title regex" do
116
+ with_html <<-HTML
117
+ <html>
118
+ <a title="piddlediddle" href="/page">Link text</a>
119
+ </html>
120
+ HTML
121
+ webrat_session.should_receive(:get).with("/page", {})
122
+ click_link /iddle/
123
+ end
124
+
125
+ it "should click links by class" do
126
+ with_html <<-HTML
127
+ <html>
128
+ <a class="piddle" href="/page">Link text</a>
129
+ </html>
130
+ HTML
131
+ webrat_session.should_receive(:get).with("/page", {})
132
+ click_link 'piddle'
133
+ end
134
+
135
+ it "should click links by class when there are many classes" do
136
+ with_html <<-HTML
137
+ <html>
138
+ <a class="one two three" href="/page">Link text</a>
139
+ </html>
140
+ HTML
141
+ webrat_session.should_receive(:get).with("/page", {})
142
+ click_link 'two'
143
+ end
144
+
145
+
146
+ it "should click links by class regex" do
147
+ with_html <<-HTML
148
+ <html>
149
+ <a class="piddlediddle" href="/page">Link text</a>
150
+ </html>
151
+ HTML
152
+ webrat_session.should_receive(:get).with("/page", {})
153
+ click_link /iddle/
154
+ end
155
+
156
+ it "should click rails javascript links with authenticity tokens" do
157
+ with_html <<-HTML
158
+ <html>
159
+ <a href="/posts" onclick="var f = document.createElement('form');
160
+ f.style.display = 'none';
161
+ this.parentNode.appendChild(f);
162
+ f.method = 'POST';
163
+ f.action = this.href;
164
+ var s = document.createElement('input');
165
+ s.setAttribute('type', 'hidden');
166
+ s.setAttribute('name', 'authenticity_token');
167
+ s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62');
168
+ f.appendChild(s);
169
+ f.submit();
170
+ return false;">Posts</a>
171
+ </html>
172
+ HTML
173
+ webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
174
+ click_link "Posts"
175
+ end
176
+
177
+ it "should click rails javascript delete links" do
178
+ with_html <<-HTML
179
+ <html>
180
+ <a href="/posts/1" onclick="var f = document.createElement('form');
181
+ f.style.display = 'none';
182
+ this.parentNode.appendChild(f);
183
+ f.method = 'POST';
184
+ f.action = this.href;
185
+ var m = document.createElement('input');
186
+ m.setAttribute('type', 'hidden');
187
+ m.setAttribute('name', '_method');
188
+ m.setAttribute('value', 'delete');
189
+ f.appendChild(m);
190
+ f.submit();
191
+ return false;">Delete</a>
192
+ </html>
193
+ HTML
194
+ webrat_session.should_receive(:delete).with("/posts/1", {})
195
+ click_link "Delete"
196
+ end
197
+
198
+ it "should click rails javascript post links" do
199
+ with_html <<-HTML
200
+ <html>
201
+ <a href="/posts" onclick="var f = document.createElement('form');
202
+ f.style.display = 'none';
203
+ this.parentNode.appendChild(f);
204
+ f.method = 'POST';
205
+ f.action = this.href;
206
+ f.submit();
207
+ return false;">Posts</a>
208
+ </html>
209
+ HTML
210
+ webrat_session.should_receive(:post).with("/posts", {})
211
+ click_link "Posts"
212
+ end
213
+
214
+ it "should click rails javascript post links without javascript" do
215
+ with_html <<-HTML
216
+ <html>
217
+ <a href="/posts" onclick="var f = document.createElement('form');
218
+ f.style.display = 'none';
219
+ this.parentNode.appendChild(f);
220
+ f.method = 'POST';
221
+ f.action = this.href;
222
+ f.submit();
223
+ return false;">Posts</a>
224
+ </html>
225
+ HTML
226
+ webrat_session.should_receive(:get).with("/posts", {})
227
+ click_link "Posts", :javascript => false
228
+ end
229
+
230
+ it "should click rails javascript post links" do
231
+ with_html <<-HTML
232
+ <html>
233
+ <a href="/posts" onclick="var f = document.createElement('form');
234
+ f.style.display = 'none';
235
+ this.parentNode.appendChild(f);
236
+ f.method = 'POST';
237
+ f.action = this.href;
238
+ var m = document.createElement('input');
239
+ m.setAttribute('type', 'hidden');
240
+ m.setAttribute('name', '_method');
241
+ m.setAttribute('value', 'post');
242
+ f.appendChild(m);
243
+ f.submit();
244
+ return false;">Post</a></h2>
245
+ </html>
246
+ HTML
247
+ webrat_session.should_receive(:post).with("/posts", {})
248
+ click_link "Post"
249
+ end
250
+
251
+ it "should click rails javascript put links" do
252
+ with_html <<-HTML
253
+ <html>
254
+ <a href="/posts" onclick="var f = document.createElement('form');
255
+ f.style.display = 'none';
256
+ this.parentNode.appendChild(f);
257
+ f.method = 'POST';
258
+ f.action = this.href;
259
+ var m = document.createElement('input');
260
+ m.setAttribute('type', 'hidden');
261
+ m.setAttribute('name', '_method');
262
+ m.setAttribute('value', 'put');
263
+ f.appendChild(m);
264
+ f.submit();
265
+ return false;">Put</a></h2>
266
+ </html>
267
+ HTML
268
+ webrat_session.should_receive(:put).with("/posts", {})
269
+ click_link "Put"
270
+ end
271
+
272
+ it "should fail if the javascript link doesn't have a value for the _method input" do
273
+ with_html <<-HTML
274
+ <html>
275
+ <a href="/posts/1" onclick="var f = document.createElement('form');
276
+ f.style.display = 'none';
277
+ this.parentNode.appendChild(f);
278
+ f.method = 'POST';
279
+ f.action = this.href;
280
+ var m = document.createElement('input');
281
+ m.setAttribute('type', 'hidden');
282
+ m.setAttribute('name', '_method');
283
+ f.appendChild(m);
284
+ f.submit();
285
+ return false;">Link</a>
286
+ </html>
287
+ HTML
288
+
289
+ lambda {
290
+ click_link "Link"
291
+ }.should raise_error(Webrat::WebratError)
292
+ end
293
+
294
+ it "should assert valid response" do
295
+ with_html <<-HTML
296
+ <html>
297
+ <a href="/page">Link text</a>
298
+ </html>
299
+ HTML
300
+ webrat_session.response_code = 501
301
+ lambda { click_link "Link text" }.should raise_error(Webrat::PageLoadError)
302
+ end
303
+
304
+ [200, 300, 400, 499].each do |status|
305
+ it "should consider the #{status} status code as success" do
306
+ with_html <<-HTML
307
+ <html>
308
+ <a href="/page">Link text</a>
309
+ </html>
310
+ HTML
311
+ webrat_session.stub!(:redirect? => false)
312
+ webrat_session.response_code = status
313
+ lambda { click_link "Link text" }.should_not raise_error
314
+ end
315
+ end
316
+
317
+ it "should fail is the link doesn't exist" do
318
+ with_html <<-HTML
319
+ <html>
320
+ <a href="/page">Link text</a>
321
+ </html>
322
+ HTML
323
+
324
+ lambda {
325
+ click_link "Missing link"
326
+ }.should raise_error(Webrat::NotFoundError)
327
+ end
328
+
329
+ it "should not be case sensitive" do
330
+ with_html <<-HTML
331
+ <html>
332
+ <a href="/page">Link text</a>
333
+ </html>
334
+ HTML
335
+ webrat_session.should_receive(:get).with("/page", {})
336
+ click_link "LINK TEXT"
337
+ end
338
+
339
+ it "should match link substrings" do
340
+ with_html <<-HTML
341
+ <html>
342
+ <a href="/page">This is some cool link text, isn't it?</a>
343
+ </html>
344
+ HTML
345
+ webrat_session.should_receive(:get).with("/page", {})
346
+ click_link "Link text"
347
+ end
348
+
349
+ it "should work with elements in the link" do
350
+ with_html <<-HTML
351
+ <html>
352
+ <a href="/page"><span>Link text</span></a>
353
+ </html>
354
+ HTML
355
+ webrat_session.should_receive(:get).with("/page", {})
356
+ click_link "Link text"
357
+ end
358
+
359
+ it "should match the first matching link" do
360
+ with_html <<-HTML
361
+ <html>
362
+ <a href="/page1">Link text</a>
363
+ <a href="/page2">Link text</a>
364
+ </html>
365
+ HTML
366
+ webrat_session.should_receive(:get).with("/page1", {})
367
+ click_link "Link text"
368
+ end
369
+
370
+ it "should choose the shortest link text match" do
371
+ with_html <<-HTML
372
+ <html>
373
+ <a href="/page1">Linkerama</a>
374
+ <a href="/page2">Link</a>
375
+ </html>
376
+ HTML
377
+
378
+ webrat_session.should_receive(:get).with("/page2", {})
379
+ click_link "Link"
380
+ end
381
+
382
+ it "should treat non-breaking spaces as spaces" do
383
+ with_html <<-HTML
384
+ <html>
385
+ <a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
386
+ </html>
387
+ HTML
388
+
389
+ webrat_session.should_receive(:get).with("/page1", {})
390
+ click_link "This is a link"
391
+ end
392
+
393
+ it "should not match on non-text contents" do
394
+ pending "needs fix" do
395
+ with_html <<-HTML
396
+ <html>
397
+ <a href="/page1"><span class="location">My house</span></a>
398
+ <a href="/page2">Location</a>
399
+ </html>
400
+ HTML
401
+
402
+ webrat_session.should_receive(:get).with("/page2", {})
403
+ click_link "Location"
404
+ end
405
+ end
406
+
407
+ it "should click link within a selector" do
408
+ with_html <<-HTML
409
+ <html>
410
+ <a href="/page1">Link</a>
411
+ <div id="container">
412
+ <a href="/page2">Link</a>
413
+ </div>
414
+ </html>
415
+ HTML
416
+
417
+ webrat_session.should_receive(:get).with("/page2", {})
418
+ click_link_within "#container", "Link"
419
+ end
420
+
421
+ it "should not make request when link is local anchor" do
422
+ with_html <<-HTML
423
+ <html>
424
+ <a href="#section-1">Jump to Section 1</a>
425
+ </html>
426
+ HTML
427
+ # Don't know why webrat_session.should_receive(:get).never doesn't work here
428
+ webrat_session.should_receive(:send).with('get_via_redirect', '#section-1', {}).never
429
+ click_link "Jump to Section 1"
430
+ end
431
+
432
+ it "should follow relative links" do
433
+ webrat_session.stub!(:current_url => "/page")
434
+ with_html <<-HTML
435
+ <html>
436
+ <a href="sub">Jump to sub page</a>
437
+ </html>
438
+ HTML
439
+ webrat_session.should_receive(:get).with("/page/sub", {})
440
+ click_link "Jump to sub page"
441
+ end
442
+
443
+ it "should follow fully qualified local links" do
444
+ webrat_session.stub!(:current_url => "/page")
445
+ with_html <<-HTML
446
+ <html>
447
+ <a href="http://subdomain.example.com/page/sub">Jump to sub page</a>
448
+ </html>
449
+ HTML
450
+ webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {})
451
+ click_link "Jump to sub page"
452
+ end
453
+
454
+ it "should follow fully qualified local links to example.com" do
455
+ with_html <<-HTML
456
+ <html>
457
+ <a href="http://www.example.com/page/sub">Jump to sub page</a>
458
+ </html>
459
+ HTML
460
+ webrat_session.should_receive(:get).with("http://www.example.com/page/sub", {})
461
+ click_link "Jump to sub page"
462
+ end
463
+
464
+ it "should follow query parameters" do
465
+ webrat_session.stub!(:current_url => "/page")
466
+ with_html <<-HTML
467
+ <html>
468
+ <a href="?foo=bar">Jump to foo bar</a>
469
+ </html>
470
+ HTML
471
+ webrat_session.should_receive(:get).with("/page?foo=bar", {})
472
+ click_link "Jump to foo bar"
473
+ end
474
+
475
+ it "should matches_text? on regexp" do
476
+ pending "need to update these"
477
+ link = Webrat::Link.new(webrat_session, nil)
478
+ link.should_receive(:text).and_return(@link_text_with_nbsp)
479
+ link.matches_text?(/link/i).should == 0
480
+ end
481
+
482
+ it "should matches_text? on link_text" do
483
+ pending "need to update these"
484
+ link = Webrat::Link.new(webrat_session, nil)
485
+ link.should_receive(:text).and_return(@link_text_with_nbsp)
486
+ link.matches_text?("Link Text").should == 0
487
+ end
488
+
489
+ it "should matches_text? on substring" do
490
+ pending "need to update these"
491
+ link = Webrat::Link.new(webrat_session, nil)
492
+ link.should_receive(:text).and_return(@link_text_with_nbsp)
493
+ link.matches_text?("nk Te").should_not be_nil
494
+ end
495
+
496
+ it "should not matches_text? on link_text case insensitive" do
497
+ pending "need to update these"
498
+ link = Webrat::Link.new(webrat_session, nil)
499
+ link.should_receive(:text).and_return(@link_text_with_nbsp)
500
+ link.should_receive(:inner_html).and_return('Link&nbsp;Text')
501
+ link.should_receive(:title).and_return(nil)
502
+ link.matches_text?("link_text").should == false
503
+ end
504
+
505
+ it "should match text not include &nbsp;" do
506
+ pending "need to update these"
507
+ link = Webrat::Link.new(webrat_session, nil)
508
+ link.should_receive(:text).and_return('LinkText')
509
+ link.matches_text?("LinkText").should == 0
510
+ end
511
+
512
+ it "should not matches_text? on wrong text" do
513
+ pending "need to update these"
514
+ link = Webrat::Link.new(webrat_session, nil)
515
+ nbsp = [0xA0].pack("U")
516
+ link.should_receive(:text).and_return("Some"+nbsp+"Other"+nbsp+"Link")
517
+ link.should_receive(:inner_html).and_return("Some&nbsp;Other&nbsp;Link")
518
+ link.should_receive(:title).and_return(nil)
519
+ link.matches_text?("Link Text").should == false
520
+ end
521
+
522
+ it "should match text including character reference" do
523
+ pending "need to update these"
524
+ no_ko_gi_ri = [0x30CE,0x30B3,0x30AE,0x30EA]
525
+ nokogiri_ja_kana = no_ko_gi_ri.pack("U*")
526
+ nokogiri_char_ref = no_ko_gi_ri.map{|c| "&#x%X;" % c }.join("")
527
+
528
+ link = Webrat::Link.new(webrat_session, nil)
529
+ link.should_receive(:text).and_return(nokogiri_ja_kana)
530
+ link.matches_text?(nokogiri_ja_kana).should == 0
531
+ end
532
+
533
+ it "should match img link" do
534
+ pending "need to update these"
535
+ link = Webrat::Link.new(webrat_session, nil)
536
+ link.should_receive(:text).and_return('')
537
+ link.should_receive(:inner_html).and_return('<img src="logo.png" />')
538
+ link.matches_text?('logo.png').should == 10
539
+ end
540
+
541
+ end