1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/dsl/all_spec.rb
Jonas Nicklas 05fd0d3f06 selector as first argument to find/all, Closes #28
Just as with within, the default is changed by
setting Capybara.default_selector.
2010-01-17 19:02:25 +01:00

61 lines
2.1 KiB
Ruby

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
context "with css selectors" do
it "should find the first element using the given locator" do
@session.all(:css, 'h1').first.text.should == 'This is a test'
@session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.all('h1').first.text.should == 'This is a test'
@session.all("input[id='test_field']").first[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should return an empty array when nothing was found" do
@session.all('//div[@id="nosuchthing"]').should be_empty
end
it "should accept an XPath instance" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@result = @session.all(@xpath).map { |r| r.value }
@result.should include('Smith', 'John', 'John Smith')
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