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.
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:
- QTP - How to set/get system time and date?
- How to execute QTP script from LoadRunner?
- QTP - How to get font size/color, background color and other attributes of controls
- How to minimize/maximize QTP window before the QTP script execution?
- All QTP visual tutorials
7 comments:
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.
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
Hi,
Any one can pl explain me
about how capture dynamic changing
images in LOAD RUNNER.
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
2Jay:
What line invokes the error?
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
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.
Post a Comment