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
return value if value and not value.empty?
end
def click
node.click
end
end
attr_reader :app, :rack_server

View file

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

View file

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

View file

@ -16,6 +16,16 @@ describe Webcat::Session do
@session.body.should == 'Another World'
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
context 'with rack test driver' do