Forum Discussion

dsstrainer's avatar
dsstrainer
Occasional Contributor
10 years ago

Autogenerate FindChild based name?

Is there a way (or can one be added) to generate a FindChild alternattive from the object spy?

 

Here's the scenario...

 

We have a .NET app with devexpress controls and TC works fine with all the controls, but this level of application has about 50 objects per name. Example:

 

 

Set StatusMessage = Sys.Process("MyApp").WPFObject("HwndSource: root").WPFObject("root").WPFObject("ContentControl", "", 1).WPFObject("Grid", "", 1).WPFObject("Grid", "", 1).WPFObject("Part_WindowContent").WPFObject("Grid", "", 1).WPFObject("ContentControl", "", 1).WPFObject("PART_ContainerContent").WPFObject("barManager").WPFObject("DockPanel", "", 1).WPFObject("dockLayoutManager").WPFObject("mainLayoutGroup").WPFObject("statusMessagesLayoutPanel").WPFObject("statusMessagesGridControl")

 This is a pain to read and any slight change to the path will break it.

 

 

I can use an Alias which comes out to:

 

Set StatusMessage = Aliases.MyApp.AS3_MainWindow.root.ContentControl.Grid.Grid.ContentControl_1.Grid.ContentControl.PART_ContainerContent.barManager.dockLayoutManager.StatusGrid.statusMessagesGridControl

 

 

But that's still a nightmare to read and when developers make small changes to the application, they often without knowing it will add additional adorner layers or groupboxes and they end up breaking the Alias. It also requires other QA coworkers to have the same Aliases setup on their machines which isn't practical.

 

So the best way I've found is to use the FindChild method which then lets me shrink it down to:

 

Set StatusMessage = Sys.Process("MyApp").FindChild("Name", "WPFObject(""statusMessagesGridControl"")", 99999)

 

Ultimately this is the way to go for us. It is fully dynamic and saves us a lot of maintenance. The only problem is that I have to do all this manually by grabbing the fullname and then getting the first and last objects and putting the findchild in place.

 

It would be ideal to have this show up as a field in the object spy

 

Like 

Fullname: xxxxxx
MappedName: yyyyyy
FindChildMethod: Sys.Process("MyApp").FindChild("Name", "WPFObject(""statusMessagesGridControl"")", 99999)

Is that or could that be possible?

 

 

2 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    Currently TC is not capable of configuring object spy....if they going to implement, I also vote for that.

     

    For your problem what about mapping up to stable hierarchy of children (eg may be  WPFObject("barManager")  ) and finding child from there?

     

  • I use the findchild method extensively too.

    You can use wildcards to shorten it a bit.

    so

    Sys.Process("Myproc").FindChild("Name", "WPFObject(""StatusMessagesGridControl"")",9999)

    could be

    Sys.Process("Myproc").FindChild("Name", "*MessagesGrid*",9999) 

     

    The two would return the same object, presuming that the control in question was the only one with the string "MessagesGrid" as part of its name.

     

    I also like to 

    Set MP = Sys.Process("Myproc")

    at the beginning of the script, and then throughout the script use

    MP.Findchild("Name", "*MessagesGrid*",9999)

    That shortens it a bit more.

    Finally, if the line is still too long there are ways to split the line... 

    For instance in VBScript, you can use an underscore right after the period, and put the rest of the command on the next line

    I sometimes have to use multiple layers of findchild, so I'll put one findchild on each line this way

     

    MP._

    Findchild(<Stuff>)._

    FindChild(<2nd Layer Stuff>)._

    Click(X, Y)

    is equivalent to

    MP.Findchild(<Stuff>).FindChild(<2nd Layer Stuff>).Click(X, Y)

    But the broken line is a bit easier to read.

    I think there's a way to do this in every supported script language...

     

    But I haven't found a way to automate making a findchild script line.

    Perhaps these tricks can help you minimize how much you have to type, though, and make your scripts more readable to boot.