Add options for click_button
This commit is contained in:
parent
f063375b9b
commit
e67f7bf1c2
|
@ -33,8 +33,8 @@ module Capybara
|
|||
#
|
||||
# @param [String] locator Text, id or value of button
|
||||
#
|
||||
def click_button(locator)
|
||||
find(:button, locator).click
|
||||
def click_button(locator, options={})
|
||||
find(:button, locator, options).click
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -137,7 +137,7 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with id given on a submit button" do
|
||||
it "should submit the associated form" do
|
||||
@session.click_button('awe123')
|
||||
|
@ -161,17 +161,17 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
extract_results(@session)['first_name'].should == 'John'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with fields associated with the form using the form attribute" do
|
||||
before do
|
||||
@session.click_button('submit_form1')
|
||||
@results = extract_results(@session)
|
||||
end
|
||||
|
||||
|
||||
it "should serialize and submit text fields" do
|
||||
@results['outside_input'].should == 'outside_input'
|
||||
end
|
||||
|
||||
|
||||
it "should serialize text areas" do
|
||||
@results['outside_textarea'].should == 'Some text here'
|
||||
end
|
||||
|
@ -179,23 +179,23 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
it "should serialize select tags" do
|
||||
@results['outside_select'].should == 'Ruby'
|
||||
end
|
||||
|
||||
|
||||
it "should not serliaze fields associated with a different form" do
|
||||
@results['for_form2'].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
context "with submit button outside the form defined by <button> tag" do
|
||||
before do
|
||||
@session.click_button('outside_button')
|
||||
@results = extract_results(@session)
|
||||
end
|
||||
|
||||
|
||||
it "should submit the associated form" do
|
||||
@results['which_form'].should == 'form2'
|
||||
end
|
||||
|
||||
|
||||
it "should submit the button that was clicked, but not other buttons" do
|
||||
@results['outside_button'].should == 'outside_button'
|
||||
@results['unused'].should be_nil
|
||||
|
@ -207,24 +207,24 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
@session.click_button('outside_submit')
|
||||
@results = extract_results(@session)
|
||||
end
|
||||
|
||||
|
||||
it "should submit the associated form" do
|
||||
@results['which_form'].should == 'form1'
|
||||
end
|
||||
|
||||
|
||||
it "should submit the button that was clicked, but not other buttons" do
|
||||
@results['outside_submit'].should == 'outside_submit'
|
||||
@results['submit_form1'].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with submit button for form1 located within form2" do
|
||||
it "should submit the form associated with the button" do
|
||||
@session.click_button('other_form_button')
|
||||
extract_results(@session)['which_form'].should == "form1"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with alt given on an image button" do
|
||||
it "should submit the associated form" do
|
||||
@session.click_button('oh hai thar')
|
||||
|
@ -395,4 +395,17 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
addresses[1]["city"].should == 'Mikolaiv'
|
||||
addresses[1]["country"].should == 'Ukraine'
|
||||
end
|
||||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.click_button('What an Awesome', :exact => false)
|
||||
extract_results(@session)['first_name'].should == 'John'
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.click_button('What an Awesome', :exact => true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue