Forum Discussion

ulTam's avatar
ulTam
Occasional Contributor
8 years ago

Aside from using name mapping, how do you handle a desktop app which has hundreds of similar fields?

I'm automating a WPF application which has hundreds of fields in one screen. Now most of them are of the same type and only differ in the WPFControlName. 

 

Adding all these fields one by one and editing them in the name mapping, does not seem very efficient. 

I know that you make use of find method to dynamically create objects. I'm thinking of creating a loop that would go through perhaps an array containing the different WPFControlNames and create an object for each.

But I'm fairly new to TestComplete and scripting, and I'm not sure where I should be placing this code. Do I put it in a separate unit? I don't want to have to use the find method everytime I need to use the field/object? 

4 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    Scenario here is, You have multiple controls like textbox, combo-box and etc, in same screen. 

     

    You can use FindAllChildren method find your objects which will return the collection of object that are matched with your given properties and values.

     

    you can try something like below,

     

    function test()
    {
          var Parent = Aliases.MyMainPage;
          var propArr = new Array("JavaClassName","AWTComponentAccessibleName");
          var txtFields = new Array("JTextField","*");
          
          var arrofObjects = getAllObjects(Parent,propArr,txtFields);
          
          //You can do the rest
    }
    
    function getAllObjects(ParentObject,Props,Values)
    {
          if(ParentObject.Exists)
          {
                return ParentObject.FindAllChildren(ParentObject,Props,Values);  
          } 
    return new Array(); }
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Correct, mapping all those components is a pain sometimes... but you only ever have to do it once and then they are identified and available for use in any test.  Generally speaking, this is going to execute faster as well.  Running script code to find your components means you're doing two things that are going to slow down your execution.  First, you're running interpreted script code which will take longer than compiled internal methods (like NameMapping). Secondly, any "Find" method is going to take execution time.

     

    What you're talking about doing, though, is something akin to a Page Object Model where you build a code unit whose only purpose is to identify a component and return it to the rest of the application.  It can be done... but you're reinventing the wheel.  You'd have to write the code to identify all the components... might as well map them. 

    • liquidphantom's avatar
      liquidphantom
      Occasional Contributor

      I have a VB6 app to deal with that is still being developed (don't ask) that has gone waaaaay beyond the number of controls limit on a form, using picBoxs etc. These controls change their names pretty much every build so no good mapping them.

       

      I had to write a function using 'FindChild' to find a child object of one of it's containers by a partial of it's name and it's index value. Then for each action call this function.

       

      Sometimes pre-mapping all the objects isn't an option.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        liquidphantom wrote:

        I have a VB6 app to deal with that is still being developed (don't ask) that has gone waaaaay beyond the number of controls limit on a form, using picBoxs etc. These controls change their names pretty much every build so no good mapping them.

         

        I had to write a function using 'FindChild' to find a child object of one of it's containers by a partial of it's name and it's index value. Then for each action call this function.

         

        Sometimes pre-mapping all the objects isn't an option.


        Wow... well, yeah, in that case, definitely need to find some other way around... but that's assuming that the "Name" property is the only property that matters for mapping.  I'm working with an application right now that has a LOT of components that, for the most part, look almost exactly the same in the Object browser with regards to the VB6 name property... however, using things like "WndCaption" or other similar values, we've found a way to uniquely map the objects... it takes a bit more work than just using the Name, but it does eventually work...

         

        ... but suffice it to say, you're experience is one where, perhaps, using an alternative method may be better.... or, sit down with the development staff and say, "Hey, ya know...  my automation is here to help you... but it's a bit difficult to do this with the dynamic factors you've introduced.  Can we establish some sort of identification methodology to enable the automation to work better?"... of course, this implies that your developers see the test automation as a benefit... but that's another story. :)