click link by title
This commit is contained in:
parent
66a5af0f56
commit
130f5a9d1b
@ -14,7 +14,8 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def matches_text?(link_text)
|
def matches_text?(link_text)
|
||||||
text =~ /#{Regexp.escape(link_text.to_s)}/i
|
matcher = /#{Regexp.escape(link_text.to_s)}/i
|
||||||
|
text =~ matcher || title =~ matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
@ -27,6 +28,10 @@ module Webrat
|
|||||||
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def title
|
||||||
|
@element['title']
|
||||||
|
end
|
||||||
|
|
||||||
def href
|
def href
|
||||||
@element["href"]
|
@element["href"]
|
||||||
end
|
end
|
||||||
|
@ -148,6 +148,14 @@ describe "clicks_link" do
|
|||||||
@session.clicks_link "Link text"
|
@session.clicks_link "Link text"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should work with anchor titles" do
|
||||||
|
@session.response_body = <<-EOS
|
||||||
|
<a href="/page" title="Link title">Link text</a>
|
||||||
|
EOS
|
||||||
|
@session.expects(:get).with("/page", {})
|
||||||
|
@session.clicks_link "Link title"
|
||||||
|
end
|
||||||
|
|
||||||
it "should match the first matching link" do
|
it "should match the first matching link" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<a href="/page1">Link text</a>
|
<a href="/page1">Link text</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user