All drivers now support relative searching

There is a bug in Selenium, which causes it to
find only descendant nodes, even when asked for
a global search. Bug filed here:

http://code.google.com/p/selenium/issues/detail?id=403
This commit is contained in:
Jonas Nicklas 2010-02-26 18:38:22 +01:00
parent 20e32d9d4a
commit 9a19b758ca
7 changed files with 36 additions and 35 deletions

View File

@ -77,6 +77,14 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
node.fire_event(event.to_s)
end
private
def all_unfiltered(locator)
noko_node = Nokogiri::HTML(driver.body).xpath(node.xpath).first
all_nodes = noko_node.xpath(locator).map { |n| n.path }.join(' | ')
driver.find(all_nodes)
end
end
attr_reader :app, :rack_server

View File

@ -94,6 +94,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
private
def all_unfiltered(locator)
node.xpath(locator).map { |n| self.class.new(driver, n) }
end
def type
node[:type]
end

View File

@ -78,6 +78,10 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
private
def all_unfiltered(locator)
node.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
end
def type
self[:type]
end

View File

@ -8,6 +8,5 @@ describe Capybara::Driver::Culerity do
it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"
it_should_behave_like "driver with header support"
it_should_behave_like "driver with node path support"
end

View File

@ -7,6 +7,5 @@ describe Capybara::Driver::RackTest do
it_should_behave_like "driver"
it_should_behave_like "driver with header support"
it_should_behave_like "driver with node path support"
end

View File

@ -7,6 +7,5 @@ describe Capybara::Driver::Selenium do
it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"
it_should_behave_like "driver without node path support"
end

View File

@ -72,6 +72,26 @@ shared_examples_for 'driver' do
end
end
describe "node relative searching" do
before do
@driver.visit('/tables')
@node = @driver.find('//body').first
end
it "should be able to navigate/search child node" do
@node.all('//table').size.should == 5
@node.find('//form').all('.//table').size.should == 1
@node.find('//form').find('.//table//caption').text.should == 'Agent'
if @driver.class == Capybara::Driver::Selenium
pending("Selenium gets this wrong, see http://code.google.com/p/selenium/issues/detail?id=403") do
@node.find('//form').all('//table').size.should == 5
end
else
@node.find('//form').all('//table').size.should == 5
end
end
end
end
shared_examples_for "driver with javascript support" do
@ -97,7 +117,6 @@ shared_examples_for "driver with javascript support" do
@driver.evaluate_script('1+1').should == 2
end
end
end
shared_examples_for "driver with header support" do
@ -106,34 +125,3 @@ shared_examples_for "driver with header support" do
@driver.response_headers['Content-Type'].should == 'text/html'
end
end
shared_examples_for "driver with node path support" do
describe "node relative searching" do
before do
@driver.visit('/tables')
@node = @driver.find('//body').first
end
it "should be able to navigate/search child nodes" do
@node.all('//table').size.should == 5
@node.find('//form').all('//table').size.should == 1
@node.find('//form').find('//table//caption').text.should == 'Agent'
end
end
end
shared_examples_for "driver without node path support" do
describe "node relative searching" do
before do
@driver.visit('/tables')
@node = @driver.find('//body').first
end
it "should get NotSupportedByDriverError" do
running do
@node.all('//form')
end.should raise_error(Capybara::NotSupportedByDriverError)
end
end
end