2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec "#fill_in" do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a text field by name" do
|
|
|
|
@session.fill_in('form[last_name]', :with => 'Green')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['last_name'].should == 'Green'
|
|
|
|
end
|
2009-12-27 03:11:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a text field by label without for" do
|
|
|
|
@session.fill_in('First Name', :with => 'Harry')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['first_name'].should == 'Harry'
|
|
|
|
end
|
2009-12-27 03:11:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a url field by label without for" do
|
|
|
|
@session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
|
|
|
|
@session.click_button('html5_submit')
|
|
|
|
extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
|
|
|
|
end
|
2010-06-29 15:58:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a field with a custom type" do
|
|
|
|
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['schmooo'].should == 'Schmooo is the game'
|
|
|
|
end
|
2010-03-12 14:11:21 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a field without a type" do
|
|
|
|
@session.fill_in('Phone', :with => '+1 555 7022')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['phone'].should == '+1 555 7022'
|
|
|
|
end
|
2010-05-20 07:43:16 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fill in a text field respecting its maxlength attribute" do
|
|
|
|
@session.fill_in('Zipcode', :with => '52071350')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['zipcode'].should == '52071'
|
|
|
|
end
|
2011-02-20 14:23:11 -05:00
|
|
|
|
2012-07-21 16:44:10 -04: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
|
2010-03-12 14:11:21 -05:00
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
2012-07-21 16:44:10 -04: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 throw an exception if a hash containing 'with' is not provided" do
|
|
|
|
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
|
|
|
end
|
2012-01-31 10:20:35 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should wait for asynchronous load", :requires => [:js] do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
|
|
|
@session.fill_in('new_field', :with => 'Testing...')
|
|
|
|
end
|
|
|
|
|
2012-09-06 03:33:43 -04:00
|
|
|
it "casts to string" do
|
|
|
|
@session.fill_in(:'form_first_name', :with => :'Harry')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['first_name'].should == 'Harry'
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
|
|
|
|
it 'should only trigger onchange once' do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.fill_in('with_change_event', :with => 'some value')
|
|
|
|
@session.find(:css, '#with_change_event').value.should == 'some value'
|
2010-04-21 17:55:33 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-01-31 10:20:35 -05:00
|
|
|
|
2012-07-21 16:44:10 -04: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
|
|
|
|
msg = "Unable to find field \"Super Secret\""
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.fill_in('Super Secret', :with => '777')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
2010-01-30 13:48:25 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-01-30 13:48:25 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
msg = "Unable to find field \"does not exist\""
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.fill_in('does not exist', :with => 'Blah blah')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
end
|
2012-09-09 11:18:03 -04:00
|
|
|
|
|
|
|
context "on a disabled field" do
|
|
|
|
it "should raise an error" do
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-09-09 11:18:03 -04:00
|
|
|
@session.fill_in('Disabled Text Field', :with => 'Blah blah')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2012-09-09 11:18:03 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-24 10:41:20 -05:00
|
|
|
|
|
|
|
context "with :exact option" do
|
|
|
|
it "should accept partial matches when false" do
|
|
|
|
@session.fill_in("Explanation", :with => "Dude", :exact => false)
|
|
|
|
@session.click_button("awesome")
|
|
|
|
extract_results(@session)["name_explanation"].should == "Dude"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not accept partial matches when true" do
|
|
|
|
expect do
|
|
|
|
@session.fill_in("Explanation", :with => "Dude", :exact => true)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|