I need to learn how to handle Watir exceptions, so i've been searching
and couldn't find a good tutorial about it (with specific examples for
Watir.) . Does anyone have worked with this before ??
Can anyone please give me some good resources or a brief
explanation?
Thanks
Sorry for not been specific but I'm starting with this of
posting... :P
I' ve read about begin/rescue clauses also raise and ensure, but I saw
different examples in which rescue is inside the begin block and
others that put it outside the block, the same for raise. And i wanted
to know which are the best practices to handle exceptions (Watir
esceptions).
I found a list of Watir exceptions in this page:
http://wtr.rubyforge.org/rdoc/classes/Watir/Exception.html
And i would like to know which are the most used...?
I'm starting to automate some test cases.. so I wrote a personal
library (very simple) that encapsulate most of watir events I used on
my test cases something like this:
def ClickButtonByName(sButtonName)
if ($ie.button(:name, sButtonName).exists?)
$ie.button(:name, sButtonName).click
$log.WritePassed("Click on: '#{sButtonName}' Button", "Done")
else
$log.WriteFailed("Click on: '#{sButtonName}' Button", "Failed,
Button not Found")
end
end
So at the same time the actions are logged in another file. Then I
call this methods from another ruby file in order to create the test
cases. Now my question is where i should put the begin/rescue clauses?
for example what if the button doesn't exist how can I handle this
exception with begin/rescue?
I'll be very thankful if you can clarify my doubts
Daniella
On Nov 8, 4:59 pm, "Charley Baker" <charley.ba...@gmail.com> wrote:
> Depends on what you mean. General exception handling is documented in the
> Pickaxe ruby book and a basic ruby question. If you have specific questions
> then ask them. The brief answer would be wrap your code in begin/rescue
> clauses if that's what you truly mean to do.
>
> -Charley
>
WARNING. Once you start rescuing exceptions, you run the risk that your
tests will find problems that will not be reported. The only way to
mitigate this risk is to make sure that you have good unit tests for
your test harness (since that is what you are creating as soon as you
start rescuing exceptions). If you don't know how to unit test your
harness, you need to learn how to do that first before you start
rescuing exceptions.
Bret
--
Bret Pettichord
Lead Developer, Watir, http://wtr.rubyforge.org
Blog, http://www.io.com/~wazmo/blog
Then create your own supporting code for your test framework gradually as the need comes up. Unit tests for this layer are crucial and I'd highly recommend test driven or behavior driven development and only building what you need when you need it. A phrase that's probably been beaten to death which encapsulates this idea is building your framework out organically.
Charley