mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added node class and made driver's nodes inherit
This commit is contained in:
parent
a8789c612c
commit
c389a0c0d3
6 changed files with 49 additions and 12 deletions
|
@ -18,6 +18,7 @@ module Capybara
|
|||
|
||||
autoload :Server, 'capybara/server'
|
||||
autoload :Session, 'capybara/session'
|
||||
autoload :Node, 'capybara/node'
|
||||
|
||||
module Driver
|
||||
autoload :RackTest, 'capybara/driver/rack_test_driver'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'culerity'
|
||||
|
||||
class Capybara::Driver::Culerity
|
||||
class Node < Struct.new(:node)
|
||||
class Node < Capybara::Node
|
||||
def text
|
||||
node.text
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ class Capybara::Driver::Culerity
|
|||
end
|
||||
|
||||
def find(selector)
|
||||
browser.elements_by_xpath(selector).map { |node| Node.new(node) }
|
||||
browser.elements_by_xpath(selector).map { |node| Node.new(self, node) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rack/test'
|
|||
require 'nokogiri'
|
||||
|
||||
class Capybara::Driver::RackTest
|
||||
class Node < Struct.new(:session, :node)
|
||||
class Node < Capybara::Node
|
||||
def text
|
||||
node.text
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Capybara::Driver::RackTest
|
|||
if tag_name == 'input' and %w(text password hidden file).include?(type)
|
||||
node['value'] = value.to_s
|
||||
elsif tag_name == 'input' and type == 'radio'
|
||||
session.html.xpath("//input[@name='#{self[:name]}']").each { |node| node.remove_attribute("checked") }
|
||||
driver.html.xpath("//input[@name='#{self[:name]}']").each { |node| node.remove_attribute("checked") }
|
||||
node['checked'] = 'checked'
|
||||
elsif tag_name == 'input' and type == 'checkbox'
|
||||
if value
|
||||
|
@ -36,9 +36,9 @@ class Capybara::Driver::RackTest
|
|||
|
||||
def click
|
||||
if tag_name == 'a'
|
||||
session.visit(self[:href])
|
||||
driver.visit(self[:href])
|
||||
elsif tag_name == 'input' and %w(submit image).include?(type)
|
||||
Form.new(session, form).submit(self)
|
||||
Form.new(driver, form).submit(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,9 +100,9 @@ class Capybara::Driver::RackTest
|
|||
|
||||
def submit(button)
|
||||
if post?
|
||||
session.submit(node['action'].to_s, params(button))
|
||||
driver.submit(node['action'].to_s, params(button))
|
||||
else
|
||||
session.visit(node['action'].to_s + '?' + params(button))
|
||||
driver.visit(node['action'].to_s + '?' + params(button))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'selenium-webdriver'
|
||||
|
||||
class Capybara::Driver::Selenium
|
||||
class Node < Struct.new(:node)
|
||||
class Node < Capybara::Node
|
||||
def text
|
||||
node.text
|
||||
end
|
||||
|
@ -77,7 +77,7 @@ class Capybara::Driver::Selenium
|
|||
end
|
||||
|
||||
def find(selector)
|
||||
driver.find_elements(:xpath, selector).map { |node| Node.new(node) }
|
||||
driver.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
36
lib/capybara/node.rb
Normal file
36
lib/capybara/node.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
class Capybara::Node
|
||||
attr_reader :driver, :node
|
||||
|
||||
def initialize(driver, node)
|
||||
@driver = driver
|
||||
@node = node
|
||||
end
|
||||
|
||||
def text
|
||||
raise "Not implemented"
|
||||
end
|
||||
|
||||
def [](name)
|
||||
raise "Not implemented"
|
||||
end
|
||||
|
||||
def value
|
||||
self[:value]
|
||||
end
|
||||
|
||||
def set(value)
|
||||
raise "Not implemented"
|
||||
end
|
||||
|
||||
def select(option)
|
||||
raise "Not implemented"
|
||||
end
|
||||
|
||||
def click
|
||||
raise "Not implemented"
|
||||
end
|
||||
|
||||
def tag_name
|
||||
raise "Not implemented"
|
||||
end
|
||||
end
|
|
@ -47,9 +47,9 @@ shared_examples_for 'driver' do
|
|||
end
|
||||
|
||||
it "should allow assignment of field value" do
|
||||
@driver.find('//input').first[:value].should == 'monkey'
|
||||
@driver.find('//input').first.value.should == 'monkey'
|
||||
@driver.find('//input').first.set('gorilla')
|
||||
@driver.find('//input').first[:value].should == 'gorilla'
|
||||
@driver.find('//input').first.value.should == 'gorilla'
|
||||
end
|
||||
|
||||
it "should extract node tag name" do
|
||||
|
|
Loading…
Reference in a new issue