Sunday 18 December 2011

Exception handling in QTP with a Custom function


Function Application_Crash(Object, Method, Arguments, retVal)

'Determine the method causing the problem
Select Case Method

Case "Check"
objMethod = "Checkpoint failure"

Case "Set"
objMethod = "Unable to set value"

Case "Select"
objMethod = "Unable to select value"

Case "Exist"
objMethod = "Unable to check for object existance"

Case "Sync"
objMethod = "Page / object synchronization error"

Case "Click"
objMethod = "Unable to click the object/link"

Case Else
objMethod = "Unknown reason"

End Select

'Determine the type of object caused the problem
objType = Object.GetTOProperty("micclass")

'Determine object properties
Name = Object.GetToProperty("name")
Type = Object.GetToProperty("type")
HTML = Object.GetToProperty("html tag")
InnerText = Object.GetToProperty("innertext")
objProperties = Name & " " & Type & " " & HTML & " " & InnerText

'Pass the error description to the data table
DataTable("Error_Source", dtGlobalSheet) = "Method = " & objMethod & " // ObjType = " & objType & " // " & objProperties

Test_Name = DataTable("Test_Name", dtGlobalSheet)
Test_Path = DataTable("Test_Path", dtGlobalSheet)
Test_Result = DataTable("Test_Result", dtGlobalSheet)

Call Get_TestResult(Test_Name, "Aborted")

End Function

'********************************************************************************************************************************************************************************************************************************************************************

No comments:

Post a Comment