mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
change node and driver api to use find_xpath and find_css
This commit is contained in:
parent
5ff2e65680
commit
eba8eaba40
8 changed files with 39 additions and 23 deletions
|
@ -7,7 +7,11 @@ class Capybara::Driver::Base
|
|||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def find(query_format=:xpath, query)
|
||||
def find_xpath(query)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def find_css(query)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -147,9 +147,9 @@ module Capybara
|
|||
elements = synchronize do
|
||||
# base.find(query.xpath(exact)).map do |node|
|
||||
if query.selector.preferred_format==:css
|
||||
base.find(:css, query.css)
|
||||
base.find_css(query.css)
|
||||
else
|
||||
base.find(:xpath, query.xpath(exact))
|
||||
base.find_xpath(query.xpath(exact))
|
||||
end.map do |node|
|
||||
Capybara::Node::Element.new(session, node, self, query)
|
||||
end
|
||||
|
|
|
@ -80,7 +80,7 @@ class Capybara::RackTest::Browser
|
|||
@dom ||= Nokogiri::HTML(html)
|
||||
end
|
||||
|
||||
def find(format=:xpath, selector)
|
||||
def find(format, selector)
|
||||
if format==:css
|
||||
dom.css(selector, Capybara::RackTest::CSSHandlers.new)
|
||||
else
|
||||
|
|
|
@ -62,8 +62,12 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
|
|||
response.status
|
||||
end
|
||||
|
||||
def find(format=:xpath, selector)
|
||||
browser.find(format, selector)
|
||||
def find_xpath(selector)
|
||||
browser.find(:xpath, selector)
|
||||
end
|
||||
|
||||
def find_css(selector)
|
||||
browser.find(:css,selector)
|
||||
end
|
||||
|
||||
def html
|
||||
|
|
|
@ -29,7 +29,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|||
|
||||
def select_option
|
||||
if select_node['multiple'] != 'multiple'
|
||||
select_node.find(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
|
||||
select_node.find_xpath(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
|
||||
end
|
||||
native["selected"] = 'selected'
|
||||
end
|
||||
|
@ -76,14 +76,14 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|||
native.path
|
||||
end
|
||||
|
||||
def find(format=:xpath, locator)
|
||||
if format==:css
|
||||
native.css(locator, Capybara::RackTest::CSSHandlers.new)
|
||||
else
|
||||
native.xpath(locator)
|
||||
end.map { |n| self.class.new(driver, n) }
|
||||
def find_xpath(locator)
|
||||
native.xpath(locator).map { |n| self.class.new(driver, n) }
|
||||
end
|
||||
|
||||
|
||||
def find_css(locator)
|
||||
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
native == other.native
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ private
|
|||
|
||||
# a reference to the select node if this is an option node
|
||||
def select_node
|
||||
find('./ancestor::select').first
|
||||
find_xpath('./ancestor::select').first
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
@ -46,8 +46,12 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
browser.current_url
|
||||
end
|
||||
|
||||
def find(selector_format=:xpath, selector)
|
||||
browser.find_elements(selector_format, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
|
||||
def find_xpath(selector)
|
||||
browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
|
||||
end
|
||||
|
||||
def find_css(selector)
|
||||
browser.find_elements(:css, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
|
||||
end
|
||||
|
||||
def wait?; true; end
|
||||
|
|
|
@ -76,10 +76,14 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
|
||||
alias :checked? :selected?
|
||||
|
||||
def find(locator_format=:xpath, locator)
|
||||
native.find_elements(locator_format, locator).map { |n| self.class.new(driver, n) }
|
||||
def find_xpath(locator)
|
||||
native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
|
||||
end
|
||||
|
||||
|
||||
def find_css(locator)
|
||||
native.find_elements(:css, locator).map { |n| self.class.new(driver, n) }
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
native == other.native
|
||||
end
|
||||
|
@ -88,6 +92,6 @@ private
|
|||
|
||||
# a reference to the select node if this is an option node
|
||||
def select_node
|
||||
find('./ancestor::select').first
|
||||
find_xpath('./ancestor::select').first
|
||||
end
|
||||
end
|
||||
|
|
|
@ -84,14 +84,14 @@ describe Capybara::RackTest::Driver do
|
|||
it 'should keep headers on link clicks' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//a').first.click
|
||||
@driver.find_xpath('.//a').first.click
|
||||
@driver.html.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on form submit' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//input').first.click
|
||||
@driver.find_xpath('.//input').first.click
|
||||
@driver.html.should include('foobar')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue