QTP: A smarter way to access your browser

We've all done it, right? We've started an IE instance, recorded/coded against it, and then when we're done, we've wanted to close it.

The trouble is that QTP has now forgotten which window is the correct one. Either the browser has changed in some small way, or we have too many open that are similar, or whatever. This doesn't happen often, but when it does, it's a royal pain

How do we ensure we can close the *correct* browser?

Lately, I've started storing the handle for the browser window I open in an environment variable. That way, using descriptive programming later, I *know* I can close the browser I want and nothing else.

Example:
Environment("BrowserHandle") = Browser("Browser).GetROProperty("hwnd")

Then later, to close:
Browser("hwnd:=" & Environment("BrowserHandle")).Close

This also works for anything, really. Navigate, or, like me, custom functions registered to your browser. I've found that while I always need this, there are many times when this really comes in handy and makes the process to get at a specific browser very efficient.

QTP: Bloggers unite!

I was contacted by the authors of a fantastic QTP site recently. Software Inquistion has lots of great examples, and seems to be a good resource for those of us interested in pursuing automated testing from a development project approach rather than from a simple record and playback. Be sure to check it out if you have use QTP at any level. Good stuff!
«March»
SunMonTueWedThuFriSat
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678