2009-12-15 14:58:51 -05:00
|
|
|
module AllSpec
|
|
|
|
shared_examples_for "all" do
|
|
|
|
describe '#all' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should find all elements using the given locator" do
|
|
|
|
@session.all('//p').should have(3).elements
|
|
|
|
@session.all('//h1').first.text.should == 'This is a test'
|
|
|
|
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return an empty array when nothing was found" do
|
2009-12-22 18:14:04 -05:00
|
|
|
@session.all('//div[@id="nosuchthing"]').should be_empty
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should accept an XPath instance" do
|
|
|
|
@session.visit('/form')
|
|
|
|
@xpath = Capybara::XPath.text_field('Name')
|
2009-12-19 05:37:04 -05:00
|
|
|
@result = @session.all(@xpath).map { |r| r.value }
|
|
|
|
@result.should include('Smith', 'John', 'John Smith')
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "within a scope" do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_scope')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should find any element using the given locator" do
|
|
|
|
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
|
|
@session.all('//li').should have(2).elements
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|