Forum Discussion

mustafa_openTAS's avatar
mustafa_openTAS
New Contributor
19 days ago
Solved

Using ControlID for More Stable Desktop UI Tests in TestComplete

Hi SmartBear Team,

Weโ€™re currently working on improving the stability and maintainability of our automated desktop tests using TestComplete for our application, OpenTAS. To reduce object recognition issues and make our tests more robust, weโ€™re considering implementing unique ControlIDs (or similar identifiers like AutomationId) across the UI. How does TestComplete support using ControlID for identifying desktop UI elements?

We tried to interact by using the testcomplete documentation info but it didn't work (see below)

Best regards,
Mustafa 

Button Full path= Sys.Process("OpenTAS").WinFormsObject("frm5101Main").WinFormsObject("ImplicoDocumentsHost", "", 1).WinFormsObject("DocumentContainer", "").WinFormsObject("DockPanelForMdi", "PRE-Release - 621 - Service Order").WinFormsObject("_Container").WinFormsObject("Form0621XCustomerOrder").WinFormsObject("actionBar").WinFormsObject("tableLayoutPanelHorizontal").WinFormsObject("ActionBarButtonControl", "", 3).WinFormsObject("btnBack")

The way how I tried to click but didn't work:

// btn control ID = 1511736

function ClickButtonByControlId()
{
  var app = Sys.Process("OpenTAS");
  var win = app.WinFormsObject("frm5101Main", "*", 1);
  var btn = win.FindChild("ControlId", 1511736, 1); // Example ID
  if (btn.Exists)
    btn.Click();
  else
    Log.Error("Button not found.");
}

  • Hi,   Yes TestComplete supports what you are doing very well.  This is my preferred method of object recognition. Have you tried increasing your search depth to 10 or 12?  It looks like your target object is several layers deep from the parent you have specified.  To further define your target multiple properties and values can be used in an array format.  

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findchild-method.html 

    TestObj.FindChild(PropNamesPropValuesDepthRefreshTree)

    TestObjA variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
    PropNames[in]   Required   Variant   
    PropValues[in]   Required   Variant   
    Depth[in]   Optional   IntegerDefault value: 0   
    RefreshTree[in]   Optional   BooleanDefault value: True   
    ResultObject

    ... If you find my posts helpful drop me a like! ๐Ÿ‘ Be sure to mark the best answer if you get one to help others out and to credit the one who helped you.  ๐Ÿ˜Ž

4 Replies

  • scot1967's avatar
    scot1967
    Icon for Champion Level 1 rankChampion Level 1

    Hi,   Yes TestComplete supports what you are doing very well.  This is my preferred method of object recognition. Have you tried increasing your search depth to 10 or 12?  It looks like your target object is several layers deep from the parent you have specified.  To further define your target multiple properties and values can be used in an array format.  

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findchild-method.html 

    TestObj.FindChild(PropNamesPropValuesDepthRefreshTree)

    TestObjA variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
    PropNames[in]   Required   Variant   
    PropValues[in]   Required   Variant   
    Depth[in]   Optional   IntegerDefault value: 0   
    RefreshTree[in]   Optional   BooleanDefault value: True   
    ResultObject

    ... If you find my posts helpful drop me a like! ๐Ÿ‘ Be sure to mark the best answer if you get one to help others out and to credit the one who helped you.  ๐Ÿ˜Ž

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    It's worth you and your developers read through About Open Applications. It's best to avoid using numbers to reference an object, as 1511736, could mean anything!

    This is a better way of identifying an object, as reading the code clearly indicates that you are searching for the "back button"

    win.FindChild("Name", "WinFormsObject(\"btnBack\")", 20);

     

    • scot1967's avatar
      scot1967
      Icon for Champion Level 1 rankChampion Level 1

      I prefer to use identifiers in tandem with a second property if dev makes them available.  This adds to the identification being unique.  Apps can have several btnBack objects along the same path.  Testing does not need to do so much work to ensure a parent object is chosen where no duplicate objects could be found and Dev does not have to be quite so creative with their names to help out testability.  

      That said a number alone is not a very good practice to use with regard to test code maintenance and troubleshooting.

      ... It also worth saying you should ensure dev isn't allowing the ControlId to auto-generate.  This would allow the value to possibly change between builds.