2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#find_by_id' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
2009-12-29 22:05:38 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should find any element by id" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find_by_id('red').tag_name).to eq('a')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2009-12-29 22:05:38 -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_by_id(:'red').tag_name).to eq('a')
|
2012-09-06 03:33:43 -04:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should raise error if no element with id is found" do
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.find_by_id('nothing_with_this_id')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2009-12-29 22:05:38 -05:00
|
|
|
end
|
2013-02-24 11:47:53 -05:00
|
|
|
|
|
|
|
context "with :visible option" do
|
|
|
|
it "finds invisible elements when `false`" do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect(@session.find_by_id("hidden_via_ancestor", visible: false).text(:all)).to match(/with hidden ancestor/)
|
2013-02-24 11:47:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "finds invisible elements when `false`" do
|
|
|
|
expect do
|
2016-10-04 14:10:29 -04:00
|
|
|
@session.find_by_id("hidden_via_ancestor", visible: true)
|
2013-02-24 11:47:53 -05:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|