capybara 1.1.4 → 2.0.0
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.
- data/{History.txt → History.md} +138 -0
- data/License.txt +22 -0
- data/README.md +850 -0
- data/lib/capybara/cucumber.rb +2 -5
- data/lib/capybara/driver/base.rb +6 -6
- data/lib/capybara/driver/node.rb +3 -2
- data/lib/capybara/dsl.rb +13 -124
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +16 -30
- data/lib/capybara/node/base.rb +56 -13
- data/lib/capybara/node/element.rb +18 -30
- data/lib/capybara/node/finders.rb +28 -90
- data/lib/capybara/node/matchers.rb +121 -73
- data/lib/capybara/node/simple.rb +13 -11
- data/lib/capybara/query.rb +78 -0
- data/lib/capybara/rack_test/browser.rb +27 -39
- data/lib/capybara/rack_test/driver.rb +13 -3
- data/lib/capybara/rack_test/node.rb +31 -2
- data/lib/capybara/result.rb +72 -0
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +33 -63
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/selector.rb +97 -34
- data/lib/capybara/selenium/driver.rb +15 -62
- data/lib/capybara/selenium/node.rb +14 -21
- data/lib/capybara/server.rb +32 -27
- data/lib/capybara/session.rb +90 -50
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +3 -0
- data/lib/capybara/spec/session/all_spec.rb +61 -59
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +68 -48
- data/lib/capybara/spec/session/choose_spec.rb +32 -18
- data/lib/capybara/spec/session/click_button_spec.rb +263 -232
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
- data/lib/capybara/spec/session/click_link_spec.rb +96 -96
- data/lib/capybara/spec/session/current_url_spec.rb +88 -10
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +93 -115
- data/lib/capybara/spec/session/first_spec.rb +51 -85
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +170 -144
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +161 -109
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -88
- data/lib/capybara/spec/session/has_text_spec.rb +195 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +205 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +13 -0
- data/lib/capybara/spec/session/select_spec.rb +99 -88
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -12
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +69 -58
- data/lib/capybara/spec/session/visit_spec.rb +74 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
- data/lib/capybara/spec/session/within_spec.rb +118 -131
- data/lib/capybara/spec/session/within_window_spec.rb +38 -0
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +32 -6
- data/lib/capybara/spec/views/form.erb +12 -10
- data/lib/capybara/spec/views/host_links.erb +2 -2
- data/lib/capybara/spec/views/tables.erb +6 -66
- data/lib/capybara/spec/views/with_html.erb +9 -4
- data/lib/capybara/spec/views/with_js.erb +11 -7
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +125 -6
- data/spec/basic_node_spec.rb +17 -5
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +31 -17
- data/spec/rack_test_spec.rb +157 -0
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -2
- data/spec/rspec/matchers_spec.rb +170 -89
- data/spec/rspec_spec.rb +1 -3
- data/spec/selenium_spec.rb +53 -0
- data/spec/server_spec.rb +37 -25
- data/spec/spec_helper.rb +1 -30
- metadata +39 -31
- data/README.rdoc +0 -722
- data/lib/capybara/spec/driver.rb +0 -301
- data/lib/capybara/spec/session/current_host_spec.rb +0 -68
- data/lib/capybara/spec/session/has_content_spec.rb +0 -106
- data/lib/capybara/spec/session/javascript.rb +0 -306
- data/lib/capybara/spec/session.rb +0 -154
- data/lib/capybara/util/save_and_open_page.rb +0 -44
- data/lib/capybara/util/timeout.rb +0 -27
- data/spec/driver/rack_test_driver_spec.rb +0 -89
- data/spec/driver/selenium_driver_spec.rb +0 -37
- data/spec/save_and_open_page_spec.rb +0 -155
- data/spec/session/rack_test_session_spec.rb +0 -55
- data/spec/session/selenium_session_spec.rb +0 -26
- data/spec/string_spec.rb +0 -77
- data/spec/timeout_spec.rb +0 -28
|
@@ -1,277 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#click_button' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
7
|
+
@session.visit('/with_js')
|
|
8
|
+
@session.click_link('Click me')
|
|
9
|
+
@session.click_button('New Here')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "casts to string" do
|
|
13
|
+
@session.click_button(:'Relative Action')
|
|
14
|
+
@session.current_path.should == '/relative'
|
|
15
|
+
extract_results(@session)['relative'].should == 'Relative Action'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "with multiple values with the same name" do
|
|
19
|
+
it "should use the latest given value" do
|
|
20
|
+
@session.check('Terms of Use')
|
|
21
|
+
@session.click_button('awesome')
|
|
22
|
+
extract_results(@session)['terms_of_use'].should == '1'
|
|
13
23
|
end
|
|
24
|
+
end
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
26
|
+
context "with a form that has a relative url as an action" do
|
|
27
|
+
it "should post to the correct url" do
|
|
28
|
+
@session.click_button('Relative Action')
|
|
29
|
+
@session.current_path.should == '/relative'
|
|
30
|
+
extract_results(@session)['relative'].should == 'Relative Action'
|
|
21
31
|
end
|
|
32
|
+
end
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
34
|
+
context "with a form that has no action specified" do
|
|
35
|
+
it "should post to the correct url" do
|
|
36
|
+
@session.click_button('No Action')
|
|
37
|
+
@session.current_path.should == '/form'
|
|
38
|
+
extract_results(@session)['no_action'].should == 'No Action'
|
|
29
39
|
end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
it "should serialise and submit search fields" do
|
|
39
|
-
@results['html5_search'].should == 'what are you looking for'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should serialise and submit email fields" do
|
|
43
|
-
@results['html5_email'].should == 'person@email.com'
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should serialise and submit url fields" do
|
|
47
|
-
@results['html5_url'].should == 'http://www.example.com'
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should serialise and submit tel fields" do
|
|
51
|
-
@results['html5_tel'].should == '911'
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should serialise and submit color fields" do
|
|
55
|
-
@results['html5_color'].should == '#FFFFFF'
|
|
56
|
-
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "with value given on a submit button" do
|
|
43
|
+
context "on a form with HTML5 fields" do
|
|
44
|
+
before do
|
|
45
|
+
@session.click_button('html5_submit')
|
|
46
|
+
@results = extract_results(@session)
|
|
57
47
|
end
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
@session.click_button('awesome')
|
|
62
|
-
@results = extract_results(@session)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should serialize and submit text fields" do
|
|
66
|
-
@results['first_name'].should == 'John'
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "should escape fields when submitting" do
|
|
70
|
-
@results['phone'].should == '+1 555 7021'
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should serialize and submit password fields" do
|
|
74
|
-
@results['password'].should == 'seeekrit'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should serialize and submit hidden fields" do
|
|
78
|
-
@results['token'].should == '12345'
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should not serialize fields from other forms" do
|
|
82
|
-
@results['middle_name'].should be_nil
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should submit the button that was clicked, but not other buttons" do
|
|
86
|
-
@results['awesome'].should == 'awesome'
|
|
87
|
-
@results['crappy'].should be_nil
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "should serialize radio buttons" do
|
|
91
|
-
@results['gender'].should == 'female'
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "should serialize check boxes" do
|
|
95
|
-
@results['pets'].should include('dog', 'hamster')
|
|
96
|
-
@results['pets'].should_not include('cat')
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should serialize text areas" do
|
|
100
|
-
@results['description'].should == 'Descriptive text goes here'
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "should serialize select tag with values" do
|
|
104
|
-
@results['locale'].should == 'en'
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it "should serialize select tag without values" do
|
|
108
|
-
@results['region'].should == 'Norway'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "should serialize first option for select tag with no selection" do
|
|
112
|
-
@results['city'].should == 'London'
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "should not serialize a select tag without options" do
|
|
116
|
-
@results['tendency'].should be_nil
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "should not submit disabled fields" do
|
|
120
|
-
@results['disabled_text_field'].should be_nil
|
|
121
|
-
@results['disabled_textarea'].should be_nil
|
|
122
|
-
@results['disabled_checkbox'].should be_nil
|
|
123
|
-
@results['disabled_radio'].should be_nil
|
|
124
|
-
@results['disabled_select'].should be_nil
|
|
125
|
-
@results['disabled_file'].should be_nil
|
|
126
|
-
end
|
|
49
|
+
it "should serialise and submit search fields" do
|
|
50
|
+
@results['html5_search'].should == 'what are you looking for'
|
|
127
51
|
end
|
|
128
|
-
end
|
|
129
52
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
@session.click_button('awe123')
|
|
133
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
53
|
+
it "should serialise and submit email fields" do
|
|
54
|
+
@results['html5_email'].should == 'person@email.com'
|
|
134
55
|
end
|
|
135
56
|
|
|
136
|
-
it "should
|
|
137
|
-
@
|
|
138
|
-
@session.body.should include('You landed')
|
|
57
|
+
it "should serialise and submit url fields" do
|
|
58
|
+
@results['html5_url'].should == 'http://www.example.com'
|
|
139
59
|
end
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
it "should submit the associated form" do
|
|
144
|
-
@session.click_button('What an Awesome Button')
|
|
145
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
60
|
+
|
|
61
|
+
it "should serialise and submit tel fields" do
|
|
62
|
+
@results['html5_tel'].should == '911'
|
|
146
63
|
end
|
|
147
64
|
|
|
148
|
-
it "should
|
|
149
|
-
@
|
|
150
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
65
|
+
it "should serialise and submit color fields" do
|
|
66
|
+
@results['html5_color'].should == '#FFFFFF'
|
|
151
67
|
end
|
|
152
68
|
end
|
|
153
69
|
|
|
154
|
-
context "
|
|
155
|
-
|
|
156
|
-
@session.click_button('
|
|
157
|
-
extract_results(@session)
|
|
70
|
+
context "on an HTML4 form" do
|
|
71
|
+
before do
|
|
72
|
+
@session.click_button('awesome')
|
|
73
|
+
@results = extract_results(@session)
|
|
158
74
|
end
|
|
159
75
|
|
|
160
|
-
it "should
|
|
161
|
-
@
|
|
162
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
76
|
+
it "should serialize and submit text fields" do
|
|
77
|
+
@results['first_name'].should == 'John'
|
|
163
78
|
end
|
|
164
|
-
end
|
|
165
79
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
@session.click_button('okay')
|
|
169
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
80
|
+
it "should escape fields when submitting" do
|
|
81
|
+
@results['phone'].should == '+1 555 7021'
|
|
170
82
|
end
|
|
171
83
|
|
|
172
|
-
it "should
|
|
173
|
-
@
|
|
174
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
84
|
+
it "should serialize and submit password fields" do
|
|
85
|
+
@results['password'].should == 'seeekrit'
|
|
175
86
|
end
|
|
176
|
-
end
|
|
177
87
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
@session.click_button('okay556')
|
|
181
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
88
|
+
it "should serialize and submit hidden fields" do
|
|
89
|
+
@results['token'].should == '12345'
|
|
182
90
|
end
|
|
183
|
-
end
|
|
184
91
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@session.click_button('Okay 556 Image')
|
|
188
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
92
|
+
it "should not serialize fields from other forms" do
|
|
93
|
+
@results['middle_name'].should be_nil
|
|
189
94
|
end
|
|
190
95
|
|
|
191
|
-
it "should
|
|
192
|
-
@
|
|
193
|
-
|
|
96
|
+
it "should submit the button that was clicked, but not other buttons" do
|
|
97
|
+
@results['awesome'].should == 'awesome'
|
|
98
|
+
@results['crappy'].should be_nil
|
|
194
99
|
end
|
|
195
|
-
end
|
|
196
100
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
@session.click_button('Click me')
|
|
200
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
101
|
+
it "should serialize radio buttons" do
|
|
102
|
+
@results['gender'].should == 'female'
|
|
201
103
|
end
|
|
202
104
|
|
|
203
|
-
it "should
|
|
204
|
-
@
|
|
205
|
-
|
|
105
|
+
it "should serialize check boxes" do
|
|
106
|
+
@results['pets'].should include('dog', 'hamster')
|
|
107
|
+
@results['pets'].should_not include('cat')
|
|
206
108
|
end
|
|
207
109
|
|
|
208
|
-
it "should
|
|
209
|
-
@
|
|
210
|
-
extract_results(@session)['button'].should == 'button_second'
|
|
110
|
+
it "should serialize text areas" do
|
|
111
|
+
@results['description'].should == 'Descriptive text goes here'
|
|
211
112
|
end
|
|
212
|
-
end
|
|
213
113
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
@session.click_button('click_me_123')
|
|
217
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
114
|
+
it "should serialize select tag with values" do
|
|
115
|
+
@results['locale'].should == 'en'
|
|
218
116
|
end
|
|
219
117
|
|
|
220
|
-
it "should serialize
|
|
221
|
-
@
|
|
222
|
-
@session.click_button('med')
|
|
223
|
-
@results = extract_results(@session)
|
|
224
|
-
@results['middle_name'].should == 'Darren'
|
|
225
|
-
@results['foo'].should be_nil
|
|
118
|
+
it "should serialize select tag without values" do
|
|
119
|
+
@results['region'].should == 'Norway'
|
|
226
120
|
end
|
|
227
|
-
end
|
|
228
121
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
@session.click_button('click_me')
|
|
232
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
122
|
+
it "should serialize first option for select tag with no selection" do
|
|
123
|
+
@results['city'].should == 'London'
|
|
233
124
|
end
|
|
234
125
|
|
|
235
|
-
it "should
|
|
236
|
-
@
|
|
237
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
126
|
+
it "should not serialize a select tag without options" do
|
|
127
|
+
@results['tendency'].should be_nil
|
|
238
128
|
end
|
|
239
129
|
|
|
240
|
-
it "should
|
|
241
|
-
@
|
|
242
|
-
|
|
130
|
+
it "should not submit disabled fields" do
|
|
131
|
+
@results['disabled_text_field'].should be_nil
|
|
132
|
+
@results['disabled_textarea'].should be_nil
|
|
133
|
+
@results['disabled_checkbox'].should be_nil
|
|
134
|
+
@results['disabled_radio'].should be_nil
|
|
135
|
+
@results['disabled_select'].should be_nil
|
|
136
|
+
@results['disabled_file'].should be_nil
|
|
243
137
|
end
|
|
244
138
|
end
|
|
139
|
+
end
|
|
245
140
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
141
|
+
context "with id given on a submit button" do
|
|
142
|
+
it "should submit the associated form" do
|
|
143
|
+
@session.click_button('awe123')
|
|
144
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
145
|
+
end
|
|
251
146
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
end
|
|
147
|
+
it "should work with partial matches" do
|
|
148
|
+
@session.click_button('Go')
|
|
149
|
+
@session.should have_content('You landed')
|
|
256
150
|
end
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
context "with title given on a submit button" do
|
|
154
|
+
it "should submit the associated form" do
|
|
155
|
+
@session.click_button('What an Awesome Button')
|
|
156
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
263
157
|
end
|
|
264
158
|
|
|
265
|
-
it "should
|
|
266
|
-
@session.click_button('
|
|
267
|
-
|
|
268
|
-
@results['no_value'].should_not be_nil
|
|
159
|
+
it "should work with partial matches" do
|
|
160
|
+
@session.click_button('What an Awesome')
|
|
161
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
269
162
|
end
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
@
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context "with alt given on an image button" do
|
|
166
|
+
it "should submit the associated form" do
|
|
167
|
+
@session.click_button('oh hai thar')
|
|
168
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "should work with partial matches" do
|
|
172
|
+
@session.click_button('hai')
|
|
173
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context "with value given on an image button" do
|
|
178
|
+
it "should submit the associated form" do
|
|
179
|
+
@session.click_button('okay')
|
|
180
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should work with partial matches" do
|
|
184
|
+
@session.click_button('kay')
|
|
185
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
context "with id given on an image button" do
|
|
190
|
+
it "should submit the associated form" do
|
|
191
|
+
@session.click_button('okay556')
|
|
192
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
context "with title given on an image button" do
|
|
197
|
+
it "should submit the associated form" do
|
|
198
|
+
@session.click_button('Okay 556 Image')
|
|
199
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "should work with partial matches" do
|
|
203
|
+
@session.click_button('Okay 556')
|
|
204
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context "with text given on a button defined by <button> tag" do
|
|
209
|
+
it "should submit the associated form" do
|
|
210
|
+
@session.click_button('Click me')
|
|
211
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "should work with partial matches" do
|
|
215
|
+
@session.click_button('Click')
|
|
216
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
context "with id given on a button defined by <button> tag" do
|
|
221
|
+
it "should submit the associated form" do
|
|
222
|
+
@session.click_button('click_me_123')
|
|
223
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
275
224
|
end
|
|
276
225
|
|
|
277
226
|
it "should serialize and send GET forms" do
|
|
@@ -281,24 +230,106 @@ shared_examples_for "click_button" do
|
|
|
281
230
|
@results['middle_name'].should == 'Darren'
|
|
282
231
|
@results['foo'].should be_nil
|
|
283
232
|
end
|
|
233
|
+
end
|
|
284
234
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
@session.
|
|
288
|
-
@session.
|
|
235
|
+
context "with value given on a button defined by <button> tag" do
|
|
236
|
+
it "should submit the associated form" do
|
|
237
|
+
@session.click_button('click_me')
|
|
238
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
289
239
|
end
|
|
290
240
|
|
|
291
|
-
it "should
|
|
292
|
-
@session.
|
|
293
|
-
@session.
|
|
294
|
-
|
|
241
|
+
it "should work with partial matches" do
|
|
242
|
+
@session.click_button('ck_me')
|
|
243
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
context "with title given on a button defined by <button> tag" do
|
|
248
|
+
it "should submit the associated form" do
|
|
249
|
+
@session.click_button('Click Title button')
|
|
250
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
295
251
|
end
|
|
296
252
|
|
|
297
|
-
it "should
|
|
298
|
-
@session.
|
|
299
|
-
@session.
|
|
300
|
-
@session.body.should include('Postback')
|
|
253
|
+
it "should work with partial matches" do
|
|
254
|
+
@session.click_button('Click Title')
|
|
255
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
301
256
|
end
|
|
302
257
|
end
|
|
258
|
+
context "with a locator that doesn't exist" do
|
|
259
|
+
it "should raise an error" do
|
|
260
|
+
msg = "Unable to find button \"does not exist\""
|
|
261
|
+
expect do
|
|
262
|
+
@session.click_button('does not exist')
|
|
263
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "should serialize and send valueless buttons that were clicked" do
|
|
268
|
+
@session.click_button('No Value!')
|
|
269
|
+
@results = extract_results(@session)
|
|
270
|
+
@results['no_value'].should_not be_nil
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "should not send image buttons that were not clicked" do
|
|
274
|
+
@session.click_button('Click me!')
|
|
275
|
+
@results = extract_results(@session)
|
|
276
|
+
@results['okay'].should be_nil
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
it "should serialize and send GET forms" do
|
|
280
|
+
@session.visit('/form')
|
|
281
|
+
@session.click_button('med')
|
|
282
|
+
@results = extract_results(@session)
|
|
283
|
+
@results['middle_name'].should == 'Darren'
|
|
284
|
+
@results['foo'].should be_nil
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "should follow redirects" do
|
|
288
|
+
@session.click_button('Go FAR')
|
|
289
|
+
@session.current_url.should match(%r{/landed$})
|
|
290
|
+
@session.should have_content('You landed')
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "should post pack to the same URL when no action given" do
|
|
294
|
+
@session.visit('/postback')
|
|
295
|
+
@session.click_button('With no action')
|
|
296
|
+
@session.should have_content('Postback')
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it "should post pack to the same URL when blank action given" do
|
|
300
|
+
@session.visit('/postback')
|
|
301
|
+
@session.click_button('With blank action')
|
|
302
|
+
@session.should have_content('Postback')
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it "ignores disabled buttons" do
|
|
306
|
+
expect do
|
|
307
|
+
@session.click_button('Disabled button')
|
|
308
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
it "should encode complex field names, like array[][value]" do
|
|
312
|
+
@session.visit('/form')
|
|
313
|
+
@session.fill_in('address1_city', :with =>'Paris')
|
|
314
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
|
315
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
|
316
|
+
@session.select("France", :from => 'address1_country')
|
|
303
317
|
|
|
318
|
+
@session.fill_in('address2_city', :with => 'Mikolaiv')
|
|
319
|
+
@session.fill_in('address2_street', :with => 'PGS')
|
|
320
|
+
@session.select("Ukraine", :from => 'address2_country')
|
|
321
|
+
|
|
322
|
+
@session.click_button "awesome"
|
|
323
|
+
|
|
324
|
+
addresses=extract_results(@session)["addresses"]
|
|
325
|
+
addresses.should have(2).addresses
|
|
326
|
+
|
|
327
|
+
addresses[0]["street"].should == 'CDG'
|
|
328
|
+
addresses[0]["city"].should == 'Paris'
|
|
329
|
+
addresses[0]["country"].should == 'France'
|
|
330
|
+
|
|
331
|
+
addresses[1]["street"].should == 'PGS'
|
|
332
|
+
addresses[1]["city"].should == 'Mikolaiv'
|
|
333
|
+
addresses[1]["country"].should == 'Ukraine'
|
|
334
|
+
end
|
|
304
335
|
end
|
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#click_link_or_button' do
|
|
2
|
+
it "should click on a link" do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
@session.click_link_or_button('labore')
|
|
5
|
+
@session.should have_content('Bar')
|
|
6
|
+
end
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
it "should click on a button" do
|
|
9
|
+
@session.visit('/form')
|
|
10
|
+
@session.click_link_or_button('awe123')
|
|
11
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
12
|
+
end
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
it "should click on a button with no type attribute" do
|
|
15
|
+
@session.visit('/form')
|
|
16
|
+
@session.click_link_or_button('no_type')
|
|
17
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
it "should be aliased as click_on" do
|
|
21
|
+
@session.visit('/form')
|
|
22
|
+
@session.click_on('awe123')
|
|
23
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
27
|
+
@session.visit('/with_js')
|
|
28
|
+
@session.click_link('Click me')
|
|
29
|
+
@session.click_link_or_button('Has been clicked')
|
|
30
|
+
end
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
it "casts to string" do
|
|
33
|
+
@session.visit('/form')
|
|
34
|
+
@session.click_link_or_button(:'awe123')
|
|
35
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "with a locator that doesn't exist" do
|
|
39
|
+
it "should raise an error" do
|
|
40
|
+
@session.visit('/with_html')
|
|
41
|
+
msg = "Unable to find link or button \"does not exist\""
|
|
42
|
+
expect do
|
|
43
|
+
@session.click_link_or_button('does not exist')
|
|
44
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
34
45
|
end
|
|
35
46
|
end
|
|
36
47
|
end
|