GUI object synchronization – custom function (QTP, VBScript)
Custom function implementing a more advanced synchronization point.
The function will wait for the object to become existing and enabled, or to disappear (not existing). The maximum time to wait could be defined or taken by default.
Used resources:
Anti sleep function (QTP, VBScript, MercuryTimer, DeviceReplay)
Service Functions – String (QTP, VBScript)
'Default Obj Sync Private Const Object_SyncTime_Max = 60 ' 1 minute Public Function WG_ObjSync(ByRef objName, ByVal objParameter) Dim boolRC Dim sTypeName Dim intSync, boolStateAppear 'Verify parameters sTypeName = TypeName (objParameter) If sTypeName <> "Dictionary" Then Set objParameter = CreateObject("Scripting.Dictionary") End If 'Sync If objParameter.Exists("p.sync") Then intSync = IntVal(objParameter.Item("p.sync")) If intSync <= 0 Then intSync = Object_SyncTime_Max End If Else Set objParameter = Nothing Exit Function End If If UCase(objParameter.Item("p.state")) = "DISAPPEAR" Then boolStateAppear = FALSE Else boolStateAppear = TRUE End If 'Sync loop MercuryTimers("WG.Timer1").Start Do boolRC = objName.Exist(0) 'Check Select Case boolStateAppear Case TRUE If boolRC Then boolRC = objName.CheckProperty("enabled", 1, 0) If boolRC Then MercuryTimers("WG.Timer1").Stop Set objParameter = Nothing Exit Function End If End If Case FALSE If Not boolRC Then MercuryTimers("WG.Timer1").Stop Set objParameter = Nothing Exit Function End If End Select 'Anti Sleep AntiSleep 'Timeout? If CInt(MercuryTimers("WG.Timer1").ElapsedTime/1000) > intSync Then MercuryTimers("WG.Timer1").Stop Set objParameter = Nothing Exit Function End If Loop End Function