pr0d1r2-capybara 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +71 -0
- data/README.rdoc +388 -0
- data/lib/capybara.rb +57 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +48 -0
- data/lib/capybara/driver/celerity_driver.rb +143 -0
- data/lib/capybara/driver/culerity_driver.rb +25 -0
- data/lib/capybara/driver/rack_test_driver.rb +271 -0
- data/lib/capybara/driver/selenium_driver.rb +161 -0
- data/lib/capybara/dsl.rb +60 -0
- data/lib/capybara/node.rb +60 -0
- data/lib/capybara/rails.rb +17 -0
- data/lib/capybara/save_and_open_page.rb +33 -0
- data/lib/capybara/searchable.rb +54 -0
- data/lib/capybara/server.rb +114 -0
- data/lib/capybara/session.rb +262 -0
- data/lib/capybara/spec/driver.rb +162 -0
- data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
- data/lib/capybara/spec/fixtures/test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +35 -0
- data/lib/capybara/spec/public/jquery.js +19 -0
- data/lib/capybara/spec/public/test.js +33 -0
- data/lib/capybara/spec/session.rb +81 -0
- data/lib/capybara/spec/session/all_spec.rb +69 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -0
- data/lib/capybara/spec/session/choose_spec.rb +26 -0
- data/lib/capybara/spec/session/click_button_spec.rb +236 -0
- data/lib/capybara/spec/session/click_link_spec.rb +108 -0
- data/lib/capybara/spec/session/click_spec.rb +24 -0
- data/lib/capybara/spec/session/current_url_spec.rb +8 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +108 -0
- data/lib/capybara/spec/session/find_button_spec.rb +16 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -0
- data/lib/capybara/spec/session/find_field_spec.rb +22 -0
- data/lib/capybara/spec/session/find_link_spec.rb +17 -0
- data/lib/capybara/spec/session/find_spec.rb +57 -0
- data/lib/capybara/spec/session/has_button_spec.rb +32 -0
- data/lib/capybara/spec/session/has_content_spec.rb +106 -0
- data/lib/capybara/spec/session/has_css_spec.rb +107 -0
- data/lib/capybara/spec/session/has_field_spec.rb +96 -0
- data/lib/capybara/spec/session/has_link_spec.rb +33 -0
- data/lib/capybara/spec/session/has_select_spec.rb +89 -0
- data/lib/capybara/spec/session/has_table_spec.rb +96 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
- data/lib/capybara/spec/session/headers.rb +19 -0
- data/lib/capybara/spec/session/javascript.rb +204 -0
- data/lib/capybara/spec/session/locate_spec.rb +59 -0
- data/lib/capybara/spec/session/select_spec.rb +77 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
- data/lib/capybara/spec/session/unselect_spec.rb +54 -0
- data/lib/capybara/spec/session/within_spec.rb +153 -0
- data/lib/capybara/spec/test_app.rb +75 -0
- data/lib/capybara/spec/views/buttons.erb +4 -0
- data/lib/capybara/spec/views/fieldsets.erb +29 -0
- data/lib/capybara/spec/views/form.erb +234 -0
- data/lib/capybara/spec/views/frame_one.erb +8 -0
- data/lib/capybara/spec/views/frame_two.erb +8 -0
- data/lib/capybara/spec/views/postback.erb +13 -0
- data/lib/capybara/spec/views/tables.erb +122 -0
- data/lib/capybara/spec/views/with_html.erb +42 -0
- data/lib/capybara/spec/views/with_js.erb +39 -0
- data/lib/capybara/spec/views/with_scope.erb +36 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +10 -0
- data/lib/capybara/version.rb +3 -0
- data/lib/capybara/wait_until.rb +28 -0
- data/lib/capybara/xpath.rb +179 -0
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +16 -0
- data/spec/driver/culerity_driver_spec.rb +12 -0
- data/spec/driver/rack_test_driver_spec.rb +11 -0
- data/spec/driver/remote_culerity_driver_spec.rb +23 -0
- data/spec/driver/remote_selenium_driver_spec.rb +18 -0
- data/spec/driver/selenium_driver_spec.rb +11 -0
- data/spec/dsl_spec.rb +140 -0
- data/spec/save_and_open_page_spec.rb +43 -0
- data/spec/searchable_spec.rb +66 -0
- data/spec/server_spec.rb +53 -0
- data/spec/session/celerity_session_spec.rb +27 -0
- data/spec/session/culerity_session_spec.rb +25 -0
- data/spec/session/rack_test_session_spec.rb +33 -0
- data/spec/session/selenium_session_spec.rb +25 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/wait_until_spec.rb +28 -0
- data/spec/xpath_spec.rb +180 -0
- metadata +259 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
shared_examples_for "session with headers support" do
|
2
|
+
describe '#response_headers' do
|
3
|
+
it "should return response headers" do
|
4
|
+
@session.visit('/with_simple_html')
|
5
|
+
@session.response_headers['Content-Type'].should == 'text/html'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_examples_for "session without headers support" do
|
11
|
+
describe "#response_headers" do
|
12
|
+
before{ @session.visit('/with_simple_html') }
|
13
|
+
it "should raise an error" do
|
14
|
+
running {
|
15
|
+
@session.response_headers
|
16
|
+
}.should raise_error(Capybara::NotSupportedByDriverError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,204 @@
|
|
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 '#find' do
|
12
|
+
it "should allow triggering of custom JS events" do
|
13
|
+
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
14
|
+
@session.visit('/with_js')
|
15
|
+
@session.find(:css, '#with_focus_event').trigger(:focus)
|
16
|
+
@session.should have_css('#focus_event_triggered')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#body' do
|
21
|
+
it "should return the current state of the page" do
|
22
|
+
@session.visit('/with_js')
|
23
|
+
@session.body.should include('I changed it')
|
24
|
+
@session.body.should_not include('This is text')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#source' do
|
29
|
+
it "should return the original, unmodified source of the page" do
|
30
|
+
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
31
|
+
@session.visit('/with_js')
|
32
|
+
@session.source.should include('This is text')
|
33
|
+
@session.source.should_not include('I changed it')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#evaluate_script" do
|
38
|
+
it "should return the evaluated script" do
|
39
|
+
@session.visit('/with_js')
|
40
|
+
@session.evaluate_script("1+3").should == 4
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#locate' do
|
45
|
+
it "should wait for asynchronous load" do
|
46
|
+
@session.visit('/with_js')
|
47
|
+
@session.click_link('Click me')
|
48
|
+
@session.locate("//a[contains(.,'Has been clicked')]")[:href].should == '#'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#wait_until' do
|
53
|
+
before do
|
54
|
+
@default_timeout = Capybara.default_wait_time
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
Capybara.default_wait_time = @default_wait_time
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should wait for block to return true" do
|
62
|
+
@session.visit('/with_js')
|
63
|
+
@session.select('My Waiting Option', :from => 'waiter')
|
64
|
+
@session.evaluate_script('activeRequests == 1').should be_true
|
65
|
+
@session.wait_until do
|
66
|
+
@session.evaluate_script('activeRequests == 0')
|
67
|
+
end
|
68
|
+
@session.evaluate_script('activeRequests == 0').should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
|
72
|
+
@session.visit('/with_html')
|
73
|
+
Proc.new do
|
74
|
+
@session.wait_until(0.1) do
|
75
|
+
@session.find('//div[@id="nosuchthing"]')
|
76
|
+
end
|
77
|
+
end.should raise_error(::Capybara::TimeoutError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should accept custom timeout in seconds" do
|
81
|
+
start = Time.now
|
82
|
+
Capybara.default_wait_time = 5
|
83
|
+
begin
|
84
|
+
@session.wait_until(0.1) { false }
|
85
|
+
rescue Capybara::TimeoutError; end
|
86
|
+
(Time.now - start).should be_close(0.1, 0.1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should default to Capybara.default_wait_time before timeout" do
|
90
|
+
@session.driver # init the driver to exclude init timing from test
|
91
|
+
start = Time.now
|
92
|
+
Capybara.default_wait_time = 0.2
|
93
|
+
begin
|
94
|
+
@session.wait_until { false }
|
95
|
+
rescue Capybara::TimeoutError; end
|
96
|
+
if @session.driver.has_shortcircuit_timeout?
|
97
|
+
(Time.now - start).should be_close(0, 0.1)
|
98
|
+
else
|
99
|
+
(Time.now - start).should be_close(0.2, 0.1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#click' do
|
105
|
+
it "should wait for asynchronous load" do
|
106
|
+
@session.visit('/with_js')
|
107
|
+
@session.click_link('Click me')
|
108
|
+
@session.click('Has been clicked')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#click_link' do
|
113
|
+
it "should wait for asynchronous load" do
|
114
|
+
@session.visit('/with_js')
|
115
|
+
@session.click_link('Click me')
|
116
|
+
@session.click_link('Has been clicked')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#click_button' do
|
121
|
+
it "should wait for asynchronous load" do
|
122
|
+
@session.visit('/with_js')
|
123
|
+
@session.click_link('Click me')
|
124
|
+
@session.click_button('New Here')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#fill_in' do
|
129
|
+
it "should wait for asynchronous load" do
|
130
|
+
@session.visit('/with_js')
|
131
|
+
@session.click_link('Click me')
|
132
|
+
@session.fill_in('new_field', :with => 'Testing...')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#check' do
|
137
|
+
it "should trigger associated events" do
|
138
|
+
@session.visit('/with_js')
|
139
|
+
@session.check('checkbox_with_event')
|
140
|
+
@session.should have_css('#checkbox_event_triggered');
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#has_xpath?' do
|
145
|
+
it "should wait for content to appear" do
|
146
|
+
@session.visit('/with_js')
|
147
|
+
@session.click_link('Click me')
|
148
|
+
@session.should have_xpath("//input[@type='submit' and @value='New Here']")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#has_no_xpath?' do
|
153
|
+
it "should wait for content to disappear" do
|
154
|
+
@session.visit('/with_js')
|
155
|
+
@session.click_link('Click me')
|
156
|
+
@session.should have_no_xpath("//p[@id='change']")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#has_css?' do
|
161
|
+
it "should wait for content to appear" do
|
162
|
+
@session.visit('/with_js')
|
163
|
+
@session.click_link('Click me')
|
164
|
+
@session.should have_css("input[type='submit'][value='New Here']")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#has_no_xpath?' do
|
169
|
+
it "should wait for content to disappear" do
|
170
|
+
@session.visit('/with_js')
|
171
|
+
@session.click_link('Click me')
|
172
|
+
@session.should have_no_css("p#change")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#has_content?' do
|
177
|
+
it "should wait for content to appear" do
|
178
|
+
@session.visit('/with_js')
|
179
|
+
@session.click_link('Click me')
|
180
|
+
@session.should have_content("Has been clicked")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#has_no_content?' do
|
185
|
+
it "should wait for content to disappear" do
|
186
|
+
@session.visit('/with_js')
|
187
|
+
@session.click_link('Click me')
|
188
|
+
@session.should have_no_content("I changed it")
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
shared_examples_for "session without javascript support" do
|
196
|
+
describe "#evaluate_script" do
|
197
|
+
before{ @session.visit('/with_simple_html') }
|
198
|
+
it "should raise an error" do
|
199
|
+
running {
|
200
|
+
@session.evaluate_script('3 + 3')
|
201
|
+
}.should raise_error(Capybara::NotSupportedByDriverError)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
shared_examples_for "locate" do
|
2
|
+
describe '#locate' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find the first element using the given locator" do
|
8
|
+
@session.locate('//h1').text.should == 'This is a test'
|
9
|
+
@session.locate("//input[@id='test_field']")[:value].should == 'monkey'
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with css selectors" do
|
13
|
+
it "should find the first element using the given locator" do
|
14
|
+
@session.locate(:css, 'h1').text.should == 'This is a test'
|
15
|
+
@session.locate(:css, "input[id='test_field']")[:value].should == 'monkey'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with xpath selectors" do
|
20
|
+
it "should find the first element using the given locator" do
|
21
|
+
@session.locate(:xpath, '//h1').text.should == 'This is a test'
|
22
|
+
@session.locate(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with css as default selector" do
|
27
|
+
before { Capybara.default_selector = :css }
|
28
|
+
it "should find the first element using the given locator" do
|
29
|
+
@session.locate('h1').text.should == 'This is a test'
|
30
|
+
@session.locate("input[id='test_field']")[:value].should == 'monkey'
|
31
|
+
end
|
32
|
+
after { Capybara.default_selector = :xpath }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise ElementNotFound with specified fail message if nothing was found" do
|
36
|
+
running do
|
37
|
+
@session.locate(:xpath, '//div[@id="nosuchthing"]', 'arghh').should be_nil
|
38
|
+
end.should raise_error(Capybara::ElementNotFound, "arghh")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should accept an XPath instance and respect the order of paths" do
|
42
|
+
@session.visit('/form')
|
43
|
+
@xpath = Capybara::XPath.text_field('Name')
|
44
|
+
@session.locate(@xpath).value.should == 'John Smith'
|
45
|
+
end
|
46
|
+
|
47
|
+
context "within a scope" do
|
48
|
+
before do
|
49
|
+
@session.visit('/with_scope')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should find the first element using the given locator" do
|
53
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
54
|
+
@session.locate('//li').text.should =~ /With Simple HTML/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
shared_examples_for "select" do
|
2
|
+
describe "#select" do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return value of the first option" do
|
8
|
+
@session.find_field('Title').value.should == 'Mrs'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return value of the selected option" do
|
12
|
+
@session.select("Miss", :from => 'Title')
|
13
|
+
@session.find_field('Title').value.should == 'Miss'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should select an option from a select box by id" do
|
17
|
+
@session.select("Finish", :from => 'form_locale')
|
18
|
+
@session.click_button('awesome')
|
19
|
+
extract_results(@session)['locale'].should == 'fi'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should select an option from a select box by label" do
|
23
|
+
@session.select("Finish", :from => 'Locale')
|
24
|
+
@session.click_button('awesome')
|
25
|
+
extract_results(@session)['locale'].should == 'fi'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should favour exact matches to option labels" do
|
29
|
+
@session.select("Mr", :from => 'Title')
|
30
|
+
@session.click_button('awesome')
|
31
|
+
extract_results(@session)['title'].should == 'Mr'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should escape quotes" do
|
35
|
+
@session.select("John's made-up language", :from => 'Locale')
|
36
|
+
@session.click_button('awesome')
|
37
|
+
extract_results(@session)['locale'].should == 'jo'
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with a locator that doesn't exist" do
|
41
|
+
it "should raise an error" do
|
42
|
+
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with an option that doesn't exist" do
|
47
|
+
it "should raise an error" do
|
48
|
+
running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with multiple select" do
|
53
|
+
it "should return an empty value" do
|
54
|
+
@session.find_field('Language').value.should == []
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return value of the selected options" do
|
58
|
+
@session.select("Ruby", :from => 'Language')
|
59
|
+
@session.select("Javascript", :from => 'Language')
|
60
|
+
@session.find_field('Language').value.should include('Ruby', 'Javascript')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should select one option" do
|
64
|
+
@session.select("Ruby", :from => 'Language')
|
65
|
+
@session.click_button('awesome')
|
66
|
+
extract_results(@session)['languages'].should == ['Ruby']
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should select multiple options" do
|
70
|
+
@session.select("Ruby", :from => 'Language')
|
71
|
+
@session.select("Javascript", :from => 'Language')
|
72
|
+
@session.click_button('awesome')
|
73
|
+
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
shared_examples_for "uncheck" do
|
2
|
+
describe "#uncheck" do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should uncheck a checkbox by id" do
|
8
|
+
@session.uncheck("form_pets_hamster")
|
9
|
+
@session.click_button('awesome')
|
10
|
+
extract_results(@session)['pets'].should include('dog')
|
11
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should uncheck a checkbox by label" do
|
15
|
+
@session.uncheck("Hamster")
|
16
|
+
@session.click_button('awesome')
|
17
|
+
extract_results(@session)['pets'].should include('dog')
|
18
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
shared_examples_for "unselect" do
|
2
|
+
describe "#unselect" do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
context "with multiple select" do
|
8
|
+
it "should unselect an option from a select box by id" do
|
9
|
+
@session.unselect('Commando', :from => 'form_underwear')
|
10
|
+
@session.click_button('awesome')
|
11
|
+
extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
|
12
|
+
extract_results(@session)['underwear'].should_not include('Commando')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should unselect an option from a select box by label" do
|
16
|
+
@session.unselect('Commando', :from => 'Underwear')
|
17
|
+
@session.click_button('awesome')
|
18
|
+
extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
|
19
|
+
extract_results(@session)['underwear'].should_not include('Commando')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should favour exact matches to option labels" do
|
23
|
+
@session.unselect("Briefs", :from => 'Underwear')
|
24
|
+
@session.click_button('awesome')
|
25
|
+
extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
|
26
|
+
extract_results(@session)['underwear'].should_not include('Briefs')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should escape quotes" do
|
30
|
+
@session.unselect("Frenchman's Pantalons", :from => 'Underwear')
|
31
|
+
@session.click_button('awesome')
|
32
|
+
extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with single select" do
|
37
|
+
it "should raise an error" do
|
38
|
+
running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with a locator that doesn't exist" do
|
43
|
+
it "should raise an error" do
|
44
|
+
running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with an option that doesn't exist" do
|
49
|
+
it "should raise an error" do
|
50
|
+
running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::OptionNotFound)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
shared_examples_for "within" do
|
2
|
+
describe '#within' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_scope')
|
5
|
+
end
|
6
|
+
|
7
|
+
context "with CSS selector" do
|
8
|
+
it "should click links in the given scope" do
|
9
|
+
@session.within(:css, "ul li[contains('With Simple HTML')]") do
|
10
|
+
@session.click_link('Go')
|
11
|
+
end
|
12
|
+
@session.body.should include('Bar')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with XPath selector" do
|
17
|
+
it "should click links in the given scope" do
|
18
|
+
@session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
|
19
|
+
@session.click_link('Go')
|
20
|
+
end
|
21
|
+
@session.body.should include('Bar')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with the default selector" do
|
26
|
+
it "should use XPath" do
|
27
|
+
@session.within("//li[contains(., 'With Simple HTML')]") do
|
28
|
+
@session.click_link('Go')
|
29
|
+
end
|
30
|
+
@session.body.should include('Bar')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with the default selector set to CSS" do
|
35
|
+
before { Capybara.default_selector = :css }
|
36
|
+
it "should use CSS" do
|
37
|
+
@session.within("ul li[contains('With Simple HTML')]") do
|
38
|
+
@session.click_link('Go')
|
39
|
+
end
|
40
|
+
@session.body.should include('Bar')
|
41
|
+
end
|
42
|
+
after { Capybara.default_selector = :xpath }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with click_link" do
|
46
|
+
it "should click links in the given scope" do
|
47
|
+
@session.within("//li[contains(.,'With Simple HTML')]") do
|
48
|
+
@session.click_link('Go')
|
49
|
+
end
|
50
|
+
@session.body.should include('Bar')
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with nested scopes" do
|
54
|
+
it "should respect the inner scope" do
|
55
|
+
@session.within("//div[@id='for_bar']") do
|
56
|
+
@session.within("//li[contains(.,'Bar')]") do
|
57
|
+
@session.click_link('Go')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@session.body.should include('Another World')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should respect the outer scope" do
|
64
|
+
@session.within("//div[@id='another_foo']") do
|
65
|
+
@session.within("//li[contains(.,'With Simple HTML')]") do
|
66
|
+
@session.click_link('Go')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@session.body.should include('Hello world')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise an error if the scope is not found on the page" do
|
74
|
+
running {
|
75
|
+
@session.within("//div[@id='doesnotexist']") do
|
76
|
+
end
|
77
|
+
}.should raise_error(Capybara::ElementNotFound)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should restore the scope when an error is raised" do
|
81
|
+
running {
|
82
|
+
@session.within("//div[@id='for_bar']") do
|
83
|
+
running {
|
84
|
+
running {
|
85
|
+
@session.within("//div[@id='doesnotexist']") do
|
86
|
+
end
|
87
|
+
}.should raise_error(Capybara::ElementNotFound)
|
88
|
+
}.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(false)
|
89
|
+
end
|
90
|
+
}.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(true)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with forms" do
|
95
|
+
it "should fill in a field and click a button" do
|
96
|
+
@session.within("//li[contains(.,'Bar')]") do
|
97
|
+
@session.click_button('Go')
|
98
|
+
end
|
99
|
+
extract_results(@session)['first_name'].should == 'Peter'
|
100
|
+
@session.visit('/with_scope')
|
101
|
+
@session.within("//li[contains(.,'Bar')]") do
|
102
|
+
@session.fill_in('First Name', :with => 'Dagobert')
|
103
|
+
@session.click_button('Go')
|
104
|
+
end
|
105
|
+
extract_results(@session)['first_name'].should == 'Dagobert'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#within_fieldset' do
|
111
|
+
before do
|
112
|
+
@session.visit('/fieldsets')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should restrict scope to a fieldset given by id" do
|
116
|
+
@session.within_fieldset("villain_fieldset") do
|
117
|
+
@session.fill_in("Name", :with => 'Goldfinger')
|
118
|
+
@session.click_button("Create")
|
119
|
+
end
|
120
|
+
extract_results(@session)['villain_name'].should == 'Goldfinger'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should restrict scope to a fieldset given by legend" do
|
124
|
+
@session.within_fieldset("Villain") do
|
125
|
+
@session.fill_in("Name", :with => 'Goldfinger')
|
126
|
+
@session.click_button("Create")
|
127
|
+
end
|
128
|
+
extract_results(@session)['villain_name'].should == 'Goldfinger'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '#within_table' do
|
133
|
+
before do
|
134
|
+
@session.visit('/tables')
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should restrict scope to a fieldset given by id" do
|
138
|
+
@session.within_table("girl_table") do
|
139
|
+
@session.fill_in("Name", :with => 'Christmas')
|
140
|
+
@session.click_button("Create")
|
141
|
+
end
|
142
|
+
extract_results(@session)['girl_name'].should == 'Christmas'
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should restrict scope to a fieldset given by legend" do
|
146
|
+
@session.within_table("Villain") do
|
147
|
+
@session.fill_in("Name", :with => 'Quantum')
|
148
|
+
@session.click_button("Create")
|
149
|
+
end
|
150
|
+
extract_results(@session)['villain_name'].should == 'Quantum'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|