preload

WinRunner to QTP migration notes (4)

Posted by Albert Gareev on Dec 04, 2008 | Categories: NotesTools

Error Handling

In WinRunner, every GUI function returns result – an integer value. Checking status of an operation is as simple as single line:


 rc = edit_set(edit,value);
 if (rc != E_OK) {
  #operation failed
  return(rc);   
  }

In QTP, most of GUI operations do not return code but execution stops if an error is encountered. To keep execution flow stable, errors have to be handled in a bit more sophisticated way:


 On Error Resume Next
   objName.Set sValue
   intRC = Err.Number
 On Error GoTo 0
 If intRC <> 0 Then boolRC = False

 If Not boolRC Then
   'operation failed
   Exit Function
 End If 

Exception Handling

I don’t know why Mercury team mixed up terms “exception” and “event”. Probably, to make it more simplified for testers without any knowledge of programming. As the result, both run-time exceptions and GUI events are defined as “exceptions”.

Exceptions are hooked to specific TSL functions and error codes:


define_tsl_exception("on_wb_List_Error1", "wb_on_List_Error", E_ANY_ERROR, "list_select_item");
#

public function wb_on_List_Error() {
 #recovery code

}

With QTP, the “tradition” deepened: now developers have to define Exception (or Event) and Handler function ONLY through a wizard, called “Recovery Scenario Manager”. Recovery operations could be selected from built-in behavior (i.e. restart test, skip test, ignore, etc.) or (thanks!) custom functions might be assigned. However, developers need to manage handlers programmatically (I’m gonna blog about it), as by default any declared handler is always active – and actively uses QTP resources impacting test execution performance.

Event Handling

As already been said, GUI events are treated pretty much as exceptions in both tools.

In WinRunner, GUI “exception” is declared the following way:


define_popup_exception("on_app_popup1", "handler_on_app_popup1", "wndAppPopup1");

# wndAppPopup1 is a logical name of the pop-up window OR it's title

# handler_on_app_popup1 is the name of a handler function that will be automatically called by WinRunner once wndAppPopup1 is spotted

With QTP, a pop-up window could be defined only through it’s title, which sometimes brings a lot of confusion (because, often Desktop applications use a same title window for many kinds of messages).


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.