How to handle synchronization in UFT​

In any test automation framework, browser handling is the most important part during automation scripting.  This page compiles a list of function to handle and operate on browser, which you can encounter during your work with test automation using UFT.

A robust Syncronization mechanism plays a vital role in making your test stable. If part of your tests fail due to a bad wait function between two clicks, then it is high time to revisit your wait function and make it more error proof.

Here in the below written code, we have two assumptions.

  1. The application is a normal web based application with hierarchy as Browser>Page etc.
  2. Browser returns ReadyState= complete or 4 once it is fully loaded.

It checks 2 things in the same order as given below.

  1. First it checks that if a page is existing within the first 120 seconds.
  2. Second, it waits for the browser to return ReadyState=complete/4
Function Wait_Sync()
    
    nBrowser_Count = Browser_Count
    If nBrowser_Count > 0 Then
        waitCounter = 0
        intStartTime = 0
        Do
            wait 1
            waitCounter = waitCounter + 1
            If (waitCounter = 120)  Then
                Exit Do
            End If
            bPageExistFlag = Browser("CreationTime:=" & nBrowser_Count - 1).Page("title:=.*").Exist(0)
            
        Loop WhilebPageExistFlag = False
        
        Do          
            On Error Resume Next
            Wait 0,500
            waitCounter = 0          
            If bPageExistFlag = True Then
                ReadyState_Val = Browser("CreationTime:=" & nBrowser_Count - 1).Page("index:=0").Object.ReadyState
                
            Else
                ReadyState_Val = "Loading"
            End If
            
            sReadyState_Val = CStr(ReadyState_Val)
            
            If   intStartTime = 600  Then
                'Print intStartTime
                Exit Do
            End If
            intStartTime = intStartTime + 1
            iFinalVal = Eval(InStr(sReadyState_Val,4) > 0 Or InStr(sReadyState_Val,"complete") > 0)
            
        Loop UntiliFinalVal = True
    End If
    
End Function

How to get browser window count​ in UFT using childobjects

'This function assumes that a global variable exists during runtime 
'to dictate the browser type i.e. IE, Chrome, FF


Function Browser_Count()
    
    Wait 0,500
    Dim objShell
    Dim objShellWindows
    Set descBrowser = Description.Create()
    descBrowser("micclass").value = "Browser"
    
    Select Case gBrowser
        Case "IE"
        descBrowser("application version").value = "internet explorer.*"
        Case "Chrome"
        descBrowser("application version").value = "Chrome.*"
        Case "FF"
        Case Else
        
    End Select
    
    Set ColChildBrowser = desktop.ChildObjects(descBrowser)
    Browser_Count = ColChildBrowser.Count
    Set ColChildBrowser = Nothing
End Function

How to capture ScreenShot in UFT

How kill browser using VBScript

Open link In new window

How to Click Page save as on a webpage using UFT

How to launch chrome in Incognito mode using UFT

Follow Us
Categories

Tags

APACHE code java jenkins selenium uft vbscript

Latest Posts
Want us to add
more code ?
5/5