You may need to close browsers before or during the QTP script execution.
You can be surprised, but QTP script, that closes all browsers, will contain 3 lines only:
Well, how does this code work?
To answer, I have to tell about QuickTest Professional Descriptive Programming.
Descriptive Programming (DP) is a working with object, which are not described in QTP Object Repository (OR).
All objects properties are calculated dynamically during the QTP test execution.
Please, check this code:
"CreationTime" is a QTP browser property, which indicates the order in which browsers were opened.
QTP Tip1: The first browser that opens receives the value "CreationTime" = 0, the second browser receives "CreationTime" = 1, and so on...
QTP Tip2: To specify value of property in Descriptive Programming, please use ":=" operator.
For example, "Title:=My application".
Since we cannot know in advance - what browser will be selected and closed, we use its "age", i.e. "CreationTime" property. We decide, which browser should be closed, during the QTP script execution only.
Let's return to above QTP script...
- Browser("CreationTime:=0").Exist - it checks whether the first opened browser exists or not
- If the browser exists, we close it - Browser("CreationTime:=0").Close - and repeat checking
Let's continue сomplicating our task:
How to close browsers by mask?For example, we have to close all browsers navigated to any Google's sites (URL contains 'google.com').
In this case, QTP script will look like:
Using this QTP code, you can close dynamically browsers by mask.
Please, note several useful QTP tips.
QTP Tip3: To get browser's URL, use: GetROProperty("URL") function.
For example, this line returns URL of the first opened browser:
QTP Tip2: Analogously, to get browser's Title, use: GetROProperty("Title") function.
I've shown and explained:
- Simple concepts of QTP Descriptive Programming
- How to close all browsers from QTP test
- How to close browsers by mask from QTP test
- QTP Descriptive Programming - How to get number of objects
- QTP Descriptive programming - processing images
- QTP Descriptive Programming - How to perform operations on objects
- QTP - How to capture tool tip?
- QTP - Capturing tool tips of images
- All QTP visual tutorials
I hope, these simple scripts will be usefull for you. Please, let me know.
Do you have suggestions/materials/questions on QTP? Please, post your comments on my blog.