diff --git a/lib/webcat/session.rb b/lib/webcat/session.rb index a8a3af5e..da7909a4 100644 --- a/lib/webcat/session.rb +++ b/lib/webcat/session.rb @@ -80,6 +80,7 @@ class Webcat::Session end def within(scope) + raise Webcat::ElementNotFound, "scope '#{scope}' not found on page" if find(scope).empty? scopes.push(scope) yield scopes.pop diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 10ace932..42a57ab0 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -482,6 +482,13 @@ shared_examples_for "session" do @session.body.should include('Hello world') end end + + it "should raise an error if the scope is not found on the page" do + running { + @session.within("//div[@id='doesnotexist']") do + end + }.should raise_error(Webcat::ElementNotFound) + end end context "with forms" do