Search code examples
vbscriptqtphp-uftmaximize-windowwscript.shell

How to Maximize Screen from VBScript?


The web application that displays database information is much more readable in full-screen mode rather than a small window. Problem is, I cannot get the window to maximize from UFT/QTP.

I've tried running the browser object from Wscript.Shell, but the application returns to UFT and maximizes that window instead of the newly created browser window.

siteA = "https://google.com"
Const max_window = 3
Set browobj = CreateObject("Wscript.Shell")
Set oShell = CreateObject("WScript.Shell")
'browobj.Run "chrome -k -incognito -url "&siteA
browobj.Run "chrome -incognito -url "&siteA, max_window
oShell.SendKeys "% x"
browobj.sendkeys "{F9}"
browobj.sendkeys "(% )X"
browobj.SendKeys "% x"

Set browobj = Nothing

Any solutions to maximizing the window with the focus object of the new browser?

Edit:

Even below will not maximize taken from this List of Controls is not working.

SystemUtil.Run "chrome.exe" , siteA ,,,3 
chrome.exe  --incognito --start-maximized

If you shut down all instances of chrome these controls work fine, but if you have an active window in chrome it will take those properties.


Solution

  • We have a function defined during our browser login process that grabs the window and maximises it so that our UFT processes run with a (nearly) full screen browser - we don't need to hide the menu bar etc. This is the function we are using:

    Public Function MISC_MaximiseBrowser(ByVal oBrowser, ByRef ErrorMsg)
        LOG_Write vbNewLine & "MISC_MaximiseBrowser"
        LOG_Write "oBrowser: " & oBrowser.GetROProperty("TestObjectName")
    
        Dim Hwnd
        dim bIsMax, bIsMaxable
    
        MISC_MaximiseBrowser = True
    
        Hwnd = oBrowser.Object.HWND
    
        If Window("hwnd:=" & Hwnd).GetROProperty("maximized") Then
            bIsMax = True
        Else
            bIsMax = False
        End If
    
        If Window("hwnd:=" & Hwnd).GetROProperty("maximizable") Then
          bIsMaxable = True
        Else
          bIsMaxable = False
        End If
    
        If Not bIsMax And bIsMaxable Then
            Window("hwnd:=" & Hwnd).Maximize
        End If
    
    End Function
    

    What this does is accepts the Browser UFT object you're working with and grabs the handle for it. If the browser is not already maximized and it's possible to maximize it, it will do so.

    You can ignore the LOG_Write statements at the start of the function - those are for our internal logging steps