diff --git a/lib/webcat/culerity_driver.rb b/lib/webcat/culerity_driver.rb index 644112aa..92aa3725 100644 --- a/lib/webcat/culerity_driver.rb +++ b/lib/webcat/culerity_driver.rb @@ -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 diff --git a/lib/webcat/rack_test_driver.rb b/lib/webcat/rack_test_driver.rb index 5376b428..85d68fcf 100644 --- a/lib/webcat/rack_test_driver.rb +++ b/lib/webcat/rack_test_driver.rb @@ -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 diff --git a/lib/webcat/session.rb b/lib/webcat/session.rb index 5be3b166..0921820f 100644 --- a/lib/webcat/session.rb +++ b/lib/webcat/session.rb @@ -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 diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 9e361e76..53772528 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -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