Add support to click_button for IDs (Patch form Gwyn Morfey)
This commit is contained in:
parent
d7a9447d59
commit
cf55dbad94
@ -26,6 +26,7 @@
|
|||||||
* Support clicking links by title (Patch from Dan Barry)
|
* Support clicking links by title (Patch from Dan Barry)
|
||||||
* Added missing spec for clicking image buttons (Patch from Tim Harper)
|
* Added missing spec for clicking image buttons (Patch from Tim Harper)
|
||||||
* Switched tests to specs, and from Mocha to RSpec's mocking library
|
* Switched tests to specs, and from Mocha to RSpec's mocking library
|
||||||
|
* Add support to click_button for IDs (Patch form Gwyn Morfey)
|
||||||
|
|
||||||
* Bug fixes
|
* Bug fixes
|
||||||
|
|
||||||
|
@ -138,6 +138,10 @@ module Webrat
|
|||||||
@element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i
|
@element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def matches_id?(id)
|
||||||
|
# @element["id"] =~ /^\W*#{Regexp.escape(id.to_s)}/i
|
||||||
|
# end
|
||||||
|
|
||||||
def matches_value?(value)
|
def matches_value?(value)
|
||||||
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
|
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,7 @@ module Webrat
|
|||||||
def find_button(value = nil)
|
def find_button(value = nil)
|
||||||
return fields_by_type([ButtonField]).first if value.nil?
|
return fields_by_type([ButtonField]).first if value.nil?
|
||||||
possible_buttons = fields_by_type([ButtonField])
|
possible_buttons = fields_by_type([ButtonField])
|
||||||
|
possible_buttons.detect { |possible_button| possible_button.matches_id?(value) } ||
|
||||||
possible_buttons.detect { |possible_button| possible_button.matches_value?(value) }
|
possible_buttons.detect { |possible_button| possible_button.matches_value?(value) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -344,6 +344,16 @@ describe "clicks_button" do
|
|||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should find buttons by their IDs" do
|
||||||
|
@session.response_body = <<-EOS
|
||||||
|
<form action="/">
|
||||||
|
<input type="submit" id="my_button" />
|
||||||
|
</form>
|
||||||
|
EOS
|
||||||
|
@session.should_receive(:get)
|
||||||
|
@session.clicks_button "my_button"
|
||||||
|
end
|
||||||
|
|
||||||
it "should find image buttons by their alt text" do
|
it "should find image buttons by their alt text" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<form action="/">
|
<form action="/">
|
||||||
|
Loading…
Reference in New Issue
Block a user