Forum Discussion

stein_oddvar_ra's avatar
stein_oddvar_ra
Contributor
10 years ago
Solved

Using AfxWnd90 or AfxWnd120 to access an MFC UI-element

I've inherited an old TestComplete suite that was developed for the testing of our applications. In one of the test projects there's some interaction with the UI-elements of an application using the alias to an AfxWnd90-object.



The problem is that this object reference is to a specific MFC version (9.0 - VS2008) - we have since started to compile our applications using 12.0 (VS2013), so the object references should be changed as well to AfxWnd120.



Is there any other way of interacting with the UI-element than actually checking if the AfxWnd90 exists, and if not, use the AfxWnd120 instead?
  • Hi Stein,



    Yes Aliases, allow you to simplifiy Name Mapping (NM) paths.



    If you set a Name Mapping property with a wildcard, the corresponding Alias will automatically be updated.



    Please find attached a screenshot of the NM tab with an example of a property WndClass with a wildcard.



    Sincerely

9 Replies

  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Nope, that won't work.



    First off, the way you use Aliases is a bit confusing: if I would do a name mapping of something like AimOS.wndAfx.AfxWnd90.EventImageWindow.AfxWnd90.AfxWnd90 I would end up with a path like this: OS.MainFrame.MainWindow.EventImageWindow.Frame1.Frame2. After that the Alias would like this: OS.MainWindow.EventImageDisplay.



    Now back to the AfxWnd*. Every NameMapping, Alias have multiple properties among which you should have WndClass. That is where you will replace AfxWnd90 by AfxWnd*.



    You will then still be able to run the following to grap AfxWnd120 UI-Elements:

    afxWnd = Aliases["AimOS"]["wndAfx"]["AfxWnd90"]["EventImageWindow"]["AfxWnd90"]["AfxWnd90"];



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Stein,



    Yes Aliases, allow you to simplifiy Name Mapping (NM) paths.



    If you set a Name Mapping property with a wildcard, the corresponding Alias will automatically be updated.



    Please find attached a screenshot of the NM tab with an example of a property WndClass with a wildcard.



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    You can use Name Mapping (NM) and Aliases by strictly keeping the UI-Element path.



    To answer your question: Aliases are directly linked and depend on their respective NM. The goal of Aliases is to allow UI-Element changes without triggering a code change.



    To be specific what are the values of the Aliases WndClass property of all the UI-elements in Aliases["AimOS"]["wndAfx"]["AfxWnd90"]["EventImageWindow"]["AfxWnd90"]["AfxWnd90"] ?



    You might want to checkout the TestComplete Name Mapping documentation.



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Stein,



    Assuming that you reference the UI-Elements with the Name Mapping or some kind of function with a string value parameter, you should be able to change AfxWnd90.PathToElementX to AfxWnd*.PathToElementX.



    Sincerely
  • Interesting.



    So when I set a reference like this:



    afxWnd = Aliases["AimOS"]["wndAfx"]["AfxWnd90"]["EventImageWindow"]["AfxWnd90"]["AfxWnd90"];



    I will get it just as precise by using:



    afxWnd = Aliases["AimOS"]["wndAfx"]["AfxWnd*"]["EventImageWindow"]["AfxWnd*"]["AfxWnd*"];



    ???
  • Okay.



    To possibly clarify: The GUI-part of  the test project was built using the test recorder and then converted to code. The resulting code would look something like this:



    Aliases["AimOS"]["wndAfx"]["AfxWnd90"]["EventImageWindow"]["AfxWnd90"]["AfxWnd90"]["ClickR"](412, 257)



    Wich basically just right-clicks inside a part of the application being tested.



    This is the way the GUI-manipulation has been coded originally. I have a suspicion that this might not be the way name mapping and aliases was supposed to be used.



    Should aliases be pointers to name mappings only?
  • I have tried to get a grip on Aliases and Name Mapping.



    If I understand correctly, the Name Mapping is the pointer to the actual UI-element. It is created automatically when you record a Keyword test.



    The Alias is created at the same time, points to the Name Mapping, and will by default get the same name as the Name Mapping element. If I understand you correctly, this can be changed to whatever you want?



    I think I missed by assuming that the Alias element was somehow referring to the UI because it had much of the same name as the UI-object.



    Can I put wildcards into the Name Mapping after the Alias is created to be able to use AfxWnd90 and AfxWnd120 UI-elements?
  • Hi Simon, and thanks!



    The name-mapping wildcard seems to map to the correct UI-element.



    To summarise the problem and the solution:



    When recording a keyword test, automatic name mapping creates specific and static references to an UI-element under test. The Alias of this mapping is given the same name as the Name Mapping.



    If you convert the keyword test to code, the Alias will look like the Name Mapping.



    Name Mappings can be edited to use wildcards to achieve a more dynamic mapping of UI-elements.



    I think this have given me a better grasp of the Alias and Name Mapping part of TestComplete. It has been an intense and steep learning curve since I inherited this project. :)



    Again, thanks for the input and pointers!