TestComplete – Handling Web Browser (3)

Categories: Source codeWeb

Parent page: GUI Recognition with TestComplete

Close, minimize, maximize, move, resize browser window

Description

A WebForm (Page, Frame, table, etc.) can not be operated same way as window. The first thing function does is iterating upwards the hierarchy to access Process object, which is used to retrieve browser window reference.

In the example presented, IEFrame property of the Process object is used which corresponds to Internet Explorer page. Use UIPage property to access Firefox page.

Implementation

Public Const syncTimeShort = 5
Public Function wbSetBrowser(ByRef objWebParent, ByVal objParameter)
 Dim boolRC
 Dim sTypeName
 Dim sWinState, sURL, intX, intY
 Dim objGUIParent, objBrowserWindow
 'Go backwards to Process level parent
 Set objGUIParent = objWebParent
 Do While True
 If objGUIParent.Parent is Nothing Then
 Exit Function
 End If
 If InStr(LCase(objGUIParent.Name),"process") > 0 Then
 Exit Do
 End If
 Set objGUIParent = objGUIParent.Parent
 Loop
 'Get Window reference
 ''Note. IEFrame (MSIE) or UIPage (Firefox)
 Set objBrowserWindow = objGUIParent.IEFRame(0)
 'Verify parameters
 sTypeName = TypeName (objParameter)
 If sTypeName <> "Dictionary" Then
 Set objParameter = CreateObject("Scripting.Dictionary")
 End If
 'Retrieve arguments
 sWinState = UCase(objParameter.Item("state"))
 If sWinState = "" Then
 sWinState = "FOCUS"
 End If
 Select Case sWinState
 Case "CLOSE"
 On Error Resume Next
 objBrowserWindow.Close(syncTimeShort*1000)
 On Error GoTo 0
 Case "FOCUS"
 On Error Resume Next
 Call objBrowserWindow.Activate()
 On Error GoTo 0
 Case "MIN"
 On Error Resume Next
 objBrowserWindow.Minimize
 On Error GoTo 0
 Case "MAX"
 On Error Resume Next
 objBrowserWindow.Maximize 
 objBrowserWindow.Activate
 On Error GoTo 0
 Case "RESTORE"
 On Error Resume Next
 objBrowserWindow.Restore 
 objBrowserWindow.Activate
 On Error GoTo 0
 Case "RESIZE"
 On Error Resume Next
 intX = IntVal(objParameter.Item("p.width"))
 intY = IntVal(objParameter.Item("p.height"))
 Call objBrowserWindow.Position(objBrowserWindow.Left, objBrowserWindow.Top, intX, intY)
 objBrowserWindow.Activate
 On Error GoTo 0
 Case "MOVE"
 On Error Resume Next
 intX = IntVal(objParameter.Item("p.x"))
 intY = IntVal(objParameter.Item("p.y"))
 Call objBrowserWindow.Position(intX, intY, objBrowserWindow.Width, objBrowserWindow.Height)
 objBrowserWindow.Activate
 On Error GoTo 0
 Case "NAVIGATE"
 sURL = objParameter.Item("url")
 On Error Resume Next
 Call objBrowserWindow.Parent.ToURL(sURL)
 On Error GoTo 0
 Case Else
 On Error Resume Next
 objBrowserWindow.Activate
 On Error GoTo 0
 End Select
End Function 

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.