1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Added custom selectors

This commit is contained in:
Jonas Nicklas 2010-08-18 03:22:54 +02:00
parent 8c534e4b70
commit 064ecda28d
4 changed files with 25 additions and 2 deletions

View file

@ -45,6 +45,14 @@ module Capybara
def configure
yield self
end
def add_selector(name, &block)
selectors[name.to_sym] = block
end
def selectors
@selectors ||= {}
end
end
autoload :Server, 'capybara/server'
@ -70,3 +78,6 @@ Capybara.configure do |config|
config.default_wait_time = 2
config.ignore_hidden_elements = false
end
Capybara.add_selector(:xpath) { |xpath| xpath }
Capybara.add_selector(:css) { |css| XPath::HTML.from_css(css) }

View file

@ -142,8 +142,7 @@ module Capybara
def normalize_locator(kind, locator=nil)
kind, locator = Capybara.default_selector, kind if locator.nil?
locator = XPath::HTML.from_css(locator) if kind == :css
locator
Capybara.selectors[kind.to_sym].call(locator)
end
def wait_conditionally_until

View file

@ -49,6 +49,14 @@ shared_examples_for "find" do
end
end
context "with custom selector" do
it "should use the custom selector" do
Capybara.add_selector(:monkey) { |name| ".//*[@id='#{name}_monkey']" }
@session.find(:monkey, 'john').text.should == 'Monkey John'
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
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

View file

@ -41,3 +41,8 @@
<div id="hidden_via_ancestor">Inside element with hidden ancestor</div>
<a href="/with_simple_html" title="awesome title" class="simple">hidden link</a>
</div>
<ul>
<li id="john_monkey">Monkey John</li>
<li id="paul_monkey">Monkey Paul</li>
</ul>