capybara 2.0.3 → 2.1.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.md +82 -0
- data/README.md +57 -52
- data/lib/capybara/cucumber.rb +4 -1
- data/lib/capybara/driver/base.rb +13 -9
- data/lib/capybara/driver/node.rb +18 -6
- data/lib/capybara/helpers.rb +111 -22
- data/lib/capybara/node/actions.rb +30 -25
- data/lib/capybara/node/base.rb +25 -32
- data/lib/capybara/node/document.rb +6 -2
- data/lib/capybara/node/element.rb +44 -7
- data/lib/capybara/node/finders.rb +49 -22
- data/lib/capybara/node/matchers.rb +38 -21
- data/lib/capybara/node/simple.rb +31 -9
- data/lib/capybara/query.rb +72 -26
- data/lib/capybara/rack_test/browser.rb +11 -3
- data/lib/capybara/rack_test/css_handlers.rb +8 -0
- data/lib/capybara/rack_test/driver.rb +11 -3
- data/lib/capybara/rack_test/form.rb +8 -1
- data/lib/capybara/rack_test/node.rb +91 -35
- data/lib/capybara/rails.rb +0 -1
- data/lib/capybara/result.rb +21 -37
- data/lib/capybara/rspec/matchers.rb +60 -31
- data/lib/capybara/selector.rb +46 -13
- data/lib/capybara/selenium/driver.rb +42 -7
- data/lib/capybara/selenium/node.rb +23 -5
- data/lib/capybara/server.rb +1 -1
- data/lib/capybara/session.rb +47 -12
- data/lib/capybara/spec/public/test.js +12 -0
- data/lib/capybara/spec/session/all_spec.rb +9 -8
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -0
- data/lib/capybara/spec/session/check_spec.rb +14 -0
- data/lib/capybara/spec/session/choose_spec.rb +14 -0
- data/lib/capybara/spec/session/click_button_spec.rb +77 -1
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +65 -0
- data/lib/capybara/spec/session/click_link_spec.rb +24 -0
- data/lib/capybara/spec/session/current_scope_spec.rb +29 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +26 -0
- data/lib/capybara/spec/session/find_button_spec.rb +12 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +12 -1
- data/lib/capybara/spec/session/find_field_spec.rb +30 -0
- data/lib/capybara/spec/session/find_link_spec.rb +12 -0
- data/lib/capybara/spec/session/find_spec.rb +264 -16
- data/lib/capybara/spec/session/first_spec.rb +25 -8
- data/lib/capybara/spec/session/has_css_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +10 -2
- data/lib/capybara/spec/session/has_selector_spec.rb +9 -0
- data/lib/capybara/spec/session/has_text_spec.rb +96 -0
- data/lib/capybara/spec/session/has_title_spec.rb +47 -0
- data/lib/capybara/spec/session/node_spec.rb +48 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +10 -2
- data/lib/capybara/spec/session/save_page_spec.rb +30 -0
- data/lib/capybara/spec/session/select_spec.rb +65 -0
- data/lib/capybara/spec/session/text_spec.rb +31 -0
- data/lib/capybara/spec/session/title_spec.rb +16 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +14 -0
- data/lib/capybara/spec/session/unselect_spec.rb +42 -0
- data/lib/capybara/spec/session/visit_spec.rb +3 -3
- data/lib/capybara/spec/session/within_frame_spec.rb +14 -0
- data/lib/capybara/spec/session/within_spec.rb +3 -3
- data/lib/capybara/spec/spec_helper.rb +7 -2
- data/lib/capybara/spec/views/form.erb +39 -2
- data/lib/capybara/spec/views/frame_child.erb +9 -0
- data/lib/capybara/spec/views/frame_parent.erb +8 -0
- data/lib/capybara/spec/views/with_base_tag.erb +10 -0
- data/lib/capybara/spec/views/with_count.erb +7 -0
- data/lib/capybara/spec/views/with_hover.erb +17 -0
- data/lib/capybara/spec/views/with_html.erb +23 -2
- data/lib/capybara/spec/views/with_js.erb +5 -0
- data/lib/capybara/spec/views/with_scope.erb +6 -1
- data/lib/capybara/spec/views/with_title.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +43 -62
- data/spec/basic_node_spec.rb +75 -24
- data/spec/dsl_spec.rb +2 -1
- data/spec/rack_test_spec.rb +4 -3
- data/spec/rspec/matchers_spec.rb +105 -17
- data/spec/server_spec.rb +15 -8
- data/spec/spec_helper.rb +2 -1
- data.tar.gz.sig +0 -0
- metadata +82 -22
- metadata.gz.sig +0 -0
|
@@ -70,7 +70,7 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
|
70
70
|
|
|
71
71
|
it "should be false when content occurs more times than given" do
|
|
72
72
|
@session.should_not have_css("h2.head", :maximum => 4) # edge case
|
|
73
|
-
@session.should_not have_css("h2", :maximum =>
|
|
73
|
+
@session.should_not have_css("h2", :maximum => 3)
|
|
74
74
|
@session.should_not have_css("p", :maximum => 1)
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -184,7 +184,7 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|
|
184
184
|
|
|
185
185
|
it "should be true when content occurs more times than given" do
|
|
186
186
|
@session.should have_no_css("h2.head", :maximum => 4) # edge case
|
|
187
|
-
@session.should have_no_css("h2", :maximum =>
|
|
187
|
+
@session.should have_no_css("h2", :maximum => 3)
|
|
188
188
|
@session.should have_no_css("p", :maximum => 1)
|
|
189
189
|
end
|
|
190
190
|
|
|
@@ -42,12 +42,16 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
|
42
42
|
@session.should have_field('First Name', :type => 'text')
|
|
43
43
|
@session.should have_field('Html5 Email', :type => 'email')
|
|
44
44
|
@session.should have_field('Html5 Tel', :type => 'tel')
|
|
45
|
+
@session.should have_field('Description', :type => 'textarea')
|
|
46
|
+
@session.should have_field('Languages', :type => 'select')
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
it "should be false if the given field is not on the page" do
|
|
48
|
-
@session.should_not have_field('First Name', :type => '
|
|
50
|
+
@session.should_not have_field('First Name', :type => 'textarea')
|
|
49
51
|
@session.should_not have_field('Html5 Email', :type => 'tel')
|
|
50
52
|
@session.should_not have_field('Description', :type => '')
|
|
53
|
+
@session.should_not have_field('Description', :type => 'email')
|
|
54
|
+
@session.should_not have_field('Languages', :type => 'textarea')
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
end
|
|
@@ -95,12 +99,16 @@ Capybara::SpecHelper.spec '#has_no_field' do
|
|
|
95
99
|
@session.should_not have_no_field('First Name', :type => 'text')
|
|
96
100
|
@session.should_not have_no_field('Html5 Email', :type => 'email')
|
|
97
101
|
@session.should_not have_no_field('Html5 Tel', :type => 'tel')
|
|
102
|
+
@session.should_not have_no_field('Description', :type => 'textarea')
|
|
103
|
+
@session.should_not have_no_field('Languages', :type => 'select')
|
|
98
104
|
end
|
|
99
105
|
|
|
100
106
|
it "should be true if the given field is not on the page" do
|
|
101
|
-
@session.should have_no_field('First Name', :type => '
|
|
107
|
+
@session.should have_no_field('First Name', :type => 'textarea')
|
|
102
108
|
@session.should have_no_field('Html5 Email', :type => 'tel')
|
|
103
109
|
@session.should have_no_field('Description', :type => '')
|
|
110
|
+
@session.should have_no_field('Description', :type => 'email')
|
|
111
|
+
@session.should have_no_field('Languages', :type => 'textarea')
|
|
104
112
|
end
|
|
105
113
|
end
|
|
106
114
|
end
|
|
@@ -53,6 +53,15 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|
|
53
53
|
@session.should_not have_selector("//p", :text => "Doesnotexist")
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
it "should respect visibility setting" do
|
|
57
|
+
@session.should have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
|
|
58
|
+
@session.should_not have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
|
|
59
|
+
Capybara.ignore_hidden_elements = false
|
|
60
|
+
@session.should have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
|
|
61
|
+
Capybara.visible_text_only = true
|
|
62
|
+
@session.should_not have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
|
|
63
|
+
end
|
|
64
|
+
|
|
56
65
|
it "should discard all matches where the given regexp is not matched" do
|
|
57
66
|
@session.should have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
|
|
58
67
|
@session.should_not have_selector("//p//a", :text => /Red$/)
|
|
@@ -74,6 +74,17 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
|
74
74
|
@session.should_not have_text('Inside element with hidden ancestor')
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
it "should be true if :all given and text is invisible." do
|
|
78
|
+
@session.visit('/with_html')
|
|
79
|
+
@session.should have_text(:all, 'Some of this text is hidden!')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should be true if `Capybara.ignore_hidden_elements = true` and text is invisible." do
|
|
83
|
+
Capybara.ignore_hidden_elements = false
|
|
84
|
+
@session.visit('/with_html')
|
|
85
|
+
@session.should have_text('Some of this text is hidden!')
|
|
86
|
+
end
|
|
87
|
+
|
|
77
88
|
it "should be true if the text in the page matches given regexp" do
|
|
78
89
|
@session.visit('/with_html')
|
|
79
90
|
@session.should have_text(/Lorem/)
|
|
@@ -105,6 +116,80 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
|
105
116
|
@session.click_link('Click me')
|
|
106
117
|
@session.should have_text("Has been clicked")
|
|
107
118
|
end
|
|
119
|
+
|
|
120
|
+
context "with between" do
|
|
121
|
+
it "should be true if the text occurs within the range given" do
|
|
122
|
+
@session.visit('/with_count')
|
|
123
|
+
@session.should have_text('count', between: 1..3)
|
|
124
|
+
@session.should have_text(/count/, between: 2..2)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should be false if the text occurs more or fewer times than range" do
|
|
128
|
+
@session.visit('/with_count')
|
|
129
|
+
@session.should_not have_text('count', between: 0..1)
|
|
130
|
+
@session.should_not have_text('count', between: 3..10)
|
|
131
|
+
@session.should_not have_text(/count/, between: 2...2)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context "with count" do
|
|
136
|
+
it "should be true if the text occurs the given number of times" do
|
|
137
|
+
@session.visit('/with_count')
|
|
138
|
+
@session.should have_text('count', count: 2)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "should be false if the text occurs a different number of times than the given" do
|
|
142
|
+
@session.visit('/with_count')
|
|
143
|
+
@session.should_not have_text('count', count: 0)
|
|
144
|
+
@session.should_not have_text('count', count: 1)
|
|
145
|
+
@session.should_not have_text(/count/, count: 3)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should coerce count to an integer" do
|
|
149
|
+
@session.visit('/with_count')
|
|
150
|
+
@session.should have_text('count', count: '2')
|
|
151
|
+
@session.should_not have_text('count', count: '3')
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context "with maximum" do
|
|
156
|
+
it "should be true when text occurs same or fewer times than given" do
|
|
157
|
+
@session.visit('/with_count')
|
|
158
|
+
@session.should have_text('count', maximum: 2)
|
|
159
|
+
@session.should have_text(/count/, maximum: 3)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should be false when text occurs more times than given" do
|
|
163
|
+
@session.visit('/with_count')
|
|
164
|
+
@session.should_not have_text('count', maximum: 1)
|
|
165
|
+
@session.should_not have_text('count', maximum: 0)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "should coerce maximum to an integer" do
|
|
169
|
+
@session.visit('/with_count')
|
|
170
|
+
@session.should have_text('count', maximum: '2')
|
|
171
|
+
@session.should_not have_text('count', maximum: '1')
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
context "with minimum" do
|
|
176
|
+
it "should be true when text occurs same or more times than given" do
|
|
177
|
+
@session.visit('/with_count')
|
|
178
|
+
@session.should have_text('count', minimum: 2)
|
|
179
|
+
@session.should have_text(/count/, minimum: 0)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "should be false when text occurs fewer times than given" do
|
|
183
|
+
@session.visit('/with_count')
|
|
184
|
+
@session.should_not have_text('count', minimum: 3)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should coerce minimum to an integer" do
|
|
188
|
+
@session.visit('/with_count')
|
|
189
|
+
@session.should have_text('count', minimum: '2')
|
|
190
|
+
@session.should_not have_text('count', minimum: '3')
|
|
191
|
+
end
|
|
192
|
+
end
|
|
108
193
|
end
|
|
109
194
|
|
|
110
195
|
Capybara::SpecHelper.spec '#has_no_text?' do
|
|
@@ -172,6 +257,17 @@ Capybara::SpecHelper.spec '#has_no_text?' do
|
|
|
172
257
|
@session.should have_no_text('Inside element with hidden ancestor')
|
|
173
258
|
end
|
|
174
259
|
|
|
260
|
+
it "should be false if :all given and text is invisible." do
|
|
261
|
+
@session.visit('/with_html')
|
|
262
|
+
@session.should_not have_no_text(:all, 'Some of this text is hidden!')
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "should be false if `Capybara.ignore_hidden_elements = true` and text is invisible." do
|
|
266
|
+
Capybara.ignore_hidden_elements = false
|
|
267
|
+
@session.visit('/with_html')
|
|
268
|
+
@session.should_not have_no_text('Some of this text is hidden!')
|
|
269
|
+
end
|
|
270
|
+
|
|
175
271
|
it "should be true if the text in the page doesn't match given regexp" do
|
|
176
272
|
@session.visit('/with_html')
|
|
177
273
|
@session.should have_no_text(/xxxxyzzz/)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#has_title?' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_js')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should be true if the page has the given title" do
|
|
7
|
+
@session.should have_title('with_js')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should allow regexp matches" do
|
|
11
|
+
@session.should have_title(/w[a-z]{3}_js/)
|
|
12
|
+
@session.should_not have_title(/monkey/)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should wait for title", :requires => [:js] do
|
|
16
|
+
@session.click_link("Change title")
|
|
17
|
+
@session.should have_title("changed title")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should be false if the page has not the given title" do
|
|
21
|
+
@session.should_not have_title('monkey')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Capybara::SpecHelper.spec '#has_no_title?' do
|
|
26
|
+
before do
|
|
27
|
+
@session.visit('/with_js')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should be false if the page has the given title" do
|
|
31
|
+
@session.should_not have_no_title('with_js')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should allow regexp matches" do
|
|
35
|
+
@session.should_not have_no_title(/w[a-z]{3}_js/)
|
|
36
|
+
@session.should have_no_title(/monkey/)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should wait for title to disappear", :requires => [:js] do
|
|
40
|
+
@session.click_link("Change title")
|
|
41
|
+
@session.should have_no_title('with_js')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should be true if the page has not the given title" do
|
|
45
|
+
@session.should have_no_title('monkey')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -57,6 +57,11 @@ Capybara::SpecHelper.spec "node" do
|
|
|
57
57
|
it "should not swallow extra newlines in textarea" do
|
|
58
58
|
@session.find('//textarea[@id="additional_newline"]').value.should == "\nbanana"
|
|
59
59
|
end
|
|
60
|
+
|
|
61
|
+
it "return any HTML content in textarea" do
|
|
62
|
+
@session.find('//textarea[1]').set("some <em>html</em> here")
|
|
63
|
+
@session.find('//textarea[1]').value.should == "some <em>html</em> here"
|
|
64
|
+
end
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
describe "#set" do
|
|
@@ -71,6 +76,18 @@ Capybara::SpecHelper.spec "node" do
|
|
|
71
76
|
@session.first('//input').set('')
|
|
72
77
|
@session.first('//input').value.should == ''
|
|
73
78
|
end
|
|
79
|
+
|
|
80
|
+
it "should not set if the text field is readonly" do
|
|
81
|
+
@session.first('//input[@readonly]').value.should == 'should not change'
|
|
82
|
+
@session.first('//input[@readonly]').set('changed')
|
|
83
|
+
@session.first('//input[@readonly]').value.should == 'should not change'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should not set if the textarea is readonly" do
|
|
87
|
+
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
|
|
88
|
+
@session.first('//textarea[@readonly]').set('changed')
|
|
89
|
+
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
|
|
90
|
+
end
|
|
74
91
|
end
|
|
75
92
|
|
|
76
93
|
describe "#tag_name" do
|
|
@@ -81,8 +98,29 @@ Capybara::SpecHelper.spec "node" do
|
|
|
81
98
|
end
|
|
82
99
|
end
|
|
83
100
|
|
|
101
|
+
describe "#disabled?" do
|
|
102
|
+
it "should extract disabled node" do
|
|
103
|
+
@session.visit('/form')
|
|
104
|
+
@session.find('//input[@id="customer_name"]').should be_disabled
|
|
105
|
+
@session.find('//input[@id="customer_email"]').should_not be_disabled
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should see disabled options as disabled" do
|
|
109
|
+
@session.visit('/form')
|
|
110
|
+
@session.find('//select[@id="form_title"]/option[1]').should_not be_disabled
|
|
111
|
+
@session.find('//select[@id="form_title"]/option[@disabled]').should be_disabled
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should see enabled options in disabled select as disabled" do
|
|
115
|
+
@session.visit('/form')
|
|
116
|
+
@session.find('//select[@id="form_disabled_select"]/option').should be_disabled
|
|
117
|
+
@session.find('//select[@id="form_title"]/option[1]').should_not be_disabled
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
84
121
|
describe "#visible?" do
|
|
85
122
|
it "should extract node visibility" do
|
|
123
|
+
Capybara.ignore_hidden_elements = false
|
|
86
124
|
@session.first('//a').should be_visible
|
|
87
125
|
|
|
88
126
|
@session.find('//div[@id="hidden"]').should_not be_visible
|
|
@@ -138,6 +176,16 @@ Capybara::SpecHelper.spec "node" do
|
|
|
138
176
|
end
|
|
139
177
|
end
|
|
140
178
|
|
|
179
|
+
describe '#hover', :requires => [:hover] do
|
|
180
|
+
it "should allow hovering on an element" do
|
|
181
|
+
pending "Selenium with firefox doesn't currently work with this (selenium with chrome does)" if @session.respond_to?(:mode) && @session.mode == :selenium && @session.driver.browser.browser == :firefox
|
|
182
|
+
@session.visit('/with_hover')
|
|
183
|
+
@session.find(:css,'.hidden_until_hover', :visible => false).should_not be_visible
|
|
184
|
+
@session.find(:css,'.wrapper').hover
|
|
185
|
+
@session.find(:css, '.hidden_until_hover', :visible => false).should be_visible
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
141
189
|
describe '#reload', :requires => [:js] do
|
|
142
190
|
context "without automatic reload" do
|
|
143
191
|
before { Capybara.automatic_reload = false }
|
|
@@ -31,12 +31,20 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
|
31
31
|
@session.should have_no_selector('.//h1')
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
it "raises any errors caught inside the server" do
|
|
34
|
+
it "raises any errors caught inside the server", :requires => [:server] do
|
|
35
|
+
quietly { @session.visit("/error") }
|
|
35
36
|
expect do
|
|
36
|
-
quietly { @session.visit("/error") }
|
|
37
37
|
@session.reset_session!
|
|
38
38
|
end.to raise_error(TestApp::TestAppError)
|
|
39
39
|
@session.visit("/")
|
|
40
40
|
@session.current_path.should == "/"
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
it "ignores server errors when `Capybara.raise_server_errors = false`", :requires => [:server] do
|
|
44
|
+
Capybara.raise_server_errors = false
|
|
45
|
+
quietly { @session.visit("/error") }
|
|
46
|
+
@session.reset_session!
|
|
47
|
+
@session.visit("/")
|
|
48
|
+
@session.current_path.should == "/"
|
|
49
|
+
end
|
|
42
50
|
end
|
|
@@ -43,4 +43,34 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
|
43
43
|
filename = path.split("/").last
|
|
44
44
|
result.should == filename
|
|
45
45
|
end
|
|
46
|
+
|
|
47
|
+
context "asset_host contains a string" do
|
|
48
|
+
before { Capybara.asset_host = "http://example.com" }
|
|
49
|
+
after { Capybara.asset_host = nil }
|
|
50
|
+
|
|
51
|
+
it "prepends base tag with value from asset_host to the head" do
|
|
52
|
+
@session.visit("/with_js")
|
|
53
|
+
path = @session.save_page
|
|
54
|
+
|
|
55
|
+
result = File.read(path)
|
|
56
|
+
result.should include("<head><base href='http://example.com' />")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "doesn't prepend base tag to pages when asset_host is nil" do
|
|
60
|
+
Capybara.asset_host = nil
|
|
61
|
+
@session.visit("/with_js")
|
|
62
|
+
path = @session.save_page
|
|
63
|
+
|
|
64
|
+
result = File.read(path)
|
|
65
|
+
result.should_not include("http://example.com")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "doesn't prepend base tag to pages which already have it" do
|
|
69
|
+
@session.visit("/with_base_tag")
|
|
70
|
+
path = @session.save_page
|
|
71
|
+
|
|
72
|
+
result = File.read(path)
|
|
73
|
+
result.should_not include("http://example.com")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
46
76
|
end
|
|
@@ -12,6 +12,29 @@ Capybara::SpecHelper.spec "#select" do
|
|
|
12
12
|
@session.find_field('Title').value.should == 'Miss'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
it "should allow selecting options where there are inexact matches" do
|
|
16
|
+
@session.select("Mr", :from => 'Title')
|
|
17
|
+
@session.find_field('Title').value.should == 'Mr'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should allow selecting options where they are the only inexact match" do
|
|
21
|
+
@session.select("Mis", :from => 'Title')
|
|
22
|
+
@session.find_field('Title').value.should == 'Miss'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should not allow selecting options where they are the only inexact match if `Capybara.exact_options = true`" do
|
|
26
|
+
Capybara.exact_options = true
|
|
27
|
+
expect do
|
|
28
|
+
@session.select("Mis", :from => 'Title')
|
|
29
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should not allow selecting an option if the match is ambiguous" do
|
|
33
|
+
expect do
|
|
34
|
+
@session.select("M", :from => 'Title')
|
|
35
|
+
end.to raise_error(Capybara::Ambiguous)
|
|
36
|
+
end
|
|
37
|
+
|
|
15
38
|
it "should return the value attribute rather than content if present" do
|
|
16
39
|
@session.find_field('Locale').value.should == 'en'
|
|
17
40
|
end
|
|
@@ -121,4 +144,46 @@ Capybara::SpecHelper.spec "#select" do
|
|
|
121
144
|
@session.find_field('Underwear').value.should include('thermal')
|
|
122
145
|
end
|
|
123
146
|
end
|
|
147
|
+
|
|
148
|
+
context "with :exact option" do
|
|
149
|
+
context "when `false`" do
|
|
150
|
+
it "can match select box approximately" do
|
|
151
|
+
@session.select("Finish", :from => "Loc", :exact => false)
|
|
152
|
+
@session.click_button("awesome")
|
|
153
|
+
extract_results(@session)["locale"].should == "fi"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "can match option approximately" do
|
|
157
|
+
@session.select("Fin", :from => "Locale", :exact => false)
|
|
158
|
+
@session.click_button("awesome")
|
|
159
|
+
extract_results(@session)["locale"].should == "fi"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "can match option approximately when :from not given" do
|
|
163
|
+
@session.select("made-up language", :exact => false)
|
|
164
|
+
@session.click_button("awesome")
|
|
165
|
+
extract_results(@session)["locale"].should == "jo"
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
context "when `true`" do
|
|
170
|
+
it "can match select box approximately" do
|
|
171
|
+
expect do
|
|
172
|
+
@session.select("Finish", :from => "Loc", :exact => true)
|
|
173
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "can match option approximately" do
|
|
177
|
+
expect do
|
|
178
|
+
@session.select("Fin", :from => "Locale", :exact => true)
|
|
179
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "can match option approximately when :from not given" do
|
|
183
|
+
expect do
|
|
184
|
+
@session.select("made-up language", :exact => true)
|
|
185
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
124
189
|
end
|
|
@@ -4,6 +4,37 @@ Capybara::SpecHelper.spec '#text' do
|
|
|
4
4
|
@session.text.should == 'Bar'
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
+
it "ignores invisible text by default" do
|
|
8
|
+
@session.visit('/with_html')
|
|
9
|
+
@session.find(:id, "hidden-text").text.should == 'Some of this text is'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "shows invisible text if `:all` given" do
|
|
13
|
+
@session.visit('/with_html')
|
|
14
|
+
@session.find(:id, "hidden-text").text(:all).should == 'Some of this text is hidden!'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "ignores invisible text if `:visible` given" do
|
|
18
|
+
Capybara.ignore_hidden_elements = false
|
|
19
|
+
@session.visit('/with_html')
|
|
20
|
+
@session.find(:id, "hidden-text").text(:visible).should == 'Some of this text is'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "ignores invisible text if `Capybara.ignore_hidden_elements = true`" do
|
|
24
|
+
@session.visit('/with_html')
|
|
25
|
+
@session.find(:id, "hidden-text").text.should == 'Some of this text is'
|
|
26
|
+
Capybara.ignore_hidden_elements = false
|
|
27
|
+
@session.find(:id, "hidden-text").text.should == 'Some of this text is hidden!'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "ignores invisible text if `Capybara.visible_text_only = true`" do
|
|
31
|
+
@session.visit('/with_html')
|
|
32
|
+
Capybara.visible_text_only = true
|
|
33
|
+
@session.find(:id, "hidden-text").text.should == 'Some of this text is'
|
|
34
|
+
Capybara.ignore_hidden_elements = false
|
|
35
|
+
@session.find(:id, "hidden-text").text.should == 'Some of this text is'
|
|
36
|
+
end
|
|
37
|
+
|
|
7
38
|
context "with css as default selector" do
|
|
8
39
|
before { Capybara.default_selector = :css }
|
|
9
40
|
it "should print the text of the page" do
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#title' do
|
|
2
|
+
|
|
3
|
+
it "should print the title of the page" do
|
|
4
|
+
@session.visit('/with_title')
|
|
5
|
+
@session.title.should == 'Test Title'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "with css as default selector" do
|
|
9
|
+
before { Capybara.default_selector = :css }
|
|
10
|
+
it "should print the title of the page" do
|
|
11
|
+
@session.visit('/with_title')
|
|
12
|
+
@session.title.should == 'Test Title'
|
|
13
|
+
end
|
|
14
|
+
after { Capybara.default_selector = :xpath }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -23,4 +23,18 @@ Capybara::SpecHelper.spec "#uncheck" do
|
|
|
23
23
|
extract_results(@session)['pets'].should include('dog')
|
|
24
24
|
extract_results(@session)['pets'].should_not include('hamster')
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
context "with :exact option" do
|
|
28
|
+
it "should accept partial matches when false" do
|
|
29
|
+
@session.uncheck('Ham', :exact => false)
|
|
30
|
+
@session.click_button('awesome')
|
|
31
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should not accept partial matches when true" do
|
|
35
|
+
expect do
|
|
36
|
+
@session.uncheck('Ham', :exact => true)
|
|
37
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
26
40
|
end
|
|
@@ -69,4 +69,46 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
|
69
69
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
context "with :exact option" do
|
|
74
|
+
context "when `false`" do
|
|
75
|
+
it "can match select box approximately" do
|
|
76
|
+
@session.unselect("Boxerbriefs", :from => "Under", :exact => false)
|
|
77
|
+
@session.click_button("awesome")
|
|
78
|
+
extract_results(@session)["underwear"].should_not include("Boxerbriefs")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "can match option approximately" do
|
|
82
|
+
@session.unselect("Boxerbr", :from => "Underwear", :exact => false)
|
|
83
|
+
@session.click_button("awesome")
|
|
84
|
+
extract_results(@session)["underwear"].should_not include("Boxerbriefs")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "can match option approximately when :from not given" do
|
|
88
|
+
@session.unselect("Boxerbr", :exact => false)
|
|
89
|
+
@session.click_button("awesome")
|
|
90
|
+
extract_results(@session)["underwear"].should_not include("Boxerbriefs")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "when `true`" do
|
|
95
|
+
it "can match select box approximately" do
|
|
96
|
+
expect do
|
|
97
|
+
@session.unselect("Boxerbriefs", :from => "Under", :exact => true)
|
|
98
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "can match option approximately" do
|
|
102
|
+
expect do
|
|
103
|
+
@session.unselect("Boxerbr", :from => "Underwear", :exact => true)
|
|
104
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "can match option approximately when :from not given" do
|
|
108
|
+
expect do
|
|
109
|
+
@session.unselect("Boxerbr", :exact => true)
|
|
110
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
72
114
|
end
|
|
@@ -72,18 +72,18 @@ Capybara::SpecHelper.spec '#visit' do
|
|
|
72
72
|
it "should send a referer when following a link" do
|
|
73
73
|
@session.visit '/referer_base'
|
|
74
74
|
@session.find('//a[@href="/get_referer"]').click
|
|
75
|
-
@session.
|
|
75
|
+
@session.should have_content %r{http://.*/referer_base}
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "should preserve the original referer URL when following a redirect" do
|
|
79
79
|
@session.visit('/referer_base')
|
|
80
80
|
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
|
81
|
-
@session.
|
|
81
|
+
@session.should have_content %r{http://.*/referer_base}
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it "should send a referer when submitting a form" do
|
|
85
85
|
@session.visit '/referer_base'
|
|
86
86
|
@session.find('//input').click
|
|
87
|
-
@session.
|
|
87
|
+
@session.should have_content %r{http://.*/referer_base}
|
|
88
88
|
end
|
|
89
89
|
end
|
|
@@ -28,4 +28,18 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|
|
28
28
|
it "should return the result of executing the block" do
|
|
29
29
|
@session.within_frame("frameOne") { "return value" }.should eql "return value"
|
|
30
30
|
end
|
|
31
|
+
it "should find the div given Element" do
|
|
32
|
+
element = @session.find(:id, 'frameOne')
|
|
33
|
+
@session.within_frame element do
|
|
34
|
+
@session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
it "should find multiple nested frames" do
|
|
38
|
+
@session.within_frame 'parentFrame' do
|
|
39
|
+
@session.within_frame 'childFrame' do
|
|
40
|
+
@session.within_frame 'grandchildFrame1' do end
|
|
41
|
+
@session.within_frame 'grandchildFrame2' do end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
31
45
|
end
|
|
@@ -5,7 +5,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
|
5
5
|
|
|
6
6
|
context "with CSS selector" do
|
|
7
7
|
it "should click links in the given scope" do
|
|
8
|
-
@session.within(:css, "#for_bar li
|
|
8
|
+
@session.within(:css, "#for_bar li", text: 'With Simple HTML') do
|
|
9
9
|
@session.click_link('Go')
|
|
10
10
|
end
|
|
11
11
|
@session.should have_content('Bar')
|
|
@@ -46,7 +46,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
|
46
46
|
|
|
47
47
|
context "with Node rather than selector" do
|
|
48
48
|
it "should click links in the given scope" do
|
|
49
|
-
node_of_interest = @session.find(:css, "#for_bar li
|
|
49
|
+
node_of_interest = @session.find(:css, "#for_bar li", text: 'With Simple HTML')
|
|
50
50
|
|
|
51
51
|
@session.within(node_of_interest) do
|
|
52
52
|
@session.click_link('Go')
|
|
@@ -58,7 +58,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
|
58
58
|
context "with the default selector set to CSS" do
|
|
59
59
|
before { Capybara.default_selector = :css }
|
|
60
60
|
it "should use CSS" do
|
|
61
|
-
@session.within("#for_bar li
|
|
61
|
+
@session.within("#for_bar li", text: 'With Simple HTML') do
|
|
62
62
|
@session.click_link('Go')
|
|
63
63
|
end
|
|
64
64
|
@session.should have_content('Bar')
|