2010-01-18 14:33:22 -05:00
|
|
|
shared_examples_for "find" do
|
|
|
|
describe '#find' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should find the first element using the given locator" do
|
|
|
|
@session.find('//h1').text.should == 'This is a test'
|
|
|
|
@session.find("//input[@id='test_field']")[:value].should == 'monkey'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with css selectors" do
|
2009-12-15 14:58:51 -05:00
|
|
|
it "should find the first element using the given locator" do
|
2010-01-18 14:33:22 -05:00
|
|
|
@session.find(:css, 'h1').text.should == 'This is a test'
|
|
|
|
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
context "with xpath selectors" do
|
|
|
|
it "should find the first element using the given locator" do
|
|
|
|
@session.find(:xpath, '//h1').text.should == 'This is a test'
|
|
|
|
@session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
2010-01-17 12:41:38 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2010-01-17 12:41:38 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
context "with css as default selector" do
|
|
|
|
before { Capybara.default_selector = :css }
|
|
|
|
it "should find the first element using the given locator" do
|
|
|
|
@session.find('h1').text.should == 'This is a test'
|
|
|
|
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
2010-01-17 12:41:38 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
after { Capybara.default_selector = :xpath }
|
|
|
|
end
|
2010-01-17 12:41:38 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should return nil when nothing was found" do
|
|
|
|
@session.find('//div[@id="nosuchthing"]').should be_nil
|
|
|
|
end
|
2010-01-17 12:41:38 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should accept an XPath instance and respect the order of paths" do
|
|
|
|
@session.visit('/form')
|
|
|
|
@xpath = Capybara::XPath.text_field('Name')
|
|
|
|
@session.find(@xpath).value.should == 'John Smith'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
context "within a scope" do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_scope')
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
|
2010-01-18 14:33:22 -05:00
|
|
|
it "should find the first element using the given locator" do
|
|
|
|
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
|
|
@session.find('//li').text.should =~ /With Simple HTML/
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|