Google Search Results
You arrived here after searching for the following phrases:
Click a phrase to jump to the first occurrence, or return to the search results.
Update: Thanks to Peretz, we now know that there is a hotfix that solves the issue (designated QTP_00563), and that the fix has already been incorporated into the upcoming QTP 10 (Atlantis). Thanks a lot for the information and the care!
I have recently spent over a day of frustrating debugging until I’ve finally stumbled upon a QTP bug which caused all my problems; so I thought I’d share it with the QTP community, hoping it would save someone else’s precious time and money.
Our story begins with the .ChildObjects command:
If you work extensively with QTP, you’ve probably came across the .ChildObjects command (if not – you can read a little about it here). This wonderful command allows us to ask a QTP object for all its child-objects that have certain properties. It allows us to write extremely elegant and dynamic scripts, without committing ourselves to working with specific GUI objects.
For example, this will input all the text fields within a given page, without knowing who they are or how many of them exist beforehand:
Dim oDesc
Set oDesc = Description.Create
oDesc("micclass").Value = "WebEdit"
Dim oChildren
Dim i
Set oChildren = Browser("index:=0").Page("index:=0").ChildObjects(oDesc)
For i = 0 to oChildren.Count - 1
oChildren.Item(i).Set "Demo Text"
Next
This is just one simple example – in real life .ChildObjects is even more amazing and useful.
The .ChildObjects command can be combined with the Desktop object, to run through all the top-level windows and applications. For example, this will highlight every opened Notepad window.
Dim oDesc
Set oDesc = Description.Create
oDesc("nativeclass").Value = "Notepad"
Dim oChildren
Dim i
Set oChildren =Desktop.ChildObjects(oDesc)
For i = 0 to oChildren.Count - 1
oChildren.HighLight
Next
Well, you get the trick.
Now to the second part of our story:
One of the amazing features of QTP, is the ability to describe objects with Regular Expressions. For example, you’d like to describe both Notepad and Wordpad windows, you could’ve used the following line in the above script:
oDesc("nativeclass").Value = "Notepad|WordPadClass"
The “|” sign is a regular expression switch that tell QTP that both “Notepad” and “WordPadClass” should be considered as successful “hits”. Regular Expressions allow for wonderful, flexible object identification, and have rescued me from the pit of despair on several occasions (you can read more on Regular Expressions in QTP in Dani’s book – Scripting QTP ).
The bug I’ve found is that when retrieving the Desktop’s child-objects, regular expressions do not work! This means that the above example would’ve yielded zero results – missing both Notepad and Wordpad windows. This is true for all regular expressions, even the simpler .* ones.
This drove me crazy, as regular expressions work well with the .ChildObjects command on every other object. As long as it’s not the Desktop object, everything’s OK. Once you use it on the Desktop – no regular expression works. Trying to manually set the .RegularExpression property of the description to true doesn’t work either, and in any case, the same description works fine when its used in a .ChildObjects command on any other object.
This bug forces me to do horrible things. If we use the Wordpad/Notepad example, it forces us to duplicate our code (once for each NativeClass); on other occasions it does even more damage. Perhaps the things which angers me the most is that it’s clearly a bug, some silly overlook or omission. It’s far too arbitrary to be anything else.
At least now that you know about it, you won’t have to waste hours of hard work figuring out where the problem is…
Posted in Yaron Assa's Blog


Yaron Assa





January 22nd, 2009 at 8:17 am
That is one bizzare behavior but I’ve seen many problems in other areas where I also had to find a workaround because of a QTP bug.
January 22nd, 2009 at 8:38 pm
Thanks for sharing that Yassa. It’s great to read these type of issues so at least if I find myself with a similar problem the little memory lightbulb may light up.
January 23rd, 2009 at 9:15 am
GREAT YASSA!!!
January 24th, 2009 at 11:34 pm
Yaron, didn’t you omit indicating that it’s a regular expression to the Description object? As far as I recall, you must explicitly tell that it is, this way:
oDesc(”nativeclass”).Value = “Notepad|WordPadClass”
oDesc(”nativeclass”).RegularExpression = True
January 25th, 2009 at 8:04 am
Meir,
“Trying to manually set the .RegularExpression property of the description to true doesn’t work either, and in any case, the same description works fine when its used in a .ChildObjects command on any other object.”
;)
January 25th, 2009 at 8:49 pm
Thanks, Barak. I just wanted to make sure it wasn’t omitted accidentally. I’ll investigate the matter to see how I dealt with it in the past, since I recall using the Desktop object. Anyway, as part of the development of My System, I intend to replace the Desktop object altogether (I already replaced almost all QTP objects for more stability and flexibility).
Cheers,
Meir
January 27th, 2009 at 5:51 am
Meir, QTP sets the RegularExpression property to True by default. You need to change it to False explicitly when you want. But for True nothing needs to be done
January 27th, 2009 at 8:35 am
After digging in my code base, it looks like it never crossed my mind (or had the need) to use RegExp with the Desktop object. When I had to manipulate multiple windows, I preferred to store their runtime references (hwnd) in a dictionary. This way any other necessary manipulations are open.
January 28th, 2009 at 9:28 am
Hi Yaron and all,
Indeed, there is a bug in QTP 9.5 that prevents using RegExp with Desktop object.
However, there is a patch (QTP_00563) that fixes this issue in QTP 9.5, and the fix is already embedded in the coming QTP 10.0 release.
Peretz
February 4th, 2009 at 9:56 am
What a terrible mistake the qtp has.
February 6th, 2009 at 2:17 am
Thats great news about the patch, but unfortunately I was unable to find it anywhere. Is it some sort of “private” patch?
February 6th, 2009 at 7:22 am
Only Test Objects will support regular expressions in QTP. DeskTop object is not a test object.
February 6th, 2009 at 8:02 am
giriumchandra - I’m not trying to use the regular expressions ON the desktop object, but on the test-object it houses (i.e. windows, etc.)
February 16th, 2009 at 1:16 pm
I had this problem one year ago when I worked on a PDF component.
My solution was to capture all objects from desktop and assign to a test object, and then, capture the target object we want to work on with the regular expression.
February 17th, 2009 at 1:23 pm
Thanks for the information Yassa. Keeping these small aspects in mind while preparing the scripts save us a lot if work at times.
March 17th, 2010 at 10:50 am
Since only one desktop is there,Regular expression is not available for Desktop object.
And it wont consider any other opened the application apart from currently activated window.