How to minimize/maximize QTP window?

How to minimize/maximize QTP window?

This is very useful feature - minimize QTP window before script execution. It allows to observe a desktop or an application under test wholly.

I will show and describe how to minimize (or maximize) QTP window programmatically - i.e. from QTP script.
Also, provided approach can be applied to minimize (maximize) any required window - Browser, Notepad, MS Word or Excel, and so on.


There are two ways to minimize QTP window:

  1. Using Minimize method of Window object
  2. Using QTP Application object - QuickTest.Application


These methods will contain several lines only and I hope that my explanations will be understandable.
So, let's explore!

  1. Using Minimize method of Window object
    You can use Minimize method of Window object to minimize QTP window (or any other).

    Let's see two cases - when a window is located in Object Repository (OR) and widows is not located in OR.

    • If a window is located in Object Repository (OR), then minimizing can be performed using the following code:

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Minimize


      In first line, we get window handle (hWnd) of Browser object . And then we pass this handle to Window object and minimize it.
      Obviously, that we can use the same approach to maximize window (use method):

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Maximize


    • If a window is not located in Object Repository (OR), then we can use some run-time object properties and descriptive programming to identify a window. For example, we can use window title.

      Please, see a screen shot of QTP window:QTP window title has a prefix - 'QuickTest Professional - ' followed by test name. I will use this prefix ('QuickTest Professional - ') with a mask:

      1. sTitleMask = "QuickTest Professional - .*"
      2. Window("regexpwndtitle:=" & sTitleMask).Minimize


      I use Regular Expressions.
      Mask
      ".*" means "match any characters zero or more times". So, this mask will identify QTP window, and this code will minimize it.

      The same approach can be applied to Browser.

      See a screen shot of this browser:

      In this case, browser has prefix 'Google - '. So, I will use it as the mask:

      1. sTitleMask = "Google - .*"
      2. Browser("regexpwndtitle:=" & sTitleMask).GetROProperty("hwnd")
      3. Window("hwnd:=" & hWnd).Minimize


      Well, you can use any approach you like. All of them work and minimize/maximize windows correctly.


  2. Using QTP Application object - QuickTest.Application
    Since this approach uses QuickTest Automation Object Model, it can be applied to QTP window only.

    There is a procedure, which minimizes QTP window:


    1. Sub MinimizeQTPWindow ()
    2.     Set     qtApp = getObject("","QuickTest.Application")
    3.     qtApp.WindowState = "Minimized"
    4.     Set qtApp = Nothing
    5. End Sub


    To minimize QTP window, just execute MinimizeQTPWindow () procedure:

    1. MinimizeQTPWindow


    For detailed information, I recommend to Read QTP Help > QuickTest Automation Object Model Reference.

Since QuickTest Automation Object Model does not use UI, second approach is more stable.
But first method is more flexible - it allows working with browsers and stand-alone windows.

In any case, I recommend to read and explore both approaches.



Do you have comments or questions on this or related QTP topics?
Please, send them and I will try to prepared detailed and informative article.

--
Thank you, my readers
Dmitry Motevich




Related articles:

7 comments:

Rajesh chaudary said...

HI Dmitry Motevich please solve below issues...Thanx for great and clear explanation..

1.Architecture of frame work

2.While testing what kind of values will be frequently changed

3.Parameterization types (script)


4.Database connection (script)

5.Output values


6.How to capture the runtime objects

7.Descriptive programming.

Aarti said...

Hi,

I'm trying to learn QTP scripting. I understand the features of QTP and how they are used. But here my question is how do you start writing the scripts. I do have an understanding on VB Script but just need a sample QTP script to know the approch. I know that we have to capture the object properties before starting to write a script but just not getting a proper approach. Could you please help me on this?

Thanks,
Aarti

msmanickavasagam said...

Hi,
Any one can pl explain me
about how capture dynamic changing
images in LOAD RUNNER.

Jay said...

Hi any body help me how to maximize the window at run time. I tried with this code

hWnd = Browser("Gmail: Email from Google").GetROProperty("hwnd")
Window("hwnd:=" & hWnd).Maximize

But it is not working. It is showing error like "The operation can not be Performed".

Please any body can tell me how fix this error

Dmitry Motevich said...

2Jay:
What line invokes the error?

Adnan said...

I get the same error on the second line.

Alternatively I found QTP 9.5 to have a built in function called 'Fullscreen'

e.g
Browser("Some browser").FullScreen

Dmitry Motevich said...

Dear Readers!
Thank you very much for you comments!

Since this article was published more than one year ago, I've just disabled an adding of new comments for the article.