Tuesday, March 2, 2010

QTP - Always use registered methods for the STABILITY of framework or test.

QTP - Always use registered methods for the STABILITY of framework or test.

When method is executed on a test object there are lot of instances where object missing, properties changed, input data not matching with the run time object (length, list box values not matching). This will stop your test by displaying run-time error . In order to shield your test from these errors, we need to override existing methods by registering user defined functions.


I will explain this concept by taking WebEdit Set method.

When this method is fired
1.Check Object exist
2. Highlight the object if required (my framework requirement, just to demo the QTP flow during execution)
3. Check object is in enable state.
4. Check whether the object max length is less than or equal to user value.
5. If 1,3 and 4 conditions are satisfied, set method is executed. I use global variables (gsExecutionStatusTestCase, gsStatusMessageTestCase)  to send failed status messages to the framework. By using status and message, framework will update control and test case files. For more information about the framework look into Dual function framework blog.

In my framework I had redefined all the test object methods, so that script would never fail due to above mentioned issues. I strongly recommend not to use "On Error Resume Next" for the same.


RegisterUserFunc "WebEdit", "Set", "WebEditSetUserDefined" 


Public Function WebEditSetUserDefined (oObject, sValue)
        If oObject.Exist(10) Then
                If gsObjectHighlight = "ON" Then
                        oObject.Highlight
                End If
                If oObject.GetROProperty("disabled") = 0 Then
                        If  oObject.GetROProperty("max length") <  Len(sValue)  Then
                                gsExecutionStatusTestCase = conF
                                gsStatusMessageTestCase = gsStatusMessageTestCase & "Object WebEdit: " & oObject.GetTOProperty("html id") & " Input greater than field length " &  " # "
                        Else
                                oObject.Set sValue
                        End If
                Else
                        gsExecutionStatusTestCase = conF
                        gsStatusMessageTestCase = gsStatusMessageTestCase & "Object WebEdit: " & oObject.GetTOProperty("html id") & " in disable state " &  " # "
                End If
        Else
                gsExecutionStatusTestCase = conF
                gsStatusMessageTestCase = gsStatusMessageTestCase & "Object WebEdit: " & oObject.GetTOProperty("html id") & " don't exist on the page " & " # "
        End If
End Function






---

2 comments:

  1. Hi Bharath,
    Wouldn't this method of using only user defined objects, slow down the execution of the script?
    Thanks,
    Harpreet

    ReplyDelete
  2. Hello Harpreet,

    Late reply, I have not read your comment.
    No, this doesn't slow the execution.

    ReplyDelete