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:
parent
dcfa90ce4a
commit
233f9fbbd5
4 changed files with 24 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -21,6 +21,10 @@ class Webcat::Session
|
|||
driver.visit(path)
|
||||
end
|
||||
|
||||
def click_link(locator)
|
||||
driver.find("//a[@id='#{locator}']").first.click
|
||||
end
|
||||
|
||||
def body
|
||||
driver.body
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue