2010-01-18 14:33:22 -05:00
|
|
|
shared_examples_for "fill_in" do
|
|
|
|
describe "#fill_in" do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a text field by id" do
|
|
|
|
@session.fill_in('form_first_name', :with => 'Harry')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['first_name'].should == 'Harry'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a text field by name" do
|
2010-01-30 13:48:25 -05:00
|
|
|
@session.fill_in('form[last_name]', :with => 'Green')
|
2010-01-18 14:33:22 -05:00
|
|
|
@session.click_button('awesome')
|
2010-01-30 13:48:25 -05:00
|
|
|
extract_results(@session)['last_name'].should == 'Green'
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2009-12-27 03:11:22 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a text field by label without for" do
|
|
|
|
@session.fill_in('Street', :with => 'Avenue Q')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['street'].should == 'Avenue Q'
|
|
|
|
end
|
2009-12-27 03:11:22 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should favour exact label matches over partial matches" do
|
|
|
|
@session.fill_in('Name', :with => 'Harry Jones')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['name'].should == 'Harry Jones'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a textarea by id" do
|
|
|
|
@session.fill_in('form_description', :with => 'Texty text')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['description'].should == 'Texty text'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a textarea by label" do
|
|
|
|
@session.fill_in('Description', :with => 'Texty text')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['description'].should == 'Texty text'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a textarea by name" do
|
|
|
|
@session.fill_in('form[description]', :with => 'Texty text')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['description'].should == 'Texty text'
|
|
|
|
end
|
2009-12-27 03:11:22 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a password field by id" do
|
|
|
|
@session.fill_in('form_password', :with => 'supasikrit')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['password'].should == 'supasikrit'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-03-12 14:11:21 -05:00
|
|
|
it "should fill in a field with a custom type" do
|
2010-03-22 19:43:55 -04:00
|
|
|
pending "selenium doesn't seem to find custom fields" if @session.mode == :selenium
|
2010-03-12 14:11:21 -05:00
|
|
|
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['schmooo'].should == 'Schmooo is the game'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should fill in a password field by name" do
|
|
|
|
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['password'].should == 'supasikrit'
|
|
|
|
end
|
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a password field by label" do
|
|
|
|
@session.fill_in('Password', :with => 'supasikrit')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['password'].should == 'supasikrit'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should fill in a password field by name" do
|
|
|
|
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['password'].should == 'supasikrit'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prefer exact matches over partial matches" do
|
|
|
|
@session.fill_in('Name', :with => 'Ford Prefect')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['name'].should == 'Ford Prefect'
|
|
|
|
end
|
2010-04-21 17:55:33 -04:00
|
|
|
|
|
|
|
it "should throw an exception if a hash containing 'with' is not provided" do
|
|
|
|
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
|
|
|
end
|
|
|
|
|
2010-01-30 13:48:25 -05:00
|
|
|
context "with ignore_hidden_fields" do
|
|
|
|
before { Capybara.ignore_hidden_elements = true }
|
|
|
|
after { Capybara.ignore_hidden_elements = false }
|
|
|
|
it "should not find a hidden field" do
|
|
|
|
running do
|
|
|
|
@session.fill_in('Super Secret', :with => '777')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
running do
|
|
|
|
@session.fill_in('does not exist', :with => 'Blah blah')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound)
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|