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:
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:
Browser("CreationTime:=0").Close
Wend
"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:
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.