Monday 4 April 2011

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.

Source

0 comments:

Post a Comment

Apex Monkeys © 2008. Design by :Yanku Templates Sponsored by: Tutorial87 Commentcute Software blogs Computers Blogs