bjeanes-capybara 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +87 -0
  3. data/README.rdoc +404 -0
  4. data/Rakefile +29 -0
  5. data/config.ru +6 -0
  6. data/lib/capybara.rb +53 -0
  7. data/lib/capybara/cucumber.rb +32 -0
  8. data/lib/capybara/driver/base.rb +37 -0
  9. data/lib/capybara/driver/celerity_driver.rb +135 -0
  10. data/lib/capybara/driver/culerity_driver.rb +25 -0
  11. data/lib/capybara/driver/rack_test_driver.rb +244 -0
  12. data/lib/capybara/driver/selenium_driver.rb +137 -0
  13. data/lib/capybara/dsl.rb +60 -0
  14. data/lib/capybara/node.rb +69 -0
  15. data/lib/capybara/rails.rb +11 -0
  16. data/lib/capybara/save_and_open_page.rb +33 -0
  17. data/lib/capybara/searchable.rb +53 -0
  18. data/lib/capybara/server.rb +111 -0
  19. data/lib/capybara/session.rb +274 -0
  20. data/lib/capybara/wait_until.rb +23 -0
  21. data/lib/capybara/xpath.rb +176 -0
  22. data/script/console +10 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/spec/capybara_spec.rb +18 -0
  26. data/spec/driver/celerity_driver_spec.rb +17 -0
  27. data/spec/driver/culerity_driver_spec.rb +13 -0
  28. data/spec/driver/rack_test_driver_spec.rb +12 -0
  29. data/spec/driver/remote_culerity_driver_spec.rb +26 -0
  30. data/spec/driver/remote_selenium_driver_spec.rb +18 -0
  31. data/spec/driver/selenium_driver_spec.rb +12 -0
  32. data/spec/drivers_spec.rb +139 -0
  33. data/spec/dsl/all_spec.rb +69 -0
  34. data/spec/dsl/attach_file_spec.rb +64 -0
  35. data/spec/dsl/check_spec.rb +39 -0
  36. data/spec/dsl/choose_spec.rb +26 -0
  37. data/spec/dsl/click_button_spec.rb +218 -0
  38. data/spec/dsl/click_link_spec.rb +108 -0
  39. data/spec/dsl/click_spec.rb +24 -0
  40. data/spec/dsl/current_url_spec.rb +8 -0
  41. data/spec/dsl/fill_in_spec.rb +91 -0
  42. data/spec/dsl/find_button_spec.rb +16 -0
  43. data/spec/dsl/find_by_id_spec.rb +16 -0
  44. data/spec/dsl/find_field_spec.rb +22 -0
  45. data/spec/dsl/find_link_spec.rb +17 -0
  46. data/spec/dsl/find_spec.rb +57 -0
  47. data/spec/dsl/has_button_spec.rb +32 -0
  48. data/spec/dsl/has_content_spec.rb +101 -0
  49. data/spec/dsl/has_css_spec.rb +107 -0
  50. data/spec/dsl/has_field_spec.rb +96 -0
  51. data/spec/dsl/has_link_spec.rb +33 -0
  52. data/spec/dsl/has_xpath_spec.rb +123 -0
  53. data/spec/dsl/locate_spec.rb +59 -0
  54. data/spec/dsl/select_spec.rb +71 -0
  55. data/spec/dsl/uncheck_spec.rb +21 -0
  56. data/spec/dsl/within_spec.rb +153 -0
  57. data/spec/dsl_spec.rb +140 -0
  58. data/spec/fixtures/capybara.jpg +0 -0
  59. data/spec/fixtures/test_file.txt +1 -0
  60. data/spec/public/jquery-ui.js +35 -0
  61. data/spec/public/jquery.js +19 -0
  62. data/spec/public/test.js +30 -0
  63. data/spec/save_and_open_page_spec.rb +43 -0
  64. data/spec/searchable_spec.rb +61 -0
  65. data/spec/server_spec.rb +47 -0
  66. data/spec/session/celerity_session_spec.rb +27 -0
  67. data/spec/session/culerity_session_spec.rb +25 -0
  68. data/spec/session/rack_test_session_spec.rb +25 -0
  69. data/spec/session/selenium_session_spec.rb +25 -0
  70. data/spec/session_spec.rb +77 -0
  71. data/spec/session_with_headers_support_spec.rb +13 -0
  72. data/spec/session_with_javascript_support_spec.rb +182 -0
  73. data/spec/session_without_headers_support_spec.rb +15 -0
  74. data/spec/session_without_javascript_support_spec.rb +15 -0
  75. data/spec/spec_helper.rb +27 -0
  76. data/spec/test_app.rb +71 -0
  77. data/spec/views/buttons.erb +4 -0
  78. data/spec/views/fieldsets.erb +29 -0
  79. data/spec/views/form.erb +226 -0
  80. data/spec/views/postback.erb +13 -0
  81. data/spec/views/tables.erb +122 -0
  82. data/spec/views/with_html.erb +38 -0
  83. data/spec/views/with_js.erb +34 -0
  84. data/spec/views/with_scope.erb +36 -0
  85. data/spec/views/with_simple_html.erb +1 -0
  86. data/spec/wait_until_spec.rb +28 -0
  87. data/spec/xpath_spec.rb +271 -0
  88. metadata +239 -0
