Forum Discussion

ringraham's avatar
ringraham
Contributor
9 years ago
Solved

TestComplete adds number to WPF object

We have a WPF desktop app where some of the object names are having numbers added to them.  For instance, when you record a test and create a CheckProperty test, it saves the objects name as:

 

hwndSource.MainWindow.Grid.AdornDecorator.PaneLayoutControl.PanePresenter.TestGridPaneView[x]

where [x] is a single digit numeric.

 

It has only happened with the Views that contain grids. In writing test scripts, I started noticing these different numbers being added. When trying to playback these scripts, they quite often fail because the grid object has a different number than what the script is calling for and the key tests also fail for this same reason. The thing is these objects should not have any number assigned to them. I'm assuming this is from "something" trying to disambiguate the names, but I'm not quite sure why it would do this, but not provide a mechanism to retrieve the name. If you look at the PanePresenter's Context or DataContext, this name doesn't appear anywhere.

 

It appears to be something added when the app is run and there is no mechanism in our code to come up with such names. Not sure if this is being done by the .Net runtime or by TestComplete.

 

Has anyone else ever heard of this issue and, more importantly, is there a way to get the name at runtime?

 

Thanks.

 

-Ron

 

  • Hi Ron, 

     

    I don't know if this is the same but i've had something like this.

    Our view are generated dynatmically and can have more than one type open at the same time. As well diferent 'version' of teh view also exist and those also can exist multiple times on screen.

     

    I dont know if this will fix your problem but replace the [x] number with *

    other option if you are trying to locate the view via script codes, try using the Find() or FindChild() and use the property "ClrFullClassName"

     

     

    parent.findChild("clrFullClassname","TheFullClassNameOfTheObject",depth)

     

    also to becareful that if you have more than one object, both of these will return the first instance only.

     

    there's also the parent.FindAllChildren("clrFullClassName","thefullclassname",depth)

    and check if you have more than one  using ubound() on the array

     

    .. sorry these are vbscript codes

     

     

     

     

9 Replies

  • finae's avatar
    finae
    Contributor

    Hi Ron, 

     

    I don't know if this is the same but i've had something like this.

    Our view are generated dynatmically and can have more than one type open at the same time. As well diferent 'version' of teh view also exist and those also can exist multiple times on screen.

     

    I dont know if this will fix your problem but replace the [x] number with *

    other option if you are trying to locate the view via script codes, try using the Find() or FindChild() and use the property "ClrFullClassName"

     

     

    parent.findChild("clrFullClassname","TheFullClassNameOfTheObject",depth)

     

    also to becareful that if you have more than one object, both of these will return the first instance only.

     

    there's also the parent.FindAllChildren("clrFullClassName","thefullclassname",depth)

    and check if you have more than one  using ubound() on the array

     

    .. sorry these are vbscript codes

     

     

     

     

    • ringraham's avatar
      ringraham
      Contributor

      The "replace objectName[x] number with *" idea did not work. As suspected, it generates a syntax error in C# script. But when I saw the FindChild method, the light clicked on. Even though the names showing up in the debugger have the numbers after them, doing a FindChild("clrClassName", "objectName", 0) works. I don't understand why it is adding the numbers to begin with? I assume it is trying to do some kind of disambiguation, but not sure why. Since each of these is in a unique parent container, the object names would not duplicate.

       

      While this did indeed solve my immediate problem, I'd sure like to know where these numbers are coming from??  If it is indeed from TestComplete, why would you do this?  Note that because of this, the keyword test scripts fail. While I can fix this via script, I cannot fix this in the keyword tests that our testers create.

       

      Since we have a support contract, I will probably open a ticket on this item as well.

       

      Thanks finae for this solution.

      • finae's avatar
        finae
        Contributor

        Do becareful using teh , 0, values

        as mentioned these are WPF components created based on components 'location' as its being generated (the xaml file) should descript where they are. if the designer change teh location of the component so does the indexes that it corresponse to, so the text boxes for first name, is binded to the view in your application moved to the second location and the last name is now teh first text box created, your ,0, index will now find the last name and not the first name.

         

        hopefully that makes sense

         

        your application designer should be able to add  name to the component for you to pick up , but i m cannot say for sure on this as i am still waiting to test this out. if TC can pick up the name of the component then our designer will ahve to name all component use to make mapping of object easier and clearer for testing.