capybara 2.9.0 → 2.10.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.
- checksums.yaml +4 -4
- data/History.md +23 -0
- data/README.md +37 -30
- data/lib/capybara/node/actions.rb +18 -15
- data/lib/capybara/node/base.rb +2 -2
- data/lib/capybara/node/element.rb +1 -1
- data/lib/capybara/node/finders.rb +37 -32
- data/lib/capybara/node/matchers.rb +187 -171
- data/lib/capybara/queries/match_query.rb +1 -3
- data/lib/capybara/queries/selector_query.rb +48 -19
- data/lib/capybara/rack_test/driver.rb +3 -3
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/rspec/features.rb +1 -1
- data/lib/capybara/rspec/matchers.rb +31 -22
- data/lib/capybara/selector/css.rb +30 -0
- data/lib/capybara/selector/selector.rb +24 -1
- data/lib/capybara/selector.rb +22 -23
- data/lib/capybara/session.rb +4 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +4 -4
- data/lib/capybara/spec/session/accept_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/accept_prompt_spec.rb +5 -5
- data/lib/capybara/spec/session/all_spec.rb +27 -27
- data/lib/capybara/spec/session/assert_current_path.rb +2 -2
- data/lib/capybara/spec/session/assert_selector.rb +28 -28
- data/lib/capybara/spec/session/assert_text.rb +20 -20
- data/lib/capybara/spec/session/assert_title.rb +2 -2
- data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
- data/lib/capybara/spec/session/check_spec.rb +19 -10
- data/lib/capybara/spec/session/choose_spec.rb +4 -4
- data/lib/capybara/spec/session/click_button_spec.rb +18 -5
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +6 -6
- data/lib/capybara/spec/session/click_link_spec.rb +13 -13
- data/lib/capybara/spec/session/current_url_spec.rb +2 -2
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +21 -8
- data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
- data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -30
- data/lib/capybara/spec/session/find_button_spec.rb +5 -5
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -2
- data/lib/capybara/spec/session/find_field_spec.rb +11 -7
- data/lib/capybara/spec/session/find_link_spec.rb +2 -2
- data/lib/capybara/spec/session/find_spec.rb +57 -48
- data/lib/capybara/spec/session/first_spec.rb +9 -9
- data/lib/capybara/spec/session/go_back_spec.rb +1 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
- data/lib/capybara/spec/session/has_button_spec.rb +12 -12
- data/lib/capybara/spec/session/has_css_spec.rb +73 -73
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +78 -68
- data/lib/capybara/spec/session/has_link_spec.rb +8 -8
- data/lib/capybara/spec/session/has_select_spec.rb +70 -61
- data/lib/capybara/spec/session/has_selector_spec.rb +28 -28
- data/lib/capybara/spec/session/has_text_spec.rb +6 -6
- data/lib/capybara/spec/session/has_title_spec.rb +2 -2
- data/lib/capybara/spec/session/has_xpath_spec.rb +26 -26
- data/lib/capybara/spec/session/headers.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +3 -3
- data/lib/capybara/spec/session/node_spec.rb +15 -15
- data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
- data/lib/capybara/spec/session/response_code.rb +1 -1
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/screenshot_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +30 -30
- data/lib/capybara/spec/session/selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +14 -14
- data/lib/capybara/spec/session/visit_spec.rb +2 -2
- data/lib/capybara/spec/session/within_frame_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +6 -6
- data/lib/capybara/spec/spec_helper.rb +1 -1
- data/lib/capybara/spec/test_app.rb +1 -1
- data/lib/capybara/spec/views/form.erb +6 -3
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +2 -2
- data/spec/basic_node_spec.rb +5 -5
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +1 -1
- data/spec/rack_test_spec.rb +7 -7
- data/spec/rspec/matchers_spec.rb +6 -6
- data/spec/rspec_spec.rb +1 -1
- data/spec/selector_spec.rb +94 -3
- data/spec/selenium_firefox_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +1 -1
- data/spec/shared_selenium_session.rb +10 -10
- metadata +3 -2
|
@@ -14,14 +14,14 @@ module Capybara
|
|
|
14
14
|
# By default it will check if the expression occurs at least once,
|
|
15
15
|
# but a different number can be specified.
|
|
16
16
|
#
|
|
17
|
-
# page.has_selector?('p.foo', :
|
|
17
|
+
# page.has_selector?('p.foo', count: 4)
|
|
18
18
|
#
|
|
19
19
|
# This will check if the expression occurs exactly 4 times.
|
|
20
20
|
#
|
|
21
21
|
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
22
22
|
# such as :text and :visible.
|
|
23
23
|
#
|
|
24
|
-
# page.has_selector?('li', :
|
|
24
|
+
# page.has_selector?('li', text: 'Horse', visible: true)
|
|
25
25
|
#
|
|
26
26
|
# has_selector? can also accept XPath expressions generated by the
|
|
27
27
|
# XPath gem:
|
|
@@ -36,8 +36,8 @@ module Capybara
|
|
|
36
36
|
# @option args [Range] :between (nil) Range of times that should contain number of times text occurs
|
|
37
37
|
# @return [Boolean] If the expression exists
|
|
38
38
|
#
|
|
39
|
-
def has_selector?(*args)
|
|
40
|
-
assert_selector(*args)
|
|
39
|
+
def has_selector?(*args, &optional_filter_block)
|
|
40
|
+
assert_selector(*args, &optional_filter_block)
|
|
41
41
|
rescue Capybara::ExpectationNotMet
|
|
42
42
|
return false
|
|
43
43
|
end
|
|
@@ -50,83 +50,12 @@ module Capybara
|
|
|
50
50
|
# @param (see Capybara::Node::Finders#has_selector?)
|
|
51
51
|
# @return [Boolean]
|
|
52
52
|
#
|
|
53
|
-
def has_no_selector?(*args)
|
|
54
|
-
assert_no_selector(*args)
|
|
53
|
+
def has_no_selector?(*args, &optional_filter_block)
|
|
54
|
+
assert_no_selector(*args, &optional_filter_block)
|
|
55
55
|
rescue Capybara::ExpectationNotMet
|
|
56
56
|
return false
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
##
|
|
60
|
-
#
|
|
61
|
-
# Checks if the current node matches given selector
|
|
62
|
-
#
|
|
63
|
-
# @param (see Capybara::Node::Finders#has_selector?)
|
|
64
|
-
# @return [Boolean]
|
|
65
|
-
#
|
|
66
|
-
def matches_selector?(*args)
|
|
67
|
-
assert_matches_selector(*args)
|
|
68
|
-
rescue Capybara::ExpectationNotMet
|
|
69
|
-
return false
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
#
|
|
74
|
-
# Checks if the current node matches given XPath expression
|
|
75
|
-
#
|
|
76
|
-
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
|
77
|
-
# @return [Boolean]
|
|
78
|
-
#
|
|
79
|
-
def matches_xpath?(xpath, options={})
|
|
80
|
-
matches_selector?(:xpath, xpath, options)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
#
|
|
85
|
-
# Checks if the current node matches given CSS selector
|
|
86
|
-
#
|
|
87
|
-
# @param [String] css The CSS selector to match against the current code
|
|
88
|
-
# @return [Boolean]
|
|
89
|
-
#
|
|
90
|
-
def matches_css?(css, options={})
|
|
91
|
-
matches_selector?(:css, css, options)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
##
|
|
95
|
-
#
|
|
96
|
-
# Checks if the current node does not match given selector
|
|
97
|
-
# Usage is identical to Capybara::Node::Matchers#has_selector?
|
|
98
|
-
#
|
|
99
|
-
# @param (see Capybara::Node::Finders#has_selector?)
|
|
100
|
-
# @return [Boolean]
|
|
101
|
-
#
|
|
102
|
-
def not_matches_selector?(*args)
|
|
103
|
-
assert_not_matches_selector(*args)
|
|
104
|
-
rescue Capybara::ExpectationNotMet
|
|
105
|
-
return false
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
##
|
|
109
|
-
#
|
|
110
|
-
# Checks if the current node does not match given XPath expression
|
|
111
|
-
#
|
|
112
|
-
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
|
113
|
-
# @return [Boolean]
|
|
114
|
-
#
|
|
115
|
-
def not_matches_xpath?(xpath, options={})
|
|
116
|
-
not_matches_selector?(:xpath, xpath, options)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
##
|
|
120
|
-
#
|
|
121
|
-
# Checks if the current node does not match given CSS selector
|
|
122
|
-
#
|
|
123
|
-
# @param [String] css The CSS selector to match against the current code
|
|
124
|
-
# @return [Boolean]
|
|
125
|
-
#
|
|
126
|
-
def not_matches_css?(css, options={})
|
|
127
|
-
not_matches_selector?(:css, css, options)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
59
|
##
|
|
131
60
|
#
|
|
132
61
|
# Asserts that a given selector is on the page or a descendant of the current node.
|
|
@@ -138,7 +67,7 @@ module Capybara
|
|
|
138
67
|
# By default it will check if the expression occurs at least once,
|
|
139
68
|
# but a different number can be specified.
|
|
140
69
|
#
|
|
141
|
-
# page.assert_selector('p#foo', :
|
|
70
|
+
# page.assert_selector('p#foo', count: 4)
|
|
142
71
|
#
|
|
143
72
|
# This will check if the expression occurs exactly 4 times. See
|
|
144
73
|
# {Capybara::Node::Finders#all} for other available result size options.
|
|
@@ -149,7 +78,7 @@ module Capybara
|
|
|
149
78
|
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
150
79
|
# such as :text and :visible.
|
|
151
80
|
#
|
|
152
|
-
# page.assert_selector('li', :
|
|
81
|
+
# page.assert_selector('li', text: 'Horse', visible: true)
|
|
153
82
|
#
|
|
154
83
|
# `assert_selector` can also accept XPath expressions generated by the
|
|
155
84
|
# XPath gem:
|
|
@@ -160,8 +89,8 @@ module Capybara
|
|
|
160
89
|
# @option options [Integer] :count (nil) Number of times the expression should occur
|
|
161
90
|
# @raise [Capybara::ExpectationNotMet] If the selector does not exist
|
|
162
91
|
#
|
|
163
|
-
def assert_selector(*args)
|
|
164
|
-
query = Capybara::Queries::SelectorQuery.new(*args)
|
|
92
|
+
def assert_selector(*args, &optional_filter_block)
|
|
93
|
+
query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
|
|
165
94
|
synchronize(query.wait) do
|
|
166
95
|
result = query.resolve_for(self)
|
|
167
96
|
unless result.matches_count? && ((!result.empty?) || query.expects_none?)
|
|
@@ -180,15 +109,15 @@ module Capybara
|
|
|
180
109
|
# considered to be an integral part of the selector. This will return
|
|
181
110
|
# true, for example, if a page contains 4 anchors but the query expects 5:
|
|
182
111
|
#
|
|
183
|
-
# page.assert_no_selector('a', :
|
|
184
|
-
# page.assert_no_selector('a', :
|
|
185
|
-
# page.assert_no_selector('a', :
|
|
112
|
+
# page.assert_no_selector('a', minimum: 1) # Found, raises Capybara::ExpectationNotMet
|
|
113
|
+
# page.assert_no_selector('a', count: 4) # Found, raises Capybara::ExpectationNotMet
|
|
114
|
+
# page.assert_no_selector('a', count: 5) # Not Found, returns true
|
|
186
115
|
#
|
|
187
116
|
# @param (see Capybara::Node::Finders#assert_selector)
|
|
188
117
|
# @raise [Capybara::ExpectationNotMet] If the selector exists
|
|
189
118
|
#
|
|
190
|
-
def assert_no_selector(*args)
|
|
191
|
-
query = Capybara::Queries::SelectorQuery.new(*args)
|
|
119
|
+
def assert_no_selector(*args, &optional_filter_block)
|
|
120
|
+
query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
|
|
192
121
|
synchronize(query.wait) do
|
|
193
122
|
result = query.resolve_for(self)
|
|
194
123
|
if result.matches_count? && ((!result.empty?) || query.expects_none?)
|
|
@@ -199,45 +128,6 @@ module Capybara
|
|
|
199
128
|
end
|
|
200
129
|
alias_method :refute_selector, :assert_no_selector
|
|
201
130
|
|
|
202
|
-
##
|
|
203
|
-
#
|
|
204
|
-
# Asserts that the current_node matches a given selector
|
|
205
|
-
#
|
|
206
|
-
# node.assert_matches_selector('p#foo')
|
|
207
|
-
# node.assert_matches_selector(:xpath, '//p[@id="foo"]')
|
|
208
|
-
# node.assert_matches_selector(:foo)
|
|
209
|
-
#
|
|
210
|
-
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
211
|
-
# such as :text and :visible.
|
|
212
|
-
#
|
|
213
|
-
# node.assert_matches_selector('li', :text => 'Horse', :visible => true)
|
|
214
|
-
#
|
|
215
|
-
# @param (see Capybara::Node::Finders#all)
|
|
216
|
-
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
|
217
|
-
#
|
|
218
|
-
def assert_matches_selector(*args)
|
|
219
|
-
query = Capybara::Queries::MatchQuery.new(*args)
|
|
220
|
-
synchronize(query.wait) do
|
|
221
|
-
result = query.resolve_for(self.query_scope)
|
|
222
|
-
unless result.include? self
|
|
223
|
-
raise Capybara::ExpectationNotMet, "Item does not match the provided selector"
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
return true
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def assert_not_matches_selector(*args)
|
|
230
|
-
query = Capybara::Queries::MatchQuery.new(*args)
|
|
231
|
-
synchronize(query.wait) do
|
|
232
|
-
result = query.resolve_for(self.query_scope)
|
|
233
|
-
if result.include? self
|
|
234
|
-
raise Capybara::ExpectationNotMet, 'Item matched the provided selector'
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
return true
|
|
238
|
-
end
|
|
239
|
-
alias_method :refute_matches_selector, :assert_not_matches_selector
|
|
240
|
-
|
|
241
131
|
##
|
|
242
132
|
#
|
|
243
133
|
# Checks if a given XPath expression is on the page or a descendant of the current node.
|
|
@@ -247,14 +137,14 @@ module Capybara
|
|
|
247
137
|
# By default it will check if the expression occurs at least once,
|
|
248
138
|
# but a different number can be specified.
|
|
249
139
|
#
|
|
250
|
-
# page.has_xpath?('.//p[@id="foo"]', :
|
|
140
|
+
# page.has_xpath?('.//p[@id="foo"]', count: 4)
|
|
251
141
|
#
|
|
252
142
|
# This will check if the expression occurs exactly 4 times.
|
|
253
143
|
#
|
|
254
144
|
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
255
145
|
# such as :text and :visible.
|
|
256
146
|
#
|
|
257
|
-
# page.has_xpath?('.//li', :
|
|
147
|
+
# page.has_xpath?('.//li', text: 'Horse', visible: true)
|
|
258
148
|
#
|
|
259
149
|
# has_xpath? can also accept XPath expressions generate by the
|
|
260
150
|
# XPath gem:
|
|
@@ -267,8 +157,8 @@ module Capybara
|
|
|
267
157
|
# @option options [Integer] :count (nil) Number of times the expression should occur
|
|
268
158
|
# @return [Boolean] If the expression exists
|
|
269
159
|
#
|
|
270
|
-
def has_xpath?(path, options={})
|
|
271
|
-
has_selector?(:xpath, path, options)
|
|
160
|
+
def has_xpath?(path, options={}, &optional_filter_block)
|
|
161
|
+
has_selector?(:xpath, path, options, &optional_filter_block)
|
|
272
162
|
end
|
|
273
163
|
|
|
274
164
|
##
|
|
@@ -279,8 +169,8 @@ module Capybara
|
|
|
279
169
|
# @param (see Capybara::Node::Finders#has_xpath?)
|
|
280
170
|
# @return [Boolean]
|
|
281
171
|
#
|
|
282
|
-
def has_no_xpath?(path, options={})
|
|
283
|
-
has_no_selector?(:xpath, path, options)
|
|
172
|
+
def has_no_xpath?(path, options={}, &optional_filter_block)
|
|
173
|
+
has_no_selector?(:xpath, path, options, &optional_filter_block)
|
|
284
174
|
end
|
|
285
175
|
|
|
286
176
|
##
|
|
@@ -292,22 +182,22 @@ module Capybara
|
|
|
292
182
|
# By default it will check if the selector occurs at least once,
|
|
293
183
|
# but a different number can be specified.
|
|
294
184
|
#
|
|
295
|
-
# page.has_css?('p#foo', :
|
|
185
|
+
# page.has_css?('p#foo', count: 4)
|
|
296
186
|
#
|
|
297
187
|
# This will check if the selector occurs exactly 4 times.
|
|
298
188
|
#
|
|
299
189
|
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
300
190
|
# such as :text and :visible.
|
|
301
191
|
#
|
|
302
|
-
# page.has_css?('li', :
|
|
192
|
+
# page.has_css?('li', text: 'Horse', visible: true)
|
|
303
193
|
#
|
|
304
194
|
# @param [String] path A CSS selector
|
|
305
195
|
# @param options (see Capybara::Node::Finders#all)
|
|
306
196
|
# @option options [Integer] :count (nil) Number of times the selector should occur
|
|
307
197
|
# @return [Boolean] If the selector exists
|
|
308
198
|
#
|
|
309
|
-
def has_css?(path, options={})
|
|
310
|
-
has_selector?(:css, path, options)
|
|
199
|
+
def has_css?(path, options={}, &optional_filter_block)
|
|
200
|
+
has_selector?(:css, path, options, &optional_filter_block)
|
|
311
201
|
end
|
|
312
202
|
|
|
313
203
|
##
|
|
@@ -318,8 +208,8 @@ module Capybara
|
|
|
318
208
|
# @param (see Capybara::Node::Finders#has_css?)
|
|
319
209
|
# @return [Boolean]
|
|
320
210
|
#
|
|
321
|
-
def has_no_css?(path, options={})
|
|
322
|
-
has_no_selector?(:css, path, options)
|
|
211
|
+
def has_no_css?(path, options={}, &optional_filter_block)
|
|
212
|
+
has_no_selector?(:css, path, options, &optional_filter_block)
|
|
323
213
|
end
|
|
324
214
|
|
|
325
215
|
##
|
|
@@ -332,8 +222,9 @@ module Capybara
|
|
|
332
222
|
# @option options [String, Regexp] :href The value the href attribute must be
|
|
333
223
|
# @return [Boolean] Whether it exists
|
|
334
224
|
#
|
|
335
|
-
def has_link?(locator, options={})
|
|
336
|
-
|
|
225
|
+
def has_link?(locator=nil, options={}, &optional_filter_block)
|
|
226
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
227
|
+
has_selector?(:link, locator, options, &optional_filter_block)
|
|
337
228
|
end
|
|
338
229
|
|
|
339
230
|
##
|
|
@@ -344,8 +235,9 @@ module Capybara
|
|
|
344
235
|
# @param (see Capybara::Node::Finders#has_link?)
|
|
345
236
|
# @return [Boolean] Whether it doesn't exist
|
|
346
237
|
#
|
|
347
|
-
def has_no_link?(locator, options={})
|
|
348
|
-
|
|
238
|
+
def has_no_link?(locator=nil, options={}, &optional_filter_block)
|
|
239
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
240
|
+
has_no_selector?(:link, locator, options, &optional_filter_block)
|
|
349
241
|
end
|
|
350
242
|
|
|
351
243
|
##
|
|
@@ -356,8 +248,9 @@ module Capybara
|
|
|
356
248
|
# @param [String] locator The text, value or id of a button to check for
|
|
357
249
|
# @return [Boolean] Whether it exists
|
|
358
250
|
#
|
|
359
|
-
def has_button?(locator, options={})
|
|
360
|
-
|
|
251
|
+
def has_button?(locator=nil, options={}, &optional_filter_block)
|
|
252
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
253
|
+
has_selector?(:button, locator, options, &optional_filter_block)
|
|
361
254
|
end
|
|
362
255
|
|
|
363
256
|
##
|
|
@@ -368,8 +261,9 @@ module Capybara
|
|
|
368
261
|
# @param [String] locator The text, value or id of a button to check for
|
|
369
262
|
# @return [Boolean] Whether it doesn't exist
|
|
370
263
|
#
|
|
371
|
-
def has_no_button?(locator, options={})
|
|
372
|
-
|
|
264
|
+
def has_no_button?(locator=nil, options={}, &optional_filter_block)
|
|
265
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
266
|
+
has_no_selector?(:button, locator, options, &optional_filter_block)
|
|
373
267
|
end
|
|
374
268
|
|
|
375
269
|
##
|
|
@@ -381,11 +275,11 @@ module Capybara
|
|
|
381
275
|
# HTML5 email/url/etc. fields, it's possible to specify a :with
|
|
382
276
|
# option to specify the text the field should contain:
|
|
383
277
|
#
|
|
384
|
-
# page.has_field?('Name', :
|
|
278
|
+
# page.has_field?('Name', with: 'Jonas')
|
|
385
279
|
#
|
|
386
280
|
# It is also possible to filter by the field type attribute:
|
|
387
281
|
#
|
|
388
|
-
# page.has_field?('Email', :
|
|
282
|
+
# page.has_field?('Email', type: 'email')
|
|
389
283
|
#
|
|
390
284
|
# Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
|
|
391
285
|
#
|
|
@@ -394,8 +288,9 @@ module Capybara
|
|
|
394
288
|
# @option options [String] :type The type attribute of the field
|
|
395
289
|
# @return [Boolean] Whether it exists
|
|
396
290
|
#
|
|
397
|
-
def has_field?(locator, options={})
|
|
398
|
-
|
|
291
|
+
def has_field?(locator=nil, options={}, &optional_filter_block)
|
|
292
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
293
|
+
has_selector?(:field, locator, options, &optional_filter_block)
|
|
399
294
|
end
|
|
400
295
|
|
|
401
296
|
##
|
|
@@ -408,8 +303,9 @@ module Capybara
|
|
|
408
303
|
# @option options [String] :type The type attribute of the field
|
|
409
304
|
# @return [Boolean] Whether it doesn't exist
|
|
410
305
|
#
|
|
411
|
-
def has_no_field?(locator, options={})
|
|
412
|
-
|
|
306
|
+
def has_no_field?(locator=nil, options={}, &optional_filter_block)
|
|
307
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
308
|
+
has_no_selector?(:field, locator, options, &optional_filter_block)
|
|
413
309
|
end
|
|
414
310
|
|
|
415
311
|
##
|
|
@@ -421,8 +317,9 @@ module Capybara
|
|
|
421
317
|
# @param [String] locator The label, name or id of a checked field
|
|
422
318
|
# @return [Boolean] Whether it exists
|
|
423
319
|
#
|
|
424
|
-
def has_checked_field?(locator, options={})
|
|
425
|
-
|
|
320
|
+
def has_checked_field?(locator=nil, options={}, &optional_filter_block)
|
|
321
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
322
|
+
has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
|
426
323
|
end
|
|
427
324
|
|
|
428
325
|
##
|
|
@@ -434,8 +331,9 @@ module Capybara
|
|
|
434
331
|
# @param [String] locator The label, name or id of a checked field
|
|
435
332
|
# @return [Boolean] Whether it doesn't exist
|
|
436
333
|
#
|
|
437
|
-
def has_no_checked_field?(locator, options={})
|
|
438
|
-
|
|
334
|
+
def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
|
|
335
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
336
|
+
has_no_selector?(:field, locator, options.merge(checked: true))
|
|
439
337
|
end
|
|
440
338
|
|
|
441
339
|
##
|
|
@@ -447,8 +345,9 @@ module Capybara
|
|
|
447
345
|
# @param [String] locator The label, name or id of an unchecked field
|
|
448
346
|
# @return [Boolean] Whether it exists
|
|
449
347
|
#
|
|
450
|
-
def has_unchecked_field?(locator, options={})
|
|
451
|
-
|
|
348
|
+
def has_unchecked_field?(locator=nil, options={}, &optional_filter_block)
|
|
349
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
350
|
+
has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
|
452
351
|
end
|
|
453
352
|
|
|
454
353
|
##
|
|
@@ -460,8 +359,9 @@ module Capybara
|
|
|
460
359
|
# @param [String] locator The label, name or id of an unchecked field
|
|
461
360
|
# @return [Boolean] Whether it doesn't exist
|
|
462
361
|
#
|
|
463
|
-
def has_no_unchecked_field?(locator, options={})
|
|
464
|
-
|
|
362
|
+
def has_no_unchecked_field?(locator=nil, options={}, &optional_filter_block)
|
|
363
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
364
|
+
has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
|
465
365
|
end
|
|
466
366
|
|
|
467
367
|
##
|
|
@@ -471,20 +371,20 @@ module Capybara
|
|
|
471
371
|
#
|
|
472
372
|
# It can be specified which option should currently be selected:
|
|
473
373
|
#
|
|
474
|
-
# page.has_select?('Language', :
|
|
374
|
+
# page.has_select?('Language', selected: 'German')
|
|
475
375
|
#
|
|
476
376
|
# For multiple select boxes, several options may be specified:
|
|
477
377
|
#
|
|
478
|
-
# page.has_select?('Language', :
|
|
378
|
+
# page.has_select?('Language', selected: ['English', 'German'])
|
|
479
379
|
#
|
|
480
380
|
# It's also possible to check if the exact set of options exists for
|
|
481
381
|
# this select box:
|
|
482
382
|
#
|
|
483
|
-
# page.has_select?('Language', :
|
|
383
|
+
# page.has_select?('Language', options: ['English', 'German', 'Spanish'])
|
|
484
384
|
#
|
|
485
385
|
# You can also check for a partial set of options:
|
|
486
386
|
#
|
|
487
|
-
# page.has_select?('Language', :
|
|
387
|
+
# page.has_select?('Language', with_options: ['English', 'German'])
|
|
488
388
|
#
|
|
489
389
|
# @param [String] locator The label, name or id of a select box
|
|
490
390
|
# @option options [Array] :options Options which should be contained in this select box
|
|
@@ -492,8 +392,9 @@ module Capybara
|
|
|
492
392
|
# @option options [String, Array] :selected Options which should be selected
|
|
493
393
|
# @return [Boolean] Whether it exists
|
|
494
394
|
#
|
|
495
|
-
def has_select?(locator, options={})
|
|
496
|
-
|
|
395
|
+
def has_select?(locator=nil, options={}, &optional_filter_block)
|
|
396
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
397
|
+
has_selector?(:select, locator, options, &optional_filter_block)
|
|
497
398
|
end
|
|
498
399
|
|
|
499
400
|
##
|
|
@@ -504,8 +405,9 @@ module Capybara
|
|
|
504
405
|
# @param (see Capybara::Node::Matchers#has_select?)
|
|
505
406
|
# @return [Boolean] Whether it doesn't exist
|
|
506
407
|
#
|
|
507
|
-
def has_no_select?(locator, options={})
|
|
508
|
-
|
|
408
|
+
def has_no_select?(locator=nil, options={}, &optional_filter_block)
|
|
409
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
410
|
+
has_no_selector?(:select, locator, options, &optional_filter_block)
|
|
509
411
|
end
|
|
510
412
|
|
|
511
413
|
##
|
|
@@ -518,8 +420,9 @@ module Capybara
|
|
|
518
420
|
# @param [String] locator The id or caption of a table
|
|
519
421
|
# @return [Boolean] Whether it exist
|
|
520
422
|
#
|
|
521
|
-
def has_table?(locator, options={})
|
|
522
|
-
|
|
423
|
+
def has_table?(locator=nil, options={}, &optional_filter_block)
|
|
424
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
425
|
+
has_selector?(:table, locator, options, &optional_filter_block)
|
|
523
426
|
end
|
|
524
427
|
|
|
525
428
|
##
|
|
@@ -530,10 +433,122 @@ module Capybara
|
|
|
530
433
|
# @param (see Capybara::Node::Matchers#has_table?)
|
|
531
434
|
# @return [Boolean] Whether it doesn't exist
|
|
532
435
|
#
|
|
533
|
-
def has_no_table?(locator, options={})
|
|
534
|
-
|
|
436
|
+
def has_no_table?(locator=nil, options={}, &optional_filter_block)
|
|
437
|
+
locator, options = nil, locator if locator.is_a? Hash
|
|
438
|
+
has_no_selector?(:table, locator, options, &optional_filter_block)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
##
|
|
442
|
+
#
|
|
443
|
+
# Asserts that the current_node matches a given selector
|
|
444
|
+
#
|
|
445
|
+
# node.assert_matches_selector('p#foo')
|
|
446
|
+
# node.assert_matches_selector(:xpath, '//p[@id="foo"]')
|
|
447
|
+
# node.assert_matches_selector(:foo)
|
|
448
|
+
#
|
|
449
|
+
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
|
450
|
+
# such as :text and :visible.
|
|
451
|
+
#
|
|
452
|
+
# node.assert_matches_selector('li', text: 'Horse', visible: true)
|
|
453
|
+
#
|
|
454
|
+
# @param (see Capybara::Node::Finders#all)
|
|
455
|
+
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
|
456
|
+
#
|
|
457
|
+
def assert_matches_selector(*args, &optional_filter_block)
|
|
458
|
+
query = Capybara::Queries::MatchQuery.new(*args, &optional_filter_block)
|
|
459
|
+
synchronize(query.wait) do
|
|
460
|
+
result = query.resolve_for(self.query_scope)
|
|
461
|
+
unless result.include? self
|
|
462
|
+
raise Capybara::ExpectationNotMet, "Item does not match the provided selector"
|
|
463
|
+
end
|
|
464
|
+
end
|
|
465
|
+
return true
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def assert_not_matches_selector(*args, &optional_filter_block)
|
|
469
|
+
query = Capybara::Queries::MatchQuery.new(*args, &optional_filter_block)
|
|
470
|
+
synchronize(query.wait) do
|
|
471
|
+
result = query.resolve_for(self.query_scope)
|
|
472
|
+
if result.include? self
|
|
473
|
+
raise Capybara::ExpectationNotMet, 'Item matched the provided selector'
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
return true
|
|
477
|
+
end
|
|
478
|
+
alias_method :refute_matches_selector, :assert_not_matches_selector
|
|
479
|
+
|
|
480
|
+
##
|
|
481
|
+
#
|
|
482
|
+
# Checks if the current node matches given selector
|
|
483
|
+
#
|
|
484
|
+
# @param (see Capybara::Node::Finders#has_selector?)
|
|
485
|
+
# @return [Boolean]
|
|
486
|
+
#
|
|
487
|
+
def matches_selector?(*args, &optional_filter_block)
|
|
488
|
+
assert_matches_selector(*args, &optional_filter_block)
|
|
489
|
+
rescue Capybara::ExpectationNotMet
|
|
490
|
+
return false
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
##
|
|
494
|
+
#
|
|
495
|
+
# Checks if the current node matches given XPath expression
|
|
496
|
+
#
|
|
497
|
+
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
|
498
|
+
# @return [Boolean]
|
|
499
|
+
#
|
|
500
|
+
def matches_xpath?(xpath, options={}, &optional_filter_block)
|
|
501
|
+
matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
##
|
|
505
|
+
#
|
|
506
|
+
# Checks if the current node matches given CSS selector
|
|
507
|
+
#
|
|
508
|
+
# @param [String] css The CSS selector to match against the current code
|
|
509
|
+
# @return [Boolean]
|
|
510
|
+
#
|
|
511
|
+
def matches_css?(css, options={}, &optional_filter_block)
|
|
512
|
+
matches_selector?(:css, css, options, &optional_filter_block)
|
|
535
513
|
end
|
|
536
514
|
|
|
515
|
+
##
|
|
516
|
+
#
|
|
517
|
+
# Checks if the current node does not match given selector
|
|
518
|
+
# Usage is identical to Capybara::Node::Matchers#has_selector?
|
|
519
|
+
#
|
|
520
|
+
# @param (see Capybara::Node::Finders#has_selector?)
|
|
521
|
+
# @return [Boolean]
|
|
522
|
+
#
|
|
523
|
+
def not_matches_selector?(*args, &optional_filter_block)
|
|
524
|
+
assert_not_matches_selector(*args, &optional_filter_block)
|
|
525
|
+
rescue Capybara::ExpectationNotMet
|
|
526
|
+
return false
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
##
|
|
530
|
+
#
|
|
531
|
+
# Checks if the current node does not match given XPath expression
|
|
532
|
+
#
|
|
533
|
+
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
|
534
|
+
# @return [Boolean]
|
|
535
|
+
#
|
|
536
|
+
def not_matches_xpath?(xpath, options={}, &optional_filter_block)
|
|
537
|
+
not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
##
|
|
541
|
+
#
|
|
542
|
+
# Checks if the current node does not match given CSS selector
|
|
543
|
+
#
|
|
544
|
+
# @param [String] css The CSS selector to match against the current code
|
|
545
|
+
# @return [Boolean]
|
|
546
|
+
#
|
|
547
|
+
def not_matches_css?(css, options={}, &optional_filter_block)
|
|
548
|
+
not_matches_selector?(:css, css, options, &optional_filter_block)
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
|
|
537
552
|
##
|
|
538
553
|
# Asserts that the page or current node has the given text content,
|
|
539
554
|
# ignoring any HTML tags.
|
|
@@ -629,6 +644,7 @@ module Capybara
|
|
|
629
644
|
def ==(other)
|
|
630
645
|
self.eql?(other) || (other.respond_to?(:base) && base == other.base)
|
|
631
646
|
end
|
|
647
|
+
|
|
632
648
|
end
|
|
633
649
|
end
|
|
634
650
|
end
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module Capybara
|
|
2
2
|
module Queries
|
|
3
3
|
class MatchQuery < Capybara::Queries::SelectorQuery
|
|
4
|
-
VALID_KEYS = [:text, :visible, :exact, :wait]
|
|
5
|
-
|
|
6
4
|
def visible
|
|
7
5
|
if options.has_key?(:visible)
|
|
8
6
|
super
|
|
@@ -14,7 +12,7 @@ module Capybara
|
|
|
14
12
|
private
|
|
15
13
|
|
|
16
14
|
def valid_keys
|
|
17
|
-
|
|
15
|
+
super - COUNT_KEYS
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
18
|
end
|