@@ -0,0 +1,26 @@
1
+ shared_examples_for "choose" do
2
+
3
+ describe "#choose" do
4
+ before do
5
+ @session.visit('/form')
6
+ end
7
+
8
+ it "should choose a radio button by id" do
9
+ @session.choose("gender_male")
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['gender'].should == 'male'
12
+ end
13
+
14
+ it "should choose a radio button by label" do
15
+ @session.choose("Both")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['gender'].should == 'both'
18
+ end
19
+
20
+ context "with a locator that doesn't exist" do
21
+ it "should raise an error" do
22
+ running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,218 @@
1
+ shared_examples_for "click_button" do
2
+ describe '#click_button' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ context "with multiple values with the same name" do
8
+ it "should use the latest given value" do
9
+ @session.check('Terms of Use')
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['terms_of_use'].should == '1'
12
+ end
13
+ end
14
+
15
+ context "with value given on a submit button" do
16
+ context "on a form with HTML5 fields" do
17
+ before do
18
+ @session.click_button('html5_submit')
19
+ @results = extract_results(@session)
20
+ end
21
+
22
+ it "should serialise and submit search fields" do
23
+ @results['html5_search'].should == 'what are you looking for'
24
+ end
25
+
26
+ it "should serialise and submit email fields" do
27
+ @results['html5_email'].should == 'person@email.com'
28
+ end
29
+
30
+ it "should serialise and submit url fields" do
31
+ @results['html5_url'].should == 'http://www.example.com'
32
+ end
33
+
34
+ it "should serialise and submit tel fields" do
35
+ @results['html5_tel'].should == '911'
36
+ end
37
+
38
+ it "should serialise and submit color fields" do
39
+ @results['html5_color'].should == '#FFF'
40
+ end
41
+ end
42
+
43
+ context "on an HTML4 form" do
44
+ before do
45
+ @session.click_button('awesome')
46
+ @results = extract_results(@session)
47
+ end
48
+
49
+ it "should serialize and submit text fields" do
50
+ @results['first_name'].should == 'John'
51
+ end
52
+
53
+ it "should escape fields when submitting" do
54
+ @results['phone'].should == '+1 555 7021'
55
+ end
56
+
57
+ it "should serialize and submit password fields" do
58
+ @results['password'].should == 'seeekrit'
59
+ end
60
+
61
+ it "should serialize and submit hidden fields" do
62
+ @results['token'].should == '12345'
63
+ end
64
+
65
+ it "should not serialize fields from other forms" do
66
+ @results['middle_name'].should be_nil
67
+ end
68
+
69
+ it "should submit the button that was clicked, but not other buttons" do
70
+ @results['awesome'].should == 'awesome'
71
+ @results['crappy'].should be_nil
72
+ end
73
+
74
+ it "should serialize radio buttons" do
75
+ @results['gender'].should == 'female'
76
+ end
77
+
78
+ it "should serialize check boxes" do
79
+ @results['pets'].should include('dog', 'hamster')
80
+ @results['pets'].should_not include('cat')
81
+ end
82
+
83
+ it "should serialize text areas" do
84
+ @results['description'].should == 'Descriptive text goes here'
85
+ end
86
+
87
+ it "should serialize select tag with values" do
88
+ @results['locale'].should == 'en'
89
+ end
90
+
91
+ it "should serialize select tag without values" do
92
+ @results['region'].should == 'Norway'
93
+ end
94
+
95
+ it "should serialize first option for select tag with no selection" do
96
+ @results['city'].should == 'London'
97
+ end
98
+
99
+ it "should not serialize a select tag without options" do
100
+ @results['tendency'].should be_nil
101
+ end
102
+ end
103
+ end
104
+
105
+ context "with id given on a submit button" do
106
+ it "should submit the associated form" do
107
+ @session.click_button('awe123')
108
+ extract_results(@session)['first_name'].should == 'John'
109
+ end
110
+
111
+ it "should work with partial matches" do
112
+ @session.click_button('Go')
113
+ @session.body.should include('You landed')
114
+ end
115
+ end
116
+
117
+ context "with value given on an image button" do
118
+ it "should submit the associated form" do
119
+ @session.click_button('okay')
120
+ extract_results(@session)['first_name'].should == 'John'
121
+ end
122
+
123
+ it "should work with partial matches" do
124
+ @session.click_button('kay')
125
+ extract_results(@session)['first_name'].should == 'John'
126
+ end
127
+ end
128
+
129
+ context "with id given on an image button" do
130
+ it "should submit the associated form" do
131
+ @session.click_button('okay556')
132
+ extract_results(@session)['first_name'].should == 'John'
133
+ end
134
+ end
135
+
136
+ context "with text given on a button defined by <button> tag" do
137
+ it "should submit the associated form" do
138
+ @session.click_button('Click me')
139
+ extract_results(@session)['first_name'].should == 'John'
140
+ end
141
+
142
+ it "should work with partial matches" do
143
+ @session.click_button('Click')
144
+ extract_results(@session)['first_name'].should == 'John'
145
+ end
146
+
147
+ it "should prefer exact matches over partial matches" do
148
+ @session.click_button('Just an input')
149
+ extract_results(@session)['button'].should == 'button_second'
150
+ end
151
+ end
152
+
153
+ context "with id given on a button defined by <button> tag" do
154
+ it "should submit the associated form" do
155
+ @session.click_button('click_me_123')
156
+ extract_results(@session)['first_name'].should == 'John'
157
+ end
158
+
159
+ it "should serialize and send GET forms" do
160
+ @session.visit('/form')
161
+ @session.click_button('med')
162
+ @results = extract_results(@session)
163
+ @results['middle_name'].should == 'Darren'
164
+ @results['foo'].should be_nil
165
+ end
166
+ end
167
+
168
+ context "with value given on a button defined by <button> tag" do
169
+ it "should submit the associated form" do
170
+ @session.click_button('click_me')
171
+ extract_results(@session)['first_name'].should == 'John'
172
+ end
173
+
174
+ it "should work with partial matches" do
175
+ @session.click_button('ck_me')
176
+ extract_results(@session)['first_name'].should == 'John'
177
+ end
178
+
179
+ it "should prefer exact matches over partial matches" do
180
+ @session.click_button('Just a button')
181
+ extract_results(@session)['button'].should == 'Just a button'
182
+ end
183
+ end
184
+
185
+ context "with a locator that doesn't exist" do
186
+ it "should raise an error" do
187
+ running do
188
+ @session.click_button('does not exist')
189
+ end.should raise_error(Capybara::ElementNotFound)
190
+ end
191
+ end
192
+
193
+ it "should serialize and send GET forms" do
194
+ @session.visit('/form')
195
+ @session.click_button('med')
196
+ @results = extract_results(@session)
197
+ @results['middle_name'].should == 'Darren'
198
+ @results['foo'].should be_nil
199
+ end
200
+
201
+ it "should follow redirects" do
202
+ @session.click_button('Go FAR')
203
+ @session.body.should include('You landed')
204
+ end
205
+
206
+ it "should post pack to the same URL when no action given" do
207
+ @session.visit('/postback')
208
+ @session.click_button('With no action')
209
+ @session.body.should include('Postback')
210
+ end
211
+
212
+ it "should post pack to the same URL when blank action given" do
213
+ @session.visit('/postback')
214
+ @session.click_button('With blank action')
215
+ @session.body.should include('Postback')
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,108 @@
1
+ shared_examples_for "click_link" do
2
+ describe '#click_link' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ context "with id given" do
8
+ it "should take user to the linked page" do
9
+ @session.click_link('foo')
10
+ @session.body.should include('Another World')
11
+ end
12
+ end
13
+
14
+ context "with text given" do
15
+ it "should take user to the linked page" do
16
+ @session.click_link('labore')
17
+ @session.body.should include('Bar')
18
+ end
19
+
20
+ it "should accept partial matches" do
21
+ @session.click_link('abo')
22
+ @session.body.should include('Bar')
23
+ end
24
+
25
+ it "should prefer exact matches over partial matches" do
26
+ @session.click_link('A link')
27
+ @session.body.should include('Bar')
28
+ end
29
+ end
30
+
31
+ context "with title given" do
32
+ it "should take user to the linked page" do
33
+ @session.click_link('awesome title')
34
+ @session.body.should include('Bar')
35
+ end
36
+
37
+ it "should accept partial matches" do
38
+ @session.click_link('some tit')
39
+ @session.body.should include('Bar')
40
+ end
41
+
42
+ it "should prefer exact matches over partial matches" do
43
+ @session.click_link('a fine link')
44
+ @session.body.should include('Bar')
45
+ end
46
+ end
47
+
48
+ context "with alternative text given to a contained image" do
49
+ it "should take user to the linked page" do
50
+ @session.click_link('awesome image')
51
+ @session.body.should include('Bar')
52
+ end
53
+
54
+ it "should take user to the linked page" do
55
+ @session.click_link('some imag')
56
+ @session.body.should include('Bar')
57
+ end
58
+
59
+ it "should prefer exact matches over partial matches" do
60
+ @session.click_link('fine image')
61
+ @session.body.should include('Bar')
62
+ end
63
+ end
64
+
65
+ context "with a locator that doesn't exist" do
66
+ it "should raise an error" do
67
+ running do
68
+ @session.click_link('does not exist')
69
+ end.should raise_error(Capybara::ElementNotFound)
70
+ end
71
+ end
72
+
73
+ it "should follow redirects" do
74
+ @session.click_link('Redirect')
75
+ @session.body.should include('You landed')
76
+ end
77
+
78
+ it "should follow redirects" do
79
+ @session.click_link('BackToMyself')
80
+ @session.body.should include('This is a test')
81
+ end
82
+
83
+ it "should do nothing on anchor links" do
84
+ @session.fill_in("test_field", :with => 'blah')
85
+ @session.click_link('Anchor')
86
+ @session.find_field("test_field").value.should == 'blah'
87
+ @session.click_link('Blank Anchor')
88
+ @session.find_field("test_field").value.should == 'blah'
89
+ end
90
+
91
+ it "should do nothing on URL+anchor links for the same page" do
92
+ @session.fill_in("test_field", :with => 'blah')
93
+ @session.click_link('Anchor on same page')
94
+ @session.find_field("test_field").value.should == 'blah'
95
+ end
96
+
97
+ it "should follow link on URL+anchor links for a different page" do
98
+ @session.click_link('Anchor on different page')
99
+ @session.body.should include('Bar')
100
+ end
101
+
102
+ it "raise an error with links with no href" do
103
+ running do
104
+ @session.click_link('No Href')
105
+ end.should raise_error(Capybara::ElementNotFound)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,24 @@
1
+ shared_examples_for "click" do
2
+ describe '#click' do
3
+ it "should click on a link" do
4
+ @session.visit('/with_html')
5
+ @session.click('labore')
6
+ @session.body.should include('Bar')
7
+ end
8
+
9
+ it "should click on a button" do
10
+ @session.visit('/form')
11
+ @session.click('awe123')
12
+ extract_results(@session)['first_name'].should == 'John'
13
+ end
14
+
15
+ context "with a locator that doesn't exist" do
16
+ it "should raise an error" do
17
+ @session.visit('/with_html')
18
+ running do
19
+ @session.click('does not exist')
20
+ end.should raise_error(Capybara::ElementNotFound)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ shared_examples_for "current_url" do
2
+ describe '#current_url' do
3
+ it "should return the current url" do
4
+ @session.visit('/form')
5
+ @session.current_url.should =~ %r(http://[^/]+/form)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,91 @@
1
+ shared_examples_for "fill_in" do
2
+ describe "#fill_in" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should fill in a text field by id" do
8
+ @session.fill_in('form_first_name', :with => 'Harry')
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['first_name'].should == 'Harry'
11
+ end
12
+
13
+ it "should fill in a text field by name" do
14
+ @session.fill_in('form[last_name]', :with => 'Green')
15
+ @session.click_button('awesome')
16
+ extract_results(@session)['last_name'].should == 'Green'
17
+ end
18
+
19
+ it "should fill in a text field by label without for" do
20
+ @session.fill_in('Street', :with => 'Avenue Q')
21
+ @session.click_button('awesome')
22
+ extract_results(@session)['street'].should == 'Avenue Q'
23
+ end
24
+
25
+ it "should favour exact label matches over partial matches" do
26
+ @session.fill_in('Name', :with => 'Harry Jones')
27
+ @session.click_button('awesome')
28
+ extract_results(@session)['name'].should == 'Harry Jones'
29
+ end
30
+
31
+ it "should fill in a textarea by id" do
32
+ @session.fill_in('form_description', :with => 'Texty text')
33
+ @session.click_button('awesome')
34
+ extract_results(@session)['description'].should == 'Texty text'
35
+ end
36
+
37
+ it "should fill in a textarea by label" do
38
+ @session.fill_in('Description', :with => 'Texty text')
39
+ @session.click_button('awesome')
40
+ extract_results(@session)['description'].should == 'Texty text'
41
+ end
42
+
43
+ it "should fill in a textarea by name" do
44
+ @session.fill_in('form[description]', :with => 'Texty text')
45
+ @session.click_button('awesome')
46
+ extract_results(@session)['description'].should == 'Texty text'
47
+ end
48
+
49
+ it "should fill in a password field by id" do
50
+ @session.fill_in('form_password', :with => 'supasikrit')
51
+ @session.click_button('awesome')
52
+ extract_results(@session)['password'].should == 'supasikrit'
53
+ end
54
+
55
+ it "should fill in a password field by label" do
56
+ @session.fill_in('Password', :with => 'supasikrit')
57
+ @session.click_button('awesome')
58
+ extract_results(@session)['password'].should == 'supasikrit'
59
+ end
60
+
61
+ it "should fill in a password field by name" do
62
+ @session.fill_in('form[password]', :with => 'supasikrit')
63
+ @session.click_button('awesome')
64
+ extract_results(@session)['password'].should == 'supasikrit'
65
+ end
66
+
67
+ it "should prefer exact matches over partial matches" do
68
+ @session.fill_in('Name', :with => 'Ford Prefect')
69
+ @session.click_button('awesome')
70
+ extract_results(@session)['name'].should == 'Ford Prefect'
71
+ end
72
+
73
+ context "with ignore_hidden_fields" do
74
+ before { Capybara.ignore_hidden_elements = true }
75
+ after { Capybara.ignore_hidden_elements = false }
76
+ it "should not find a hidden field" do
77
+ running do
78
+ @session.fill_in('Super Secret', :with => '777')
79
+ end.should raise_error(Capybara::ElementNotFound)
80
+ end
81
+ end
82
+
83
+ context "with a locator that doesn't exist" do
84
+ it "should raise an error" do
85
+ running do
86
+ @session.fill_in('does not exist', :with => 'Blah blah')
87
+ end.should raise_error(Capybara::ElementNotFound)
88
+ end
89
+ end
90
+ end
91
+ end