[Wtr-general] OT: Need help Trapping Errors in Ruby

Paul Carvalho tester.paul at gmail.com
Wed Jan 10 15:10:07 EST 2007


Hi there, I've got more of a Ruby question than a Watir one, so I hope you
don't mind if I post it here first.

I am in the process of rewriting my first Ruby/Watir scripts from a year ago
- a site-map walkthrough script to collect some simple Performance metrics.
When I first wrote the script, I used the Test/Unit (Class/Test) structure
because that was the only way I knew how to structure scripts at that time.
(i.e. used the Watir examples as a guide.)

A year later, I now know how to structure my scripts in a more regular Ruby
script fashion so I updated my walkthrough script.  I used a neat trick in
my old script to recover from a script error (e.g. assertion failure) and
continue on but I seem to be having some problems doing the same thing with
the Ruby script format.  I was wondering if someone can offer any advice to
help me figure this out.

Here's what I've got so far:

## Main script snippet:
  ...
  # open the IE browser
  $ie = IE.new

  # A) Walk the Public Pages.  => Need to Trap this so the
"something_went_wrong" variable works correctly
  page_set_to_check( walk_Public_Pages )

----

# Here's the page_set_to_check() method:

module site_walkabout_methods

  def page_set_to_check( page_set )
      begin
          page_set
      rescue => e
          $something_went_wrong = 'Yes'
      end
      write_status
  end

end
----

So, the "walk_Public_Pages" routine gets called, but if there's an assertion
failure in it (e.g. because of an incorrect link name), the "rescue => e"
part of page_set_to_check() doesn't run like I would expect it to.  In fact,
the whole script terminates at this point!

Please let me know if you have any helpful suggestions to get the script to
auto-recover and continue.

Thanks.  Paul C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20070110/8a6caa75/attachment-0001.html 


More information about the Wtr-general mailing list