From 881d9f388d3bc3775ad84564a2568559e7e33b82 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 2 Dec 2008 22:13:13 -0500 Subject: [PATCH] Adding have_xpath matcher for Selenium --- lib/webrat/selenium/matchers.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index 59bb529..a3d38f8 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -2,6 +2,34 @@ module Webrat module Selenium module Matchers + class HaveXpath + def initialize(expected) + @expected = expected + end + + def matches?(response) + response.session.wait_for do + response.selenium.is_element_present("xpath=#{@expected}") + end + end + + # ==== Returns + # String:: The failure message. + def failure_message + "expected following text to match xpath #{@expected}:\n#{@document}" + end + + # ==== Returns + # String:: The failure message to be displayed in negative matches. + def negative_failure_message + "expected following text to not match xpath #{@expected}:\n#{@document}" + end + end + + def have_xpath(xpath) + HaveXpath.new(xpath) + end + class HaveSelector def initialize(expected) @expected = expected