From feb29e2d644ec00665a39123b4d771aa6fe1aaf0 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas and Kevin Fitzpatrick Date: Fri, 13 Nov 2009 21:33:40 +0100 Subject: [PATCH] Added has_content? to check for content on page --- lib/webcat/session.rb | 4 ++++ spec/session_spec.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/webcat/session.rb b/lib/webcat/session.rb index be8f4913..a0f0594c 100644 --- a/lib/webcat/session.rb +++ b/lib/webcat/session.rb @@ -60,6 +60,10 @@ class Webcat::Session def body driver.body end + + def has_content?(content) + driver.find("//*[contains(child::text(),'#{content}')]").size > 0 + end private diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 06d93682..1ffdc7be 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -280,6 +280,21 @@ shared_examples_for "session" do YAML.load(@session.body)['locale'].should == 'fi' end end + + describe '#has_content?' do + it "should be true if the given content is on the page at least once" do + @session.visit('/with_html') + @session.should have_content('est') + @session.should have_content('Lorem') + @session.should have_content('Redirect') + end + + it "should be false if the given content is not on the page" do + @session.visit('/with_html') + @session.should_not have_content('xxxxyzzz') + @session.should_not have_content('monkey') + end + end describe "#attach_file" do before do