I am trying to test this form with cucumber:
http://westside-consulting.com/tes/application/
(never mind the PHP errors at the bottom - they don't affect this
test). You will see that there are two forms, each with a button
where value="submit". Then if my script executes 'click_button
"submit" ' it submits the first form in the page which is the wrong
form. Looking in the code for Webrat I found in core/scope.rb
def click_button(value = nil)
find_button(value).click
end
then in core/locators/button_locator.rb:
def find_button(value) #:nodoc:
ButtonLocator.new(@session, dom, value).locate!
end
near the top of that:
def locate
ButtonField.load(@session, button_element)
end
def button_element
button_elements.detect do |element|
@value.nil? ||
matches_id?(element) ||
matches_value?(element) ||
matches_html?(element) ||
matches_alt?(element)
end
end
etc.
So this is iterating over each button in the form, in the order in
which they appear, and then checking whether each of the attributes ==
@value in the above order. So if there is more than one button with
the same value, html, or alt, it just clicks the first one, which may
or may not be what I wanted!
Wouldn't it be more useful if I could say "click_button :id =>
'submit' "?
I'm new to Ruby but I would be happy to try my hand at submitting a
patch with a new method. Alas, Ruby does not seem to allow for
function overloading as does C++, so I would have to come up with a
new name in order to use this idiom. Would anyone like to suggest a
name? Would "click_button_with" work for people?