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,306 +0,0 @@
|
|
|
1
|
-
shared_examples_for "session with javascript support" do
|
|
2
|
-
describe 'all JS specs' do
|
|
3
|
-
before do
|
|
4
|
-
Capybara.default_wait_time = 1
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
after do
|
|
8
|
-
Capybara.default_wait_time = 0
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe 'Node#drag_to' do
|
|
12
|
-
it "should drag and drop an object" do
|
|
13
|
-
@session.visit('/with_js')
|
|
14
|
-
element = @session.find('//div[@id="drag"]')
|
|
15
|
-
target = @session.find('//div[@id="drop"]')
|
|
16
|
-
element.drag_to(target)
|
|
17
|
-
@session.find('//div[contains(., "Dropped!")]').should_not be_nil
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe 'Node#reload' do
|
|
22
|
-
context "without automatic reload" do
|
|
23
|
-
before { Capybara.automatic_reload = false }
|
|
24
|
-
it "should reload the current context of the node" do
|
|
25
|
-
@session.visit('/with_js')
|
|
26
|
-
node = @session.find(:css, '#reload-me')
|
|
27
|
-
@session.click_link('Reload!')
|
|
28
|
-
sleep(0.3)
|
|
29
|
-
node.reload.text.should == 'has been reloaded'
|
|
30
|
-
node.text.should == 'has been reloaded'
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should reload a parent node" do
|
|
34
|
-
@session.visit('/with_js')
|
|
35
|
-
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
|
36
|
-
@session.click_link('Reload!')
|
|
37
|
-
sleep(0.3)
|
|
38
|
-
node.reload.text.should == 'has been reloaded'
|
|
39
|
-
node.text.should == 'has been reloaded'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should not automatically reload" do
|
|
43
|
-
@session.visit('/with_js')
|
|
44
|
-
node = @session.find(:css, '#reload-me')
|
|
45
|
-
@session.click_link('Reload!')
|
|
46
|
-
sleep(0.3)
|
|
47
|
-
running { node.text.should == 'has been reloaded' }.should raise_error
|
|
48
|
-
end
|
|
49
|
-
after { Capybara.automatic_reload = true }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context "with automatic reload" do
|
|
53
|
-
it "should reload the current context of the node automatically" do
|
|
54
|
-
@session.visit('/with_js')
|
|
55
|
-
node = @session.find(:css, '#reload-me')
|
|
56
|
-
@session.click_link('Reload!')
|
|
57
|
-
sleep(0.3)
|
|
58
|
-
node.text.should == 'has been reloaded'
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should reload a parent node automatically" do
|
|
62
|
-
@session.visit('/with_js')
|
|
63
|
-
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
|
64
|
-
@session.click_link('Reload!')
|
|
65
|
-
sleep(0.3)
|
|
66
|
-
node.text.should == 'has been reloaded'
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "should reload a node automatically when using find" do
|
|
70
|
-
@session.visit('/with_js')
|
|
71
|
-
node = @session.find(:css, '#reload-me')
|
|
72
|
-
@session.click_link('Reload!')
|
|
73
|
-
sleep(0.3)
|
|
74
|
-
node.find(:css, 'a').text.should == 'has been reloaded'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should not reload nodes which haven't been found" do
|
|
78
|
-
@session.visit('/with_js')
|
|
79
|
-
node = @session.all(:css, '#the-list li')[1]
|
|
80
|
-
@session.click_link('Fetch new list!')
|
|
81
|
-
sleep(0.3)
|
|
82
|
-
running { node.text.should == 'Foo' }.should raise_error
|
|
83
|
-
running { node.text.should == 'Bar' }.should raise_error
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "should reload nodes with options" do
|
|
87
|
-
@session.visit('/with_js')
|
|
88
|
-
node = @session.find(:css, 'em', :text => "reloaded")
|
|
89
|
-
@session.click_link('Reload!')
|
|
90
|
-
sleep(1)
|
|
91
|
-
node.text.should == 'has been reloaded'
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
describe '#find' do
|
|
97
|
-
it "should allow triggering of custom JS events" do
|
|
98
|
-
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
|
99
|
-
@session.visit('/with_js')
|
|
100
|
-
@session.find(:css, '#with_focus_event').trigger(:focus)
|
|
101
|
-
@session.should have_css('#focus_event_triggered')
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
describe '#body' do
|
|
106
|
-
it "should return the current state of the page" do
|
|
107
|
-
@session.visit('/with_js')
|
|
108
|
-
@session.body.should include('I changed it')
|
|
109
|
-
@session.body.should_not include('This is text')
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
describe '#source' do
|
|
114
|
-
it "should return the original, unmodified source of the page" do
|
|
115
|
-
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
|
116
|
-
@session.visit('/with_js')
|
|
117
|
-
@session.source.should include('This is text')
|
|
118
|
-
@session.source.should_not include('I changed it')
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
describe "#evaluate_script" do
|
|
123
|
-
it "should evaluate the given script and return whatever it produces" do
|
|
124
|
-
@session.visit('/with_js')
|
|
125
|
-
@session.evaluate_script("1+3").should == 4
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe "#execute_script" do
|
|
130
|
-
it "should execute the given script and return nothing" do
|
|
131
|
-
@session.visit('/with_js')
|
|
132
|
-
@session.execute_script("$('#change').text('Funky Doodle')").should be_nil
|
|
133
|
-
@session.should have_css('#change', :text => 'Funky Doodle')
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe '#find' do
|
|
138
|
-
it "should wait for asynchronous load" do
|
|
139
|
-
@session.visit('/with_js')
|
|
140
|
-
@session.click_link('Click me')
|
|
141
|
-
@session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "with frozen time" do
|
|
145
|
-
it "raises an error suggesting that Capybara is stuck in time" do
|
|
146
|
-
@session.visit('/with_js')
|
|
147
|
-
now = Time.now
|
|
148
|
-
Time.stub(:now).and_return(now)
|
|
149
|
-
expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
describe '#wait_until' do
|
|
155
|
-
before do
|
|
156
|
-
@default_timeout = Capybara.default_wait_time
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
after do
|
|
160
|
-
Capybara.default_wait_time = @default_wait_time
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "should wait for block to return true" do
|
|
164
|
-
@session.visit('/with_js')
|
|
165
|
-
@session.select('My Waiting Option', :from => 'waiter')
|
|
166
|
-
@session.evaluate_script('activeRequests == 1').should be_true
|
|
167
|
-
@session.wait_until do
|
|
168
|
-
@session.evaluate_script('activeRequests == 0')
|
|
169
|
-
end
|
|
170
|
-
@session.evaluate_script('activeRequests == 0').should be_true
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
|
|
174
|
-
@session.visit('/with_html')
|
|
175
|
-
Proc.new do
|
|
176
|
-
@session.wait_until(0.1) do
|
|
177
|
-
@session.all('//div[@id="nosuchthing"]').first
|
|
178
|
-
end
|
|
179
|
-
end.should raise_error(::Capybara::TimeoutError)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "should accept custom timeout in seconds" do
|
|
183
|
-
start = Time.now
|
|
184
|
-
Capybara.default_wait_time = 5
|
|
185
|
-
begin
|
|
186
|
-
@session.wait_until(0.1) { false }
|
|
187
|
-
rescue Capybara::TimeoutError; end
|
|
188
|
-
(Time.now - start).should be_within(0.1).of(0.1)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it "should default to Capybara.default_wait_time before timeout" do
|
|
192
|
-
@session.driver # init the driver to exclude init timing from test
|
|
193
|
-
start = Time.now
|
|
194
|
-
Capybara.default_wait_time = 0.2
|
|
195
|
-
begin
|
|
196
|
-
@session.wait_until { false }
|
|
197
|
-
rescue Capybara::TimeoutError; end
|
|
198
|
-
if @session.driver.has_shortcircuit_timeout?
|
|
199
|
-
(Time.now - start).should be_within(0.1).of(0)
|
|
200
|
-
else
|
|
201
|
-
(Time.now - start).should be_within(0.1).of(0.2)
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
describe '#click_link_or_button' do
|
|
207
|
-
it "should wait for asynchronous load" do
|
|
208
|
-
@session.visit('/with_js')
|
|
209
|
-
@session.click_link('Click me')
|
|
210
|
-
@session.click_link_or_button('Has been clicked')
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
describe '#click_link' do
|
|
215
|
-
it "should wait for asynchronous load" do
|
|
216
|
-
@session.visit('/with_js')
|
|
217
|
-
@session.click_link('Click me')
|
|
218
|
-
@session.click_link('Has been clicked')
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
describe '#click_button' do
|
|
223
|
-
it "should wait for asynchronous load" do
|
|
224
|
-
@session.visit('/with_js')
|
|
225
|
-
@session.click_link('Click me')
|
|
226
|
-
@session.click_button('New Here')
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
describe '#fill_in' do
|
|
231
|
-
it "should wait for asynchronous load" do
|
|
232
|
-
@session.visit('/with_js')
|
|
233
|
-
@session.click_link('Click me')
|
|
234
|
-
@session.fill_in('new_field', :with => 'Testing...')
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
describe '#check' do
|
|
239
|
-
it "should trigger associated events" do
|
|
240
|
-
@session.visit('/with_js')
|
|
241
|
-
@session.check('checkbox_with_event')
|
|
242
|
-
@session.should have_css('#checkbox_event_triggered');
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
describe '#has_xpath?' do
|
|
247
|
-
it "should wait for content to appear" do
|
|
248
|
-
@session.visit('/with_js')
|
|
249
|
-
@session.click_link('Click me')
|
|
250
|
-
@session.should have_xpath("//input[@type='submit' and @value='New Here']")
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
describe '#has_no_xpath?' do
|
|
255
|
-
it "should wait for content to disappear" do
|
|
256
|
-
@session.visit('/with_js')
|
|
257
|
-
@session.click_link('Click me')
|
|
258
|
-
@session.should have_no_xpath("//p[@id='change']")
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
describe '#has_css?' do
|
|
263
|
-
it "should wait for content to appear" do
|
|
264
|
-
@session.visit('/with_js')
|
|
265
|
-
@session.click_link('Click me')
|
|
266
|
-
@session.should have_css("input[type='submit'][value='New Here']")
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
describe '#has_no_xpath?' do
|
|
271
|
-
it "should wait for content to disappear" do
|
|
272
|
-
@session.visit('/with_js')
|
|
273
|
-
@session.click_link('Click me')
|
|
274
|
-
@session.should have_no_css("p#change")
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
describe '#has_content?' do
|
|
279
|
-
it "should wait for content to appear" do
|
|
280
|
-
@session.visit('/with_js')
|
|
281
|
-
@session.click_link('Click me')
|
|
282
|
-
@session.should have_content("Has been clicked")
|
|
283
|
-
end
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
describe '#has_no_content?' do
|
|
287
|
-
it "should wait for content to disappear" do
|
|
288
|
-
@session.visit('/with_js')
|
|
289
|
-
@session.click_link('Click me')
|
|
290
|
-
@session.should have_no_content("I changed it")
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
shared_examples_for "session without javascript support" do
|
|
298
|
-
describe "#evaluate_script" do
|
|
299
|
-
before{ @session.visit('/with_simple_html') }
|
|
300
|
-
it "should raise an error" do
|
|
301
|
-
running {
|
|
302
|
-
@session.evaluate_script('3 + 3')
|
|
303
|
-
}.should raise_error(Capybara::NotSupportedByDriverError)
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
end
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
require 'capybara/spec/test_app'
|
|
2
|
-
require 'nokogiri'
|
|
3
|
-
|
|
4
|
-
Dir[File.dirname(__FILE__)+'/session/*'].each { |group| require group }
|
|
5
|
-
|
|
6
|
-
shared_examples_for "session" do
|
|
7
|
-
def extract_results(session)
|
|
8
|
-
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
after do
|
|
12
|
-
@session.reset_session!
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '#visit' do
|
|
16
|
-
it "should fetch a response from the driver" do
|
|
17
|
-
@session.visit('/')
|
|
18
|
-
@session.body.should include('Hello world!')
|
|
19
|
-
@session.visit('/foo')
|
|
20
|
-
@session.body.should include('Another World')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe '#body' do
|
|
25
|
-
it "should return the unmodified page body" do
|
|
26
|
-
@session.visit('/')
|
|
27
|
-
@session.body.should include('Hello world!')
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe '#html' do
|
|
32
|
-
it "should return the unmodified page body" do
|
|
33
|
-
# html and body should be aliased, but we can't just check for
|
|
34
|
-
# method(:html) == method(:body) because these shared examples get run
|
|
35
|
-
# against the DSL, which uses forwarding methods. So we test behavior.
|
|
36
|
-
@session.visit('/')
|
|
37
|
-
@session.body.should include('Hello world!')
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe '#source' do
|
|
42
|
-
it "should return the unmodified page source" do
|
|
43
|
-
@session.visit('/')
|
|
44
|
-
@session.source.should include('Hello world!')
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe '#reset_session!' do
|
|
49
|
-
it "removes cookies" do
|
|
50
|
-
@session.visit('/set_cookie')
|
|
51
|
-
@session.visit('/get_cookie')
|
|
52
|
-
@session.body.should include('test_cookie')
|
|
53
|
-
|
|
54
|
-
@session.reset_session!
|
|
55
|
-
@session.visit('/get_cookie')
|
|
56
|
-
@session.body.should_not include('test_cookie')
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "resets current host" do
|
|
60
|
-
@session.visit('http://capybara-testapp.heroku.com')
|
|
61
|
-
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
|
62
|
-
|
|
63
|
-
@session.reset_session!
|
|
64
|
-
@session.current_host.should be_nil
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "resets current path" do
|
|
68
|
-
@session.visit('/with_html')
|
|
69
|
-
@session.current_path.should == '/with_html'
|
|
70
|
-
|
|
71
|
-
@session.reset_session!
|
|
72
|
-
@session.current_path.should be_nil
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "resets page body" do
|
|
76
|
-
@session.visit('/with_html')
|
|
77
|
-
@session.body.should include('This is a test')
|
|
78
|
-
@session.find('.//h1').text.should include('This is a test')
|
|
79
|
-
|
|
80
|
-
@session.reset_session!
|
|
81
|
-
@session.body.should_not include('This is a test')
|
|
82
|
-
@session.should have_no_selector('.//h1')
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it_should_behave_like "all"
|
|
87
|
-
it_should_behave_like "first"
|
|
88
|
-
it_should_behave_like "attach_file"
|
|
89
|
-
it_should_behave_like "check"
|
|
90
|
-
it_should_behave_like "choose"
|
|
91
|
-
it_should_behave_like "click_link_or_button"
|
|
92
|
-
it_should_behave_like "click_button"
|
|
93
|
-
it_should_behave_like "click_link"
|
|
94
|
-
it_should_behave_like "fill_in"
|
|
95
|
-
it_should_behave_like "find_button"
|
|
96
|
-
it_should_behave_like "find_field"
|
|
97
|
-
it_should_behave_like "find_link"
|
|
98
|
-
it_should_behave_like "find_by_id"
|
|
99
|
-
it_should_behave_like "find"
|
|
100
|
-
it_should_behave_like "has_content"
|
|
101
|
-
it_should_behave_like "has_css"
|
|
102
|
-
it_should_behave_like "has_css"
|
|
103
|
-
it_should_behave_like "has_selector"
|
|
104
|
-
it_should_behave_like "has_xpath"
|
|
105
|
-
it_should_behave_like "has_link"
|
|
106
|
-
it_should_behave_like "has_button"
|
|
107
|
-
it_should_behave_like "has_field"
|
|
108
|
-
it_should_behave_like "has_select"
|
|
109
|
-
it_should_behave_like "has_table"
|
|
110
|
-
it_should_behave_like "select"
|
|
111
|
-
it_should_behave_like "text"
|
|
112
|
-
it_should_behave_like "uncheck"
|
|
113
|
-
it_should_behave_like "unselect"
|
|
114
|
-
it_should_behave_like "within"
|
|
115
|
-
it_should_behave_like "current_url"
|
|
116
|
-
it_should_behave_like "current_host"
|
|
117
|
-
|
|
118
|
-
it "should encode complex field names, like array[][value]" do
|
|
119
|
-
@session.visit('/form')
|
|
120
|
-
@session.fill_in('address1_city', :with =>'Paris')
|
|
121
|
-
@session.fill_in('address1_street', :with =>'CDG')
|
|
122
|
-
@session.fill_in('address1_street', :with =>'CDG')
|
|
123
|
-
@session.select("France", :from => 'address1_country')
|
|
124
|
-
|
|
125
|
-
@session.fill_in('address2_city', :with => 'Mikolaiv')
|
|
126
|
-
@session.fill_in('address2_street', :with => 'PGS')
|
|
127
|
-
@session.select("Ukraine", :from => 'address2_country')
|
|
128
|
-
|
|
129
|
-
@session.click_button "awesome"
|
|
130
|
-
|
|
131
|
-
addresses=extract_results(@session)["addresses"]
|
|
132
|
-
addresses.should have(2).addresses
|
|
133
|
-
|
|
134
|
-
addresses[0]["street"].should == 'CDG'
|
|
135
|
-
addresses[0]["city"].should == 'Paris'
|
|
136
|
-
addresses[0]["country"].should == 'France'
|
|
137
|
-
|
|
138
|
-
addresses[1]["street"].should == 'PGS'
|
|
139
|
-
addresses[1]["city"].should == 'Mikolaiv'
|
|
140
|
-
addresses[1]["country"].should == 'Ukraine'
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
describe Capybara::Session do
|
|
147
|
-
context 'with non-existant driver' do
|
|
148
|
-
it "should raise an error" do
|
|
149
|
-
running {
|
|
150
|
-
Capybara::Session.new(:quox, TestApp).driver
|
|
151
|
-
}.should raise_error(Capybara::DriverNotFoundError)
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module Capybara
|
|
2
|
-
class << self
|
|
3
|
-
def save_page(html, file_name=nil)
|
|
4
|
-
file_name ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
|
|
5
|
-
name = File.join(*[Capybara.save_and_open_page_path, file_name].compact)
|
|
6
|
-
|
|
7
|
-
unless Capybara.save_and_open_page_path.nil? || File.directory?(Capybara.save_and_open_page_path )
|
|
8
|
-
FileUtils.mkdir_p(Capybara.save_and_open_page_path)
|
|
9
|
-
end
|
|
10
|
-
FileUtils.touch(name) unless File.exist?(name)
|
|
11
|
-
|
|
12
|
-
tempfile = File.new(name,'w')
|
|
13
|
-
tempfile.write(rewrite_css_and_image_references(html))
|
|
14
|
-
tempfile.close
|
|
15
|
-
tempfile.path
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def save_and_open_page(html, file_name=nil)
|
|
19
|
-
open_in_browser save_page(html, file_name)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
protected
|
|
23
|
-
|
|
24
|
-
def open_in_browser(path) # :nodoc
|
|
25
|
-
require "launchy"
|
|
26
|
-
Launchy.open(path)
|
|
27
|
-
rescue LoadError
|
|
28
|
-
warn "Sorry, you need to install launchy (`gem install launchy`) and " <<
|
|
29
|
-
"make sure it's available to open pages with `save_and_open_page`."
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def rewrite_css_and_image_references(response_html) # :nodoc:
|
|
33
|
-
root = Capybara.asset_root
|
|
34
|
-
return response_html unless root
|
|
35
|
-
directories = Dir.new(root).entries.select { |name|
|
|
36
|
-
(root+name).directory? and not name.to_s =~ /^\./
|
|
37
|
-
}
|
|
38
|
-
if not directories.empty?
|
|
39
|
-
response_html.gsub!(/("|')\/(#{directories.join('|')})/, '\1' + root.to_s + '/\2')
|
|
40
|
-
end
|
|
41
|
-
return response_html
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Capybara
|
|
2
|
-
class << self
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
# Provides timeout similar to standard library Timeout, but avoids threads
|
|
6
|
-
#
|
|
7
|
-
def timeout(seconds = 1, driver = nil, error_message = nil, &block)
|
|
8
|
-
start_time = Time.now
|
|
9
|
-
|
|
10
|
-
result = nil
|
|
11
|
-
|
|
12
|
-
until result
|
|
13
|
-
return result if result = yield
|
|
14
|
-
|
|
15
|
-
delay = seconds - (Time.now - start_time)
|
|
16
|
-
if delay <= 0
|
|
17
|
-
raise TimeoutError, error_message || "timed out"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
driver && driver.wait_until(delay)
|
|
21
|
-
|
|
22
|
-
sleep(0.05)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
require 'stringio'
|
|
4
|
-
|
|
5
|
-
def capture(*streams)
|
|
6
|
-
streams.map! { |stream| stream.to_s }
|
|
7
|
-
begin
|
|
8
|
-
result = StringIO.new
|
|
9
|
-
streams.each { |stream| eval "$#{stream} = result" }
|
|
10
|
-
yield
|
|
11
|
-
ensure
|
|
12
|
-
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
|
|
13
|
-
end
|
|
14
|
-
result.string
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe Capybara::RackTest::Driver do
|
|
18
|
-
before do
|
|
19
|
-
@driver = TestSessions::RackTest.driver
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should throw an error when no rack app is given" do
|
|
23
|
-
running do
|
|
24
|
-
Capybara::RackTest::Driver.new(nil)
|
|
25
|
-
end.should raise_error(ArgumentError)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it_should_behave_like "driver"
|
|
29
|
-
it_should_behave_like "driver with header support"
|
|
30
|
-
it_should_behave_like "driver with status code support"
|
|
31
|
-
it_should_behave_like "driver with cookies support"
|
|
32
|
-
it_should_behave_like "driver with infinite redirect detection"
|
|
33
|
-
|
|
34
|
-
describe '#reset!' do
|
|
35
|
-
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
|
|
36
|
-
|
|
37
|
-
it 'should reset headers' do
|
|
38
|
-
@driver.header('FOO', 'BAR')
|
|
39
|
-
@driver.visit('/get_header')
|
|
40
|
-
@driver.body.should include('BAR')
|
|
41
|
-
|
|
42
|
-
@driver.reset!
|
|
43
|
-
@driver.visit('/get_header')
|
|
44
|
-
@driver.body.should_not include('BAR')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'should reset response' do
|
|
48
|
-
@driver.visit('/foo')
|
|
49
|
-
lambda { @driver.response }.should_not raise_error
|
|
50
|
-
@driver.reset!
|
|
51
|
-
lambda { @driver.response }.should raise_error
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'should request response' do
|
|
55
|
-
@driver.visit('/foo')
|
|
56
|
-
lambda { @driver.request }.should_not raise_error
|
|
57
|
-
@driver.reset!
|
|
58
|
-
lambda { @driver.request }.should raise_error
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
describe ':headers option' do
|
|
63
|
-
it 'should always set headers' do
|
|
64
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
|
65
|
-
@driver.visit('/get_header')
|
|
66
|
-
@driver.body.should include('foobar')
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'should keep headers on link clicks' do
|
|
70
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
|
71
|
-
@driver.visit('/header_links')
|
|
72
|
-
@driver.find('.//a').first.click
|
|
73
|
-
@driver.body.should include('foobar')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'should keep headers on form submit' do
|
|
77
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
|
78
|
-
@driver.visit('/header_links')
|
|
79
|
-
@driver.find('.//input').first.click
|
|
80
|
-
@driver.body.should include('foobar')
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'should keep headers on redirects' do
|
|
84
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
|
85
|
-
@driver.visit('/get_header_via_redirect')
|
|
86
|
-
@driver.body.should include('foobar')
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'rbconfig'
|
|
3
|
-
|
|
4
|
-
describe Capybara::Selenium::Driver do
|
|
5
|
-
before do
|
|
6
|
-
@driver = TestSessions::Selenium.driver
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it_should_behave_like "driver"
|
|
10
|
-
it_should_behave_like "driver with javascript support"
|
|
11
|
-
it_should_behave_like "driver with resynchronization support"
|
|
12
|
-
it_should_behave_like "driver with frame support"
|
|
13
|
-
it_should_behave_like "driver with support for window switching"
|
|
14
|
-
it_should_behave_like "driver without status code support"
|
|
15
|
-
it_should_behave_like "driver with cookies support"
|
|
16
|
-
|
|
17
|
-
describe "exit codes" do
|
|
18
|
-
before do
|
|
19
|
-
@current_dir = Dir.getwd
|
|
20
|
-
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
after do
|
|
24
|
-
Dir.chdir(@current_dir)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
|
|
28
|
-
`rspec spec/fixtures/selenium_driver_rspec_failure.rb`
|
|
29
|
-
$?.exitstatus.should be 1
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should have return code 0 when running selenium_driver_rspec_success.rb" do
|
|
33
|
-
`rspec spec/fixtures/selenium_driver_rspec_success.rb`
|
|
34
|
-
$?.exitstatus.should be 0
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|