Add support for <button> tag in Session#click_button
This commit is contained in:
parent
ea6857b52b
commit
510f33e86d
|
@ -142,8 +142,9 @@ module Capybara
|
|||
end
|
||||
|
||||
def find_button(locator)
|
||||
button = find("//input[@type='submit' or @type='image'][@id='#{locator}' or @value='#{locator}']").first || find("//button[@id='#{locator}' or @value='#{locator}' or contains(.,'#{locator}')]").first
|
||||
raise Capybara::ElementNotFound, "no button with value or id '#{locator}' found" unless button
|
||||
button = find("//input[@type='submit' or @type='image'][@id='#{locator}' or @value='#{locator}']").first \
|
||||
|| find("//button[@id='#{locator}' or @value='#{locator}' or contains(.,'#{locator}')]").first
|
||||
raise Capybara::ElementNotFound, "no button with value or id or text '#{locator}' found" unless button
|
||||
button
|
||||
end
|
||||
|
||||
|
|
|
@ -145,6 +145,38 @@ shared_examples_for "session" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the button is defined by a <button> tag" do
|
||||
|
||||
before do
|
||||
@session.visit('/buttons')
|
||||
end
|
||||
|
||||
context "with text given" do
|
||||
it "should locate the button" do
|
||||
running do
|
||||
@session.click_button('Click me')
|
||||
end.should_not raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with id given" do
|
||||
it "should locate the button" do
|
||||
running do
|
||||
@session.click_button('click_me_123')
|
||||
end.should_not raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with value given" do
|
||||
it "should locate the button" do
|
||||
running do
|
||||
@session.click_button('click_me')
|
||||
end.should_not raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with a locator that doesn't exist" do
|
||||
it "should raise an error" do
|
||||
running do
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<h1>Buttons</h1>
|
||||
<button>Click me!</button>
|
||||
<button id="click_me_123">Click me by id!</button>
|
||||
<button value="click_me">Click me by value!</button>
|
Loading…
Reference in New Issue