diff --git a/lib/webrat/field.rb b/lib/webrat/field.rb index 34b70bd..f6b1a1e 100644 --- a/lib/webrat/field.rb +++ b/lib/webrat/field.rb @@ -101,8 +101,12 @@ module Webrat class ButtonField < Field + def matches_text?(text) + @element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i + end + def matches_value?(value) - @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i + @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) end def to_param diff --git a/lib/webrat/form.rb b/lib/webrat/form.rb index 50c2e2d..4b84711 100644 --- a/lib/webrat/form.rb +++ b/lib/webrat/form.rb @@ -45,7 +45,7 @@ module Webrat @fields = [] - (@element / "input, textarea, select").each do |field_element| + (@element / "button, input, textarea, select").each do |field_element| @fields << Field.class_for_element(field_element).new(self, field_element) end diff --git a/test/clicks_button_test.rb b/test/clicks_button_test.rb index a309f4c..ea21557 100644 --- a/test/clicks_button_test.rb +++ b/test/clicks_button_test.rb @@ -332,4 +332,26 @@ class ClicksButtonTest < Test::Unit::TestCase @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""}) @session.clicks_button end + + def test_should_recognize_button_tags + @response.stubs(:body).returns(<<-EOS) +
+ +
+ + EOS + @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""}) + @session.clicks_button "Login" + end end