public
Fork of brynary/webrat
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://www.brynary.com/uploads/webrat/rdoc/index.html
Clone URL: git://github.com/nicksieger/webrat.git
Add support for 'button' elements in forms, and selecting
them by inner text
nicksieger (author)
Thu Apr 17 09:31:40 -0700 2008
commit  e6486b640bc45c483caa9d574e4a1d327074354b
tree    2b62484586951d8249dd5766ac4b37d442ff564a
parent  13b0ec75f427f5b69c162fb18020181caee77ac1
...
101
102
103
 
 
 
 
104
105
 
106
107
108
...
101
102
103
104
105
106
107
108
 
109
110
111
112
0
@@ -101,8 +101,12 @@ module Webrat
0
   
0
   class ButtonField < Field
0
 
0
+ def matches_text?(text)
0
+ @element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i
0
+ end
0
+
0
     def matches_value?(value)
0
- @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i
0
+ @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value)
0
     end
0
 
0
     def to_param
...
45
46
47
48
 
49
50
51
...
45
46
47
 
48
49
50
51
0
@@ -45,7 +45,7 @@ module Webrat
0
       
0
       @fields = []
0
       
0
- (@element / "input, textarea, select").each do |field_element|
0
+ (@element / "button, input, textarea, select").each do |field_element|
0
         @fields << Field.class_for_element(field_element).new(self, field_element)
0
       end
0
       
...
332
333
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
0
@@ -332,4 +332,26 @@ class ClicksButtonTest < Test::Unit::TestCase
0
     @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""})
0
     @session.clicks_button
0
   end
0
+
0
+ def test_should_recognize_button_tags
0
+ @response.stubs(:body).returns(<<-EOS)
0
+ <form method="get" action="/login">
0
+ <input id="user_email" name="user[email]" value="" type="text" />
0
+ <button type="submit" />
0
+ </form>
0
+ EOS
0
+ @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""})
0
+ @session.clicks_button
0
+ end
0
+
0
+ def test_should_recognize_button_tags_by_content
0
+ @response.stubs(:body).returns(<<-EOS)
0
+ <form method="get" action="/login">
0
+ <input id="user_email" name="user[email]" value="" type="text" />
0
+ <button type="submit">Login</button>
0
+ </form>
0
+ EOS
0
+ @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""})
0
+ @session.clicks_button "Login"
0
+ end
0
 end

Comments

    No one has commented yet.