Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #652 from grzuy/650_support_type_filter

Support :type option for #has_field? matcher
  • Loading branch information...
commit bb7f4b1d688b57b5c1ccbe6a996a0860323e2f3f 2 parents c387aba + 77c2f30
Elabs authored
View
6 lib/capybara/node/matchers.rb
@@ -253,8 +253,13 @@ def has_no_button?(locator)
#
# page.has_field?('Name', :with => 'Jonas')
#
+ # It is also possible to filter by the field type attribute:
+ #
+ # page.has_field?('Email', :type => 'email')
+ #
# @param [String] locator The label, name or id of a field to check for
# @option options [String] :with The text content of the field
+ # @option options [String] :type The type attribute of the field
# @return [Boolean] Whether it exists
#
def has_field?(locator, options={})
@@ -268,6 +273,7 @@ def has_field?(locator, options={})
#
# @param [String] locator The label, name or id of a field to check for
# @option options [String] :with The text content of the field
+ # @option options [String] :type The type attribute of the field
# @return [Boolean] Whether it doesn't exist
#
def has_no_field?(locator, options={})
View
1  lib/capybara/selector.rb
@@ -80,6 +80,7 @@ def filter(name, &block)
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
filter(:with) { |node, with| node.value == with }
+ filter(:type) { |node, type| node[:type] == type }
end
Capybara.add_selector(:fieldset) do
View
28 lib/capybara/spec/session/has_field_spec.rb
@@ -36,6 +36,20 @@
@session.should_not have_field('First Name', :with => 'John')
end
end
+
+ context 'with type' do
+ it "should be true if a field with the given type is on the page" do
+ @session.should have_field('First Name', :type => 'text')
+ @session.should have_field('Html5 Email', :type => 'email')
+ @session.should have_field('Html5 Tel', :type => 'tel')
+ end
+
+ it "should be false if the given field is not on the page" do
+ @session.should_not have_field('First Name', :type => 'email')
+ @session.should_not have_field('Html5 Email', :type => 'tel')
+ @session.should_not have_field('Description', :type => '')
+ end
+ end
end
describe '#has_no_field' do
@@ -75,6 +89,20 @@
@session.should have_no_field('First Name', :with => 'John')
end
end
+
+ context 'with type' do
+ it "should be false if a field with the given type is on the page" do
+ @session.should_not have_no_field('First Name', :type => 'text')
+ @session.should_not have_no_field('Html5 Email', :type => 'email')
+ @session.should_not have_no_field('Html5 Tel', :type => 'tel')
+ end
+
+ it "should be true if the given field is not on the page" do
+ @session.should have_no_field('First Name', :type => 'email')
+ @session.should have_no_field('Html5 Email', :type => 'tel')
+ @session.should have_no_field('Description', :type => '')
+ end
+ end
end
describe '#has_checked_field?' do
Please sign in to comment.
Something went wrong with that request. Please try again.