Login   /   Register

No Regular-Expressions for the desktop object

Rate this article
     4 votes, average: 4.5 out of 54 votes, average: 4.5 out of 54 votes, average: 4.5 out of 54 votes, average: 4.5 out of 54 votes, average: 4.5 out of 5
Loading ... Loading ...
January 21st, 2009 by Yaron Assa

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

16 Responses to “No Regular-Expressions for the desktop object”

  1. barak3d Says:

    [+]

    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... ...

  2. glennh Says:

    [+]

    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 li... ...

  3. Devendra Sharma Says:

    [-]

    GREAT YASSA!!!

  4. Meir Bar-Tal Says:

    [+]

    Yaron, didn't you omit indicating that it's a regular expression to the Description object? As far as I recall, you must explicitl... ...

  5. barak3d Says:

    [+]

    Meir, "Trying to manually set the .RegularExpression property of the description to true doesn’t work either, and in any case, ... ...

  6. Meir Bar-Tal Says:

    [+]

    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 i... ...

  7. tarunlalwani Says:

    [+]

    Meir, QTP sets the RegularExpression property to True by default. You need to change it to False explicitly when you want. But for... ...

  8. Meir Bar-Tal Says:

    [+]

    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. Whe... ...

  9. pregev Says:

    [+]

    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 ... ...

  10. heqingbluesky Says:

    [-]

    What a terrible mistake the qtp has.

  11. offspring Says:

    [-]

    Thats great news about the patch, but unfortunately I was unable to find it anywhere. Is it some sort of “private” patch?

  12. giriumchandra Says:

    [-]

    Only Test Objects will support regular expressions in QTP. DeskTop object is not a test object.

  13. Yaron Assa Says:

    [+]

    giriumchandra - I'm not trying to use the regular expressions ON the desktop object, but on the test-object it houses (i.e. window... ...

  14. PascalAugugliaro Says:

    [+]

    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 t... ...

  15. leelamanoharqa Says:

    [-]

    Thanks for the information Yassa. Keeping these small aspects in mind while preparing the scripts save us a lot if work at times.

  16. primal_v Says:

    [+]

    Since only one desktop is there,Regular expression is not available for Desktop object. And it wont consider any other opened t... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 590 times