2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#find_field' 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 find any field" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find_field('Dog').value).to eq('dog')
|
|
|
|
expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
|
|
|
|
expect(@session.find_field('Region')[:name]).to eq('form[region]')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-09-06 03:33:43 -04:00
|
|
|
it "casts to string" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find_field(:'Dog').value).to eq('dog')
|
2012-09-06 03:33:43 -04:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should raise error if the field doesn't exist" do
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.find_field('Does not exist')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2014-07-02 14:17:53 -04:00
|
|
|
it "should warn if filter option is invalid" do
|
|
|
|
expect_any_instance_of(Kernel).to receive(:warn).
|
2015-09-19 14:42:45 -04:00
|
|
|
with('Invalid value nil passed to filter disabled - defaulting to false')
|
2014-07-02 14:17:53 -04:00
|
|
|
@session.find_field('Dog', disabled: nil)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be aliased as 'field_labeled' for webrat compatibility" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.field_labeled('Dog').value).to eq('dog')
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.field_labeled('Does not exist')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2013-02-24 11:47:53 -05:00
|
|
|
|
|
|
|
context "with :exact option" do
|
|
|
|
it "should accept partial matches when false" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find_field("Explanation", :exact => false)[:name]).to eq("form[name_explanation]")
|
2013-02-24 11:47:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not accept partial matches when true" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Explanation", :exact => true)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2013-03-08 08:18:56 -05:00
|
|
|
|
|
|
|
context "with :disabled option" do
|
|
|
|
it "should find disabled fields when true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find_field("Disabled Checkbox", :disabled => true)[:name]).to eq("form[disabled_checkbox]")
|
2013-03-08 08:18:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find disabled fields when false" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Disabled Checkbox", :disabled => false)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find disabled fields by default" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Disabled Checkbox")
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
2015-09-18 23:22:19 -04:00
|
|
|
|
|
|
|
it "should find disabled fields when :all" do
|
|
|
|
expect(@session.find_field("Disabled Checkbox", :disabled => :all)[:name]).to eq("form[disabled_checkbox]")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should find enabled fields when :all" do
|
|
|
|
expect(@session.find_field('Dog', :disabled => :all).value).to eq('dog')
|
|
|
|
end
|
2013-03-08 08:18:56 -05:00
|
|
|
end
|
2015-08-25 17:25:42 -04:00
|
|
|
|
|
|
|
context 'with :readonly option' do
|
|
|
|
it "should find readonly fields when true" do
|
|
|
|
expect(@session.find_field('form[readonly_test]', readonly: true)[:id]).to eq 'readonly'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find readonly fields when false" do
|
|
|
|
expect(@session.find_field('form[readonly_test]', readonly: false)[:id]).to eq 'not_readonly'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should ignore readonly by default" do
|
|
|
|
expect do
|
|
|
|
@session.find_field('form[readonly_test]')
|
|
|
|
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
|
|
|
|
end
|
|
|
|
end
|
2016-04-13 16:50:37 -04:00
|
|
|
|
2016-04-26 11:51:22 -04:00
|
|
|
context 'with no locator' do
|
2016-04-13 16:50:37 -04:00
|
|
|
it 'should use options to find the field' do
|
|
|
|
expect(@session.find_field(with: 'dog')['id']).to eq "form_pets_dog"
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|