Forum Discussion

Mario_Alberts's avatar
Mario_Alberts
New Contributor
15 years ago

Create Automated Tests that are Resistant to Changes in the UI

Object 1 was changed to Object 2 and my script fails now.   The article below describes this scenario; how do I provide unique names so that my script will always run?


1). Aliases.MyApplication.frmCustomerLookup.grpPhoneSearch.pbPhoneNumber.RegExTextBox


2).Aliases.MyApplication.wndWindowsForms10Window8app033c0d9d.WindowsForms10Window8app033c0d9d.Item.Item2


"Automated tests created with scripts or keyword tests are dependent on the application under test. The user interface of the application may change between builds, especially in the early stages. These changes may affect the test results, or your automated tests may no longer work with future versions of the application. The problem is automated testing tools use a series of properties to identify and locate an object. Sometimes a testing tool relies on location coordinates to find the object. For instance, if the control caption or its location has changed, the automated test will no longer be able to find the object when it runs and will fail. To run the automated test successfully, you may need to replace old names with new ones in the entire project, before running the test against the new version of the application. However, if you provide unique names for your controls, it makes your automated tests resistant to these UI changes and ensures that your automated tests work without having to make changes to the test itself. This also eliminates the automated testing tool from relying on location coordinates to find the control, which is less stable and breaks easily."

17 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Then most definitely you're dealing with this scenario:  



    2)  The component has certain dynamic properties (ID, name, etc) that need to be accounted for in the mapping.  I suspect that this is the case with your situation.  You'll need to either use a different set of criteria to be able to uniquely identify FarmaProForm so that it does not have to be changed frequently, or you'll need to modify your existing criteria (with wildcards, conditional mode, required children, etc), to make it more flexible.




    As indicated, you will need to edit the criteria for FarmaProForm to accommodate the dynamic properties with wildcards (the asterisk character for the most part (*)) or to use different criteria than what was automatically generated when you first recorded/created your test.



    Again, if you can provide screenshots demonstrating the form you are working with, what is currently being used in the mapping of that form (in this case, FarmaProForm), and the list of available properties for that form, it will be easier to provide you with more specific help.
  • I was trying to record a test with the srtange names, but they are no longer generated, what I get it's just the following message when trying to run the test.





    An error occurred while calling the "Keys" method or property of the "m_txtSearch"
    object.

    The object or one of its parent objects does not exist.


    Tested Object













    Alias: Aliases["FarmaPro"]["FarmaProForm"]["m_panel1"]["m_splitContainerBottom1"]["SplitterPanel1"]["Naviger1"]["m_searchControl1"]["m_txtSearch1"]
    Mapping item: NameMapping["Sys"]["FarmaPro"]["FarmaProForm"]["m_panel1"]["m_splitContainerBottom1"]["SplitterPanel1"]["Naviger1"]["m_searchControl1"]["m_txtSearch1"]

    Missing Object













    Alias: Aliases["FarmaPro"]["FarmaProForm"]
    Mapping item: NameMapping["Sys"]["FarmaPro"]["FarmaProForm"]
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    if you can provide screenshots demonstrating the form you are working with, what is currently being used in the mapping of that form (in this case, FarmaProForm), and the list of available properties for that form, it will be easier to provide you with more specific help.




    As for your particular problem you just posted about, that could still be a problem with it not able to find the form because of dynamic properties.  If the mapping of FarmaProForm doesn't match the properties of the actual object on playback, you'll get that kind of error.



    However, another possibility is that, on playback, the form in question may not be displayed by the time you try to execute the keys method.  If there is a delay between running your application and having the form display, you need to make sure you add to your tests some sort of code to specify that it wait until the form exists.  The best way to do this, in your case, is to add to your tests the WaitAliasChild method so that, after running the application, you wait for the form to appear before you move on.  Something like





    TestedApps.FarmaPro.Run()

    while (!Aliases.FarmaPro.WaitAliasChild("FarmaProForm", 500).Exists)

    {

        Delay(500)

    }




    That's a quick and dirty example that will probably need to be tweaked and/or modified to the specifics of your test project but, hopefully, you get the general idea.
  • New things are hapenning. I see the screenshot.



    I tried to record the steps failing again and the new object names generated are WinFormsObject("FarmaProForm") -> WinFormsObject("m_txtSearch) and the old names were FarmaProForm -> m_txtSearch.



    These new names are not in the NameMappings file.

    I before recording with these new names I deleted the names WindowsBlaBlaBla from NameMappings file.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Again, I cannot help you get the old names to be usable in your tests if you don't provide me with the information requested.
  • Since I asked for help in official support and I didn't get it let's try again from here.



    What information exactly do you want? Remember I cannot post here sensitive code data because that information is private to the company.



    Cheers,

    Miguel
  • I'm very disappointed with the help on this forum and with the official support which gave me no answer and it has passed the whole weekend.



    Suddenly instead of generating names like window001002 it started generating the good names like FarmaProForm.



    Suddenly and Miraculously.



    And this was the solution I had to implement: record the test again.



    The executable file is the same, so there were no changes to the code.



    And your help here was understandable.