background image
<< Exceptions - Using do...except | Exceptions - Adding to the default error handling >>
Exceptions - Performing more than one verification in a testcase
<< Exceptions - Using do...except | Exceptions - Adding to the default error handling >>
User's Guide
211
9 H
ANDLING
E
XCEPTIONS
Performing more than one verification in a testcase
Consider this simple testcase:
testcase except1 (STRING sExpectedVal, STRING sActualVal)
do
Verify (sExpectedVal, sActualVal)
Print ("Verification succeeded")
except
Print ("Verification failed")
This testcase uses the built-in function Verify, which generates an exception
if its two arguments are not equivalent. In this testcase, if sExpectedVal
equals sActualVal, no exception is raised, "Verification succeeded" is printed,
and the testcase terminates. If the two values are not equal, Verify raises an
exception, control immediately passes to the except clause (the first Print
statement is not executed), and "Verification failed" is printed.
Here is the result if the two values "one" and "two" are passed to the testcase:
Testcase except1 ("one", "two") - Passed
Verification failed
Note that testcase passes and the recovery system is not called, because you
handled the error yourself. (In "Adding to the default error handling" on
page 212, y
ou will learn how you can handle the error yourself and call the
recovery system too.)
You handle the error in the except clause. You can include any 4Test
statements, so you could, for example, choose to ignore the error, write
information to a separate log file, log the error in the results file, and so on.
The following sections describe some typical uses of do...except.
Performing more than one verification in a testcase
Usually, testcases have only one verification statement. If the verification
fails, an exception is raised and the testcase terminates. But sometimes for
ease of maintenance, you might want to have more than one verification
statement in a testcase. Consider the following:
testcase MultiVerify ()
TextEditor.Search.Find.Pick ()
Find.VerifyCaption ("Find")
Find.VerifyFocus (Find.FindWhat)
Find.VerifyEnabled (TRUE)
Find.Cancel.Click ()