'————————————————————————————————————————————— '' ' Class clsAjaxUtil ' ' Methods: ' AddObject ' DestroyDict ' RemoveObject ' SetBrowser ' SyncObjects * ' SyncWebTable * ' ' Author: Anshoo Arora ' ' Version: v1.0 '' '————————————————————————————————————————————— Class clsAjaxSync '————————————————————————————————————————————— Public StatusSync ' Synchronization with changes in application Public ObjectSync ' To synchronize while the object loads Public oBrowser ' Reference to the target browser: SetBrowser "MyBrowser" Public oTable ' Reference to the target table: SyncWebTable "MyTable" Public intVisCnt Private sClass ' Class used in SyncObjects Private intObjectCount ' Changes in Object Counts in SyncObjects Private oLocalDict ' Dictionary '————————————————————————————————————————— ' Name: Class_Initialize (Private) ' ' Purpose: Scripting.Dictionary Singleton ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Private Sub Class_Initialize '————————————————————————————————————————— Dim bInit 'As Boolean bInit = False 'Singleton Pattern (see references in remarks above) If IsObject(oGlobalDict) = True Then If Not oGlobalDict is Nothing Then bInit = True End If End If 'Only create new object if needed If bInit = False Then Set oGlobalDict = CreateObject( "Scripting.Dictionary" ) 'Set the local class excel reference to the global Singleton object Set oLocalDict = oGlobalDict End Sub '————————————————————————————————————————— ' Name: AddObject (Public) ' ' Purpose: Add object to collection ' ' Parameters: ' sObjectName: Name of the object stored as refereces ' oObject: Reference of the object ' ' Author: ' ' Date: '————————————————————————————————————————— Public Sub AddObject( sObjectName, ByRef oObject ) '————————————————————————————————————————— If oLocalDict.Exists(sObjectName) Then RemoveObject sObjectName End If oLocalDict.Add sObjectName, oObject End Sub '————————————————————————————————————————— ' Name: SyncWebTable (Public) ' ' Purpose: Synchronize the table for StatusSync seconds to make sure no text has changed. ' ' Parameters: ' ' Author: ' ' Date: ' ' Remarks: ' Uses recursion '————————————————————————————————————————— Public Sub SyncWebTable( sTableName ) '————————————————————————————————————————— If IsObject(Me.oTable) Then Set Me.oTable = Nothing Set Me.oTable = oLocalDict.Item( sTableName ) If ObjectSync = "" Then ObjectSync = 1 ' Check if the Table exists If oTable.Exist(ObjectSync) Then ' Make sure the table is visible If oTable.GetROProperty( "x" ) <> 0 Then ' Sync for changes in Table SyncText Else Reporter.ReportEvent micWarning, sTableName, "Object not visible." Me.intVisCnt = Me.intVisCnt + 1 ' Maybe the table is still loading its elements, use recursion and check again. If Not Me.intVisCnt >= 2 Then SyncWebTable sTableName End If Else Reporter.ReportEvent micWarning, sTableName, "Object not found." End If End Sub '————————————————————————————————————————— ' Name: SyncText ' ' Purpose: Verify if the table text has changed. If the text ' changes, the original text string is reset. The loop runs again until it ' reaches its max: StatusSync. ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Private Sub SyncText '————————————————————————————————————————— Dim intWait, sNewText, sReportChanges Dim sDivider: sDivider = "================================" Dim sRefText: sRefText = GetTableText If StatusSync = 0 Then StatusSync = 1 Do ' Get the updated innerText from the Table sNewText = GetTableText sReportChanges = sRefText &vbLf&sDivider& sNewText &vbLf&sDivider& sReportChanges ' Verify if there were changes If sRefText <> sNewText Then intWait = 0 sRefText = sNewText Else intWait = intWait + 1 End If Wait(1) Loop Until intWait = StatusSync Reporter.ReportEvent micInfo, "WebTable Sync", sReportChanges End Sub '————————————————————————————————————————— ' Name:SyncObjects (Public) ' ' Purpose: Checks whether the object count has changed. ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Public Sub SyncObjects( ClassName ) '————————————————————————————————————————— Dim intWait, intNewCount, sReportChanges Dim sDivider: sDivider = "================================" sClass = ClassName Dim intObjectCount: intObjectCount = CountObjects If StatusSync = 0 Then StatusSync = 1 Do ' Get the current number of objects count for ClassName intNewCount = CountObjects sReportChanges = "Old: " & intObjectCount &vbLf& "New: " &_ intNewCount &vbLf&sDivider&vbLf& sReportChanges &vbLf ' Verify if there were any changes in the count for ClassName If intObjectCount <> intNewCount Then intWait = 0 intObjectCount = intNewCount Else intWait = intWait + 1 End If Wait(1) Loop Until intWait = StatusSync Reporter.ReportEvent micInfo, "Sync Objects", sReportChanges End Sub '————————————————————————————————————————— ' Name: SetBrowser (Public) ' ' Purpose: Set the browser in which the objects count is being searched for ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Public Sub SetBrowser( sBrowserName ) '————————————————————————————————————————— Set Me.oBrowser = oLocalDict.Item( sBrowserName ) End Sub '————————————————————————————————————————— ' Name: RemoveObject (Public) ' ' Purpose: Remove object from collection ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Public Sub RemoveObject( sObjectName ) '————————————————————————————————————————— If oLocalDict.Exists(sObjectName) Then oLocalDict.Remove(sObjectName) End If End Sub '————————————————————————————————————————— ' Name: DestroyDict (Public) ' ' Purpose: Releases Dictionary ' ' Parameters: ' ' Author: ' ' Date: '————————————————————————————————————————— Public Sub DestroyDict '————————————————————————————————————————— oLocalDict.RemoveAll Set oLocalDict = Nothing Set oGlobalDict = Nothing End Sub '————————————————————————————————————————— ' Name: CountObjects (Private) ' ' Purpose: Internal Function to retrieve visible object count ' ' Parameters: ' ' Return: ' Integer ' ' Author: ' ' Date: '————————————————————————————————————————— Private Function CountObjects '————————————————————————————————————————— Dim pDesc: Set pDesc = Description.Create pDesc( "micclass" ).Value = sClass '* Get all objects with micClass = sClass CountObjects = oBrowser.Page("micclass:=Page").ChildObjects(pDesc).Count '* Get only visible objects pDesc( "x" ).Value = 0 CountObjects = CountObjects - oBrowser.Page("micclass:=Page").ChildObjects(pDesc).Count End Function '————————————————————————————————————————— ' Name: GetTableText (Private) ' ' Purpose: Retrieves the innertext of the table ' ' Parameters: ' ' Return: ' String ' ' Author: ' ' Date: '————————————————————————————————————————— Private Function GetTableText '————————————————————————————————————————— Reporter.Filter = rfDisableAll On Error Resume Next oTable.Init GetTableText = oTable.object.innerText If Err.Number <> 0 Then Err.Clear End If On Error Goto 0 Reporter.Filter = rfEnableAll End Function End Class Set Ajax = New clsAjaxSync Public Function AjaxUtil Set AjaxUtil = Ajax End Function