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:
- Using Minimize method of Window object
- 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!
- 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:
- hWnd = Browser("browser_name").GetROProperty("hwnd")
- 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):- hWnd = Browser("browser_name").GetROProperty("hwnd")
- 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:- sTitleMask = "QuickTest Professional - .*"
- 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:
- sTitleMask = "Google - .*"
- Browser("regexpwndtitle:=" & sTitleMask).GetROProperty("hwnd")
- Window("hwnd:=" & hWnd).Minimize
Well, you can use any approach you like. All of them work and minimize/maximize windows correctly.
- If a window is located in Object Repository (OR), then minimizing can be performed using the following code:
- 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:
- Sub MinimizeQTPWindow ()
- Set qtApp = getObject("","QuickTest.Application")
- qtApp.WindowState = "Minimized"
- Set qtApp = Nothing
- End Sub
To minimize QTP window, just execute MinimizeQTPWindow () procedure:
- 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.
0 comments:
Post a Comment