Forum Discussion

kevingiles's avatar
kevingiles
Occasional Contributor
4 years ago
Solved

Dynamic Object Recognition and how to use FindChild in Keyword test

Hello, everybody. I am currently assessing TestComplete as a replacement for another Automated test tool which is becoming more and more cumbersome. 

I have only a short time to complete my assessment before I have to return to "real" work and will have no opportunity to continue.

Please excuse me if I am missing the obvious as I am trying to rush things through a bit, sorry.

 

My boss will not allow us to use User Code as she feels this makes our tests difficult to maintain. Most of our testers have no programming background.

Consequently, I am trying to use Keyword Testing as much as possible. I have two problems, which I believe to be interrelated.

1. We have dynamically generated popup menus. In the other tool, we could supply a variable against one of the properties (text) to find the menu item we wanted to click. In my current keyword tests, I find an apparently fixed index number. I have read this article Testing-with-a-dynamic-built-menu-structure which indicates the use of the FindChild method may solve my issue but I would like a (pictorial?) example of how this would look in TestComplete. Step by step would be great.

I have attached a screenshot of the menu I want to be dynamic.

 

2. In a similar vein, we often have a number of objects which are dynamically placed on screen, and, in the other tool we can, again, reference these using a property such as caption which is linked to a variable at run time. I have tried using a variable against a property for these objects but at runtime, the value of the variable seems to be ignored and I get the object which was originally recorded. I wonder if FindChild will also solve this problem.

I have attached a screen shot of what I tried but even when I change the variable StepNumber1 the object selected is the same.

 

Many thanks in advance.

 

Regards to all.

  • kevingiles's avatar
    kevingiles
    4 years ago

    Hey - I have found a solution that I worked out with a suggestion from another Forum member.

    Sub ClickPopup(Category,ItemName )
      Dim MyDiagram
      Set MyDiagram= Aliases.ClientHost.HwndSource_ProcessEditor.ProcessEditor.tabControl.myDiagram
      Call MyDiagram.ClickR(223, 369) ' Will make this a parameter eventually
      Call MyDiagram.PopupMenu.Click("New|" + Category)
      Dim FoundEntry
      Set FoundEntry = NameMapping.Sys.ClientHost.FindChild("text",ItemName,100) ' ClientHost is the application main window
      FoundEntry.Click()


    End Sub

     

    Thanks for the hints and help from rushikesh.

6 Replies

  • Wamboo's avatar
    Wamboo
    Community Hero

    Hello,

    If I can suggest it, talk to your boss about creating automation scripts by writing code rather than recording elements on the screen.

     

    There are a lot of questions about the choice of working method:


    1. how big application do you plan to cover with tests?
    When working with keywordTest, you are using a very strong functionality called "NameMapping". Only selected elements should be added to this repository, not everything. Too large a NameMapping file will cause optimization problems in the future.

     

    2. Maintaining and modifying the tests.
    If your test scenarios are modified frequently, choose the scripting method with no keyword. It will be easier to maintain and create common libraries.

     

    3. working together on the project and storing files in the repository.
    By choosing the scripting method, it will be easier to divide the work into individual team members.

     

    Searching for dynamic elements:

    In TestComplete you can choose between different methods .Findxxx(),

    One of them is the FindChild() method you mentioned.

     

    An example from Javascript:

     

    // variable
    var object = Aliases.program.object;

     

    // in the object you have in the variable you can search for the elementvar searched forObject = object.FindChild("property name", "property value", nesting)

     

    // to the above-mentioned variable I'll save the object to be searched.

     

    Inside the keyword test, Yo can actually write a function to perform some action.

     

    If you open a tab called "Object browser" in TestComplete you will see all the elements that you can potentially map to Aliases and search by .Findxxx()

    On the forum, we have already talked many times about topics related to starting work with TestComplete. Please check it:

     

    https://community.smartbear.com/t5/TestComplete-Desktop-Testing/NameMapping-Alias-and-find-function/td-p/187593

     

    https://community.smartbear.com/t5/TestComplete-Desktop-Testing/NameMapping-Alias-and-find-function/td-p/187593

     

     

    • kevingiles's avatar
      kevingiles
      Occasional Contributor

      Ok,

      I have stated that my boss does not want user code. I understand your frustration that I don't just do it with a bit of script but I AM NOT PERMITTED TO and, believe me, I have argued my point frequently.

       

      so what have I tried?

      I have found that I can get a child item within a Keyword test into a variable of type object. (Can't prove this works yet due to the point below.)

      How do I then click on the object which is now in the variable?

       

      Note that I really want to find the object with the text "New" somewhere within the popup menu which appears after the ClickR on bpa Diagram but, by the time I get back to TestComplete the menu is gone.

      If I do a recording it does say Popup menu is the Item/Object but this is not in the name mapper as far as I can see.

       

      I have attached a screenshot of how far I have got but what do I select as the new operation in the keyword test in order to get a click? I have tried On-Screen Action but if I select the variable for it to act upon (which contains the object from the previous Set variable step) it then says that this has no operations.

       

      Screenshot of the test attached.

       

      I did also try to create a new mapping and, somehow, I go a tree down to the first level of menu. however, my menu could be multiple levels (3 currently) and I would like to find the child with a certain name at any point in the tree. SO I suppose I would use FindChild on the root level of the menu.

      Also attached a picture of this.

       

      Thanks to anyone who can help.