mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Made find_link and find_button public
This commit is contained in:
parent
dcc082337e
commit
d74f2e86da
2 changed files with 51 additions and 17 deletions
|
@ -100,6 +100,23 @@ class Capybara::Session
|
|||
field
|
||||
end
|
||||
alias_method :field_labeled, :find_field
|
||||
|
||||
def find_link(locator)
|
||||
link = find_element("//a[@id='#{locator}']", "//a[contains(.,'#{locator}')]", "//a[@title='#{locator}']")
|
||||
raise Capybara::ElementNotFound, "no link with title, id or text '#{locator}' found" unless link
|
||||
link
|
||||
end
|
||||
|
||||
def find_button(locator)
|
||||
button = find_element(
|
||||
"//input[@type='submit'][@id='#{locator}']",
|
||||
"//input[@type='submit'][@value='#{locator}']",
|
||||
"//input[@type='image'][@id='#{locator}']",
|
||||
"//input[@type='image'][@value='#{locator}']"
|
||||
)
|
||||
raise Capybara::ElementNotFound, "no button with value or id '#{locator}' found" unless button
|
||||
button
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
@ -126,23 +143,6 @@ private
|
|||
@scopes ||= []
|
||||
end
|
||||
|
||||
def find_link(locator)
|
||||
link = find_element("//a[@id='#{locator}']", "//a[contains(.,'#{locator}')]", "//a[@title='#{locator}']")
|
||||
raise Capybara::ElementNotFound, "no link with title, id or text '#{locator}' found" unless link
|
||||
link
|
||||
end
|
||||
|
||||
def find_button(locator)
|
||||
button = find_element(
|
||||
"//input[@type='submit'][@id='#{locator}']",
|
||||
"//input[@type='submit'][@value='#{locator}']",
|
||||
"//input[@type='image'][@id='#{locator}']",
|
||||
"//input[@type='image'][@value='#{locator}']"
|
||||
)
|
||||
raise Capybara::ElementNotFound, "no button with value or id '#{locator}' found" unless button
|
||||
button
|
||||
end
|
||||
|
||||
FIELDS_PATHS = {
|
||||
:text_field => proc { |id| "//input[@type='text'][@id='#{id}']" },
|
||||
:text_area => proc { |id| "//textarea[@id='#{id}']" },
|
||||
|
|
|
@ -489,6 +489,40 @@ shared_examples_for "session" do
|
|||
}.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#find_link' do
|
||||
before do
|
||||
@session.visit('/with_html')
|
||||
end
|
||||
|
||||
it "should find any field" do
|
||||
@session.find_link('foo').text.should == "ullamco"
|
||||
@session.find_link('labore')[:href].should == "/with_simple_html"
|
||||
end
|
||||
|
||||
it "should raise an error if the field doesn't exist" do
|
||||
running {
|
||||
@session.find_link('Does not exist')
|
||||
}.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#find_button' do
|
||||
before do
|
||||
@session.visit('/form')
|
||||
end
|
||||
|
||||
it "should find any field" do
|
||||
@session.find_button('med')[:id].should == "mediocre"
|
||||
@session.find_button('crap321').value.should == "crappy"
|
||||
end
|
||||
|
||||
it "should raise an error if the field doesn't exist" do
|
||||
running {
|
||||
@session.find_button('Does not exist')
|
||||
}.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#within' do
|
||||
before do
|
||||
|
|
Loading…
Add table
Reference in a new issue