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

Added click_link with id

This commit is contained in:
Jonas Nicklas 2009-11-05 00:42:13 +01:00
parent dcfa90ce4a
commit 233f9fbbd5
4 changed files with 24 additions and 2 deletions

View file

@ -16,6 +16,10 @@ class Webcat::Driver::Culerity
end end
return value if value and not value.empty? return value if value and not value.empty?
end end
def click
node.click
end
end end
attr_reader :app, :rack_server attr_reader :app, :rack_server

View file

@ -2,7 +2,7 @@ require 'rack/test'
require 'nokogiri' require 'nokogiri'
class Webcat::Driver::RackTest class Webcat::Driver::RackTest
class Node < Struct.new(:node) class Node < Struct.new(:session, :node)
def text def text
node.text node.text
end end
@ -11,6 +11,10 @@ class Webcat::Driver::RackTest
value = node.attributes[name.to_s] value = node.attributes[name.to_s]
return value.to_s if value return value.to_s if value
end end
def click
session.visit(attribute(:href))
end
end end
include ::Rack::Test::Methods include ::Rack::Test::Methods
@ -32,7 +36,7 @@ class Webcat::Driver::RackTest
end end
def find(selector) def find(selector)
html.xpath(selector).map { |node| Node.new(node) } html.xpath(selector).map { |node| Node.new(self, node) }
end end
private private

View file

@ -21,6 +21,10 @@ class Webcat::Session
driver.visit(path) driver.visit(path)
end end
def click_link(locator)
driver.find("//a[@id='#{locator}']").first.click
end
def body def body
driver.body driver.body
end end

View file

@ -16,6 +16,16 @@ describe Webcat::Session do
@session.body.should == 'Another World' @session.body.should == 'Another World'
end end
end end
describe '#click_link' do
context "with id given" do
it "should take user to the linked page" do
@session.visit('/with_html')
@session.click_link('foo')
@session.body.should == 'Another World'
end
end
end
end end
context 'with rack test driver' do context 'with rack test driver' do