Search This Blog

Sunday, November 20, 2011

QTP -> Function for providing the synch to the application object

' Name: Fun_SynchObjectToAppear
' Purpose: This function is used for providing the synch to the application object
' Argument(s):
'     ip_obj: Object under the test EX: SparkDropDownList
'     ip_intStartTime: Start time from which the max wait time  is evaluated. Ex: Timer value at the time of calling this function
'     ip_intWaitTimeInSec: Maximum wait time for object to appaer in the application and get visible
' Returns:
'      NON Zero Value: Indicates that the object is appeared on the screen and is visible.
'        0 Indicates that the object is not available under the application after waiting for the given max wait time.  
' Example: returnValue = Fun_SynchObjectToAppear(objSparkApplication, Timer, "360")
Public Function Fun_SynchObjectToAppear(ByRef ip_Obj, ip_intStartTime, ip_intWaitTimeInSec)
 Dim blnObjectLoaded, intStartTime, intEndTime
 blnObjectLoaded = False 'Set the flag to false to indicate that the object is not loaded
 intStartTime = ip_intStartTime 'Start tiem is set as the passed argument value
  If ip_Obj.Exist(1) Then
   If CStr(ip_Obj.GetRoProperty("visible")) = "True" Then
     blnObjectLoaded = True 'Reset the flag to indicate that the object is appeared on the application
     Exit Do 'Exit the loop if the expected object is exists and is visible in the application
   End If
  End If   
  intEndTime = Timer 'Set the current time as end time
 Loop Until intEndTime > intStartTime + ip_intWaitTimeInSec 'Break the loop if the end time reached as more than the max wait time

 '<<< Report the report based upon the load event on the tab selection >>>
 If blnObjectLoaded = True Then
   Fun_SynchObjectToAppear = (intEndTime - ip_intStartTime)/60 'Return the total time taken in minutes as a return value
   Fun_SynchObjectToAppear = "0" 'Return ZERO to indicate that the object is not appeared on the screen
 End If
End Function
'<<< ---------- Function registration----------- >>>
RegisterUserFunc "SparkDropDownList", "Fun_SynchObjectToAppear", "Fun_SynchObjectToAppear"
RegisterUserFunc "SparkTextInput", "Fun_SynchObjectToAppear", "Fun_SynchObjectToAppear"
RegisterUserFunc "SparkCheckBox", "Fun_SynchObjectToAppear", "Fun_SynchObjectToAppear"
RegisterUserFunc "SparkButton", "Fun_SynchObjectToAppear", "Fun_SynchObjectToAppear"

Example : -

 '<<< Synch provided until the filter object gets displayed in the application >>>
 Set objSparkApplication = Browser("FlexApp").FlexApplication("app").SparkApplication("erfr-flex-gui.swf").SparkSkinnableContainer("showHidePane").SparkButton("Filters")
 intWaitTimeInSec = intConstWaitShort * 60
 '<<< Calling user defined function for providing application object synchronization >>>
 returnValue = Fun_SynchObjectToAppear(objSparkApplication, Timer, intWaitTimeInSec)

No comments:

Post a Comment