Forum Discussion

pretzelz's avatar
pretzelz
Occasional Contributor
13 years ago

Why does name mapping forget?! After software restart.

Hello community,



I may be able to solve some of my problems if I can gather the answer to this, so I'm posting it in a different thread to my previous.



When I record macros with name mapping enabled, for a start it seems to have generally better compatibilty in terms of being able to accurately play back the various clicks and drags etc that I recorded. However.....  I have found that if I leave test complete open, but restart my software, the name mapping is no longer valid and the code won't execute.





For example:  I record a macro which involves clicking one static button on a static interface. The following code is generated:




  var stackPanel;

  stackPanel = Aliases.EXEFramework.HwndSource_LayoutManagerWindow.LayoutManagerWindow.Grid.Viewbox.ModuleBar.StackPanel;

  stackPanel.LitRadioButton.Click(48, 31);





I run the code - it plays back clicking the button.





A little while later, I decide to restart my software for one reason or another (perhaps my software is running a little sluggishly). I load it back up to exactly the same state it was in previously. (full screen, static interface)



I run the previously working code.



I get "waiting for the LitRadioButton object" during runtime. Then the Update Name Mapping Screen with Test Object Not Found.



I would love a solution as to why?  My entire project will be big, so I can't keep restoring broken links in the name mapping on every restart of TC and my software. Why can't TC remember the buttons it previously assigned names to using its own system?



Many thanks!




5 Replies

  • pretzelz's avatar
    pretzelz
    Occasional Contributor
    I would really appreciate if someone from SmartBear could offer an answer on this one, as I'm trialling TestComplete at the moment and need to understand more about this problem and how to move past it. Many thanks.
  •  


    Hello David,

    The problem you describe can happen if recognition parameters TestComplete uses to map your button are not stable, for example, if one of the properties used to recognize your button changes its value every time you restart your application under test.

    Could you please open the Name Mapping editor in TestComplete and check what properties and values are used to identify your button?

    You can try to change your button's mapping criteria as described in the [url= http://support.smartbear.com/viewarticle/28732/]"Modifying Mapping Criteria"[/url] section of the TestComplete Help system.

    Please let us know if this does not help.

    Thank you.
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 2 rankChampion Level 2
    Hi David,



    In addition to Julia's answer, I would like to add my two cents. :) (This also will be relevant to your http://community.smartbear.com/forum/post/?mode=singleThread&thread=292c9e02-30b5-45c6-9f32-9056da5e88d7 thread and Stephanie's comment.)



    The problem you are seen is quite common for the software developed using certain technologies and development patterns. One of the worst cases I've seen so far was with .Net WPF technology and view-controller model.

    The case is that such software generates UI controls during runtime and does not assign unique names (IDs) to the generated controls. This results that instead of using these IDs to map controls within the NameMapping scheme and use them later to identify controls during test run, TestComplete resorts to secondary NameMapping algorithm/method/template scheme. This secondary approach uses Window Class, Window Title and Index properties as identification criteria for the control. And here is the trap: the case is that usually dynamically generated controls of the same type (e.g. buttons) have the same Window Class and the same (usually empty) Window Title. And this is not TestComplete's fault, but the same problem will exist for any tool just because Window Class and Window Title are system properties assigned by the operating system (OS). So the Index property appears to be the only one left that makes it possible to distinguish one control from another of the same type (e.g. one LitRadioButton button from another one). But the Index property is a dynamic 'artificial' one that indicates the order in which controls of the same type were created during runtime, i.e. it is not persistent and may (and usually does for the dynamically generated controls) change between different runs of the tested application.

    For example, from the user point of view, your software may have two buttons with OK and Cancel labels on top (not captions, but for the end user looking like button's caption!). But within the software these buttons may be identified as Button('LitRadioButton', '', 1) for the OK and Button('LitRadioButton', '', 2) for the Cancel button during the first run, but for the second run the order or their generation may change with the result that OK button will be identified as Button('LitRadioButton', '', 2) and Cancel as Button('LitRadioButton', '', 1). Obviously this will break your tests.

    To make the situation even worse, WPF applications are using a lot of panels with the same Class name and empty Title inserted by the runtime engine.



    The best approach to overcome the above problem is to talk with Development and ask them to assign unique ID to every UI element that your tests need to interact with. But the talk may be not successful because: a) Development may not need ID for some controls and thus forget to assign ID to this control; and, more serious, b) assigning IDs to controls may contradict to some development patterns used to develop the given software (for example, the mentioned view-controller model) and Development may refuse to break the pattern.



    One of the best Best Practices :) I've met was recommendation from Christian Ekiza (http://blog.smartbear.com/software-quality/bid/169929/) posted here several years ago. He recommended not to record the test from scratch and let TestComplete to generate NameMapping according to its default algorithms, but instead execute the test manually, without recording and examining every UI control used in the test in TestComplete's Object Browser. The goal of this examination is to identify what properties are accessible from the Object Browser for this or that control and what properties have unique and stable values that can be used for reliable control's identification. Once such properties are identified, the new NameMapping template (mentioned in Julia's message) should be created and only then you may record the test.



    One more possible approach is to use the recorded test (recorded as a script, but not as a keyword test) as a skeleton and use different Findxxx() functions (e.g. FindChild, FindNamedChild, etc. -- see TestComplete's help for more details) to search for the needed controls.



    I would recommend the 'Creating Reliable Tests For Dynamic Objects with Name Mapping' (http://support.smartbear.com/support/screencasts/testcomplete/reliable-tests-for-dynamic-objects/) video from the TestComplete Webinars and Videos page (http://support.smartbear.com/screencasts/testcomplete/) - it might inspire you with better understanding of what's going on behind the scenes in the tested application and ideas of how this may be solved for your particular tested application.
  • pretzelz's avatar
    pretzelz
    Occasional Contributor
    Thank you both for your feedback, and particularly Alex for your detailed response to this issue. I did have a discussion with one of the developers yesterday and we talked about this issue, but your post will help shed much more light on it.



    I have, as it happens, found a solution to the problem. I originally used name mapping as I found it more reliable to open submenus etc without a problem, when compared to non-name mapping. However now, I have a solution as to why non-name mapped playback suffered so many issues. I found that if I record macros (not LLP) very slowly, hovering at least 6 seconds over a button before pressing (and waiting for the hover caption bubble to disappear) then TC records more code for that action! And thus, it works!



    Thank you again both for your insight into the name mapping issue. We'll continue to review that one since it helps understand the nature of our software and some of the automated testing issues we may face with it.



    Having conquered some ground yesterday with TestComplete, I've been pleased to set up some good tests to leave running finally. I'm going to start a new thread about the results, since this will obviously be the next hurdle to understand and jump in our mission to build an automated suite.

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 2 rankChampion Level 2
    Hi David,



    > [...] if I record macros (not LLP) very slowly [...]



    Yes, you mentioned a great point I missed in my reply. To make recording as fast as possible on the one hand and ensure that the correct control was a subject of the operation on the other hand, personally I prefer (after recording is started and recording toolbar (http://support.smartbear.com/viewarticle/33275/) is visible) to click on the down-triangle button on the right of the recording toolbar so that the Parent Name and Object Name edit boxes are visible and use them to control that TestComplete had enough time to 'understand' what control is going to be used and thus recorded correct action over expected control.