Search This Blog

Friday, September 9, 2011

QTP & QC-> Code for function to provide a controlled wait for synchronizing the application til the expected objects gets displayed in the screen & in exists

'****************************************************************************************************************************
'Function Name : Fun_WaitForObjectExists
'Description   This function is used to provide a controlled wait for synchronizing the application til the expected objects gets displayed in the screen
'Parameters      ip_obj : Expected object     
'         ip_MaxWaitCount : Total max wait * 2 time in sec for the expected object to get displayed
'Return Val ue     0: indicates success
'       1: indicates failure
' Ex:ample    Fun_WaitForObjectExists(ip_obj, 20)
'****************************************************************************************************************************
Function Fun_WaitForObjectExists(ip_obj, ip_MaxWaitCount)
  Fun_WaitForObjectExists = "1" 'Indicates Failure 
  Wait intConstShortWaitTime '<<< --- This wait is reuired to synch the application browser --- >>>

  '<<< ------- Keep looping until the object is found to be existing in the application -------- >>>
  Do While CInt(ip_MaxWaitCount) > 0
   If ip_obj.Exist(intConstShortWaitTime) Then    
    Fun_WaitForObjectExists = "0" '<<< --- Set the flag as success and exit the loop ----- >>>
    Exit Do
   Else
    '<<< --------- Decriment the counter by 1 and loop back -------- >>>>
    Wait intConstShortWaitTime
    ip_MaxWaitCount  = CInt(ip_MaxWaitCount ) - 1    
   End If
  Loop

  '<<< ------ If the flag is found to be still under initial status it indicates the failure of the object identification ------ >>>
  If Fun_WaitForObjectExists = "1" Then
    Fun_ReportFailure "Application sync event" , "Expected Object is not displayed in the screen within the given wait time", Browser("Browser Main")
   End If
End Function
'****************************************************************************************************************************
'Function Name : Fun_WaitForObjectInExists
'Description   This function is used to provide a controlled wait for synchronizing the application til the expected objects gets disappears from the screen
'Parameters      ip_obj : Expected object     
'         ip_MaxWaitCount : Total max wait * 2 time in sec for the expected object to get displayed
'Return Val ue     Null: If expected object gets displayed
'        Exists the component iteration if expected object does not disappears 
' Ex:ample    Fun_WaitForObjectInExists(ip_obj, 20)
'****************************************************************************************************************************
Function Fun_WaitForObjectInExists(ip_obj, ip_MaxWaitCount)
   Dim blnFlag
   blnFlag = "1"
   Wait intConstShortWaitTime '<<< --- This wait is reuired to synch the application browser --- >>>
   '<<< ------- Keep looping until the object is found to be inexisting in the application -------- >>>
   Do While CInt(ip_MaxWaitCount) > 0
    If ip_obj.Exist(intConstShortWaitTime) Then    
     '<<< --------- Decriment the counter by 1 and loop back -------- >>>>
     Wait intConstShortWaitTime
     ip_MaxWaitCount  = CInt(ip_MaxWaitCount ) - 1     
    Else    
     blnFlag = "0"  '<<< --- Set the flag as success and exit the loop ----- >>>
     Exit Do   
    End If
   Loop
   '<<< ------ If the flag is found to be still under initial status it indicates the failure of the object identification ------ >>>
   If blnFlag = "1" Then
     Fun_ReportFailure "Application synch event" , "Expected Object does not inexist in the screen within the given max wait time", Browser("Browser Main")
            End If
   Fun_WaitForObjectInExists = blnFlag
End Function

No comments:

Post a Comment