background image
<< Exceptions - Performing more than one verification in a testcase | Exceptions - the GetSelText method >>
Exceptions - Adding to the default error handling
<< Exceptions - Performing more than one verification in a testcase | Exceptions - the GetSelText method >>
212
User's Guide
9 H
ANDLING
E
XCEPTIONS
Adding to the default error handling
That testcase contains three verification statements. However, if, for example,
the first verification (VerifyCaption) fails, an exception is raised and the
testcase terminates. The second and third verifications never happen.
To verify more than one thing in a testcase, you can trap all but the last one in
a do...except statement, such as:
testcase MultiVerify2 ()
TextEditor.Search.Find.Pick ()
do
Find.VerifyCaption ("Find")
except
ExceptLog ()
do
Find.VerifyFocus (Find.FindWhat)
except
ExceptLog ()
Find.VerifyEnabled (TRUE)
Find.Cancel.Click ()
Here, all the verifications will happen each time the testcase is run. If either
of the first two fails, the 4Test function ExceptLog is called. That function
logs the error information in the results file, then continues execution of the
script.
Adding to the default error handling
You can also use do...except to perform some custom error handling, then
use the reraise statement to pass control to the recovery system as usual.
Consider this situation: The Text Editor application displays a message box if
a user searches for text that doesn't exist in the document. So you can create a
data-driven testcase that verifies that the message box appears and has the
correct message. (That testcase is shown in "Testing an application with
invalid data" on page 193.)
But suppose you want to determine if the Text
Editor application is finding false matches, that is, if it is selecting text in the
document before displaying the message box. That means that you want to do
some testing after the exception is raised, instead of immediately passing
control to the recovery system, as shown in this example:
testcase Negative (SEARCHINFO Data)
STRING sMatch
TextEditor.File.New.Pick ()
DocumentWindow.Document.TypeKeys (Data.sText + Data.sPos)
TextEditor.Search.Find.Pick ()
Find.FindWhat.SetText (Data.sPattern)