Home > Enterprise >  Where does MFC get the Automation IDs from?
Where does MFC get the Automation IDs from?

Time:03-16

I am about to add automatic GUI tests to an MFC application (created with Visual Studio 2019). It seems as AutomationId is something that could be useful when identifying various child windows in the application.

When I examined the application using Microsoft’s tool “Visual UIA Verify” I noticed that most of the child windows in the application have AutomationIds.

My concern is that they might not be unique if I have multiple instances of a window class and that the IDs may change over time.

My questions are

  • Where do the AutomationIds come from?
  • Can I change them?
  • Can I rely on them being constant?

CodePudding user response:

If I'm not mistaken, the automation id is just the control id for the window's child control.

This is automatically set for controls in dialogs loaded from a resource (.rc file). The control id can also be set at runtime for non-dialog controls by passing a number for the HMENU parameter in CreateWindow. So yes, you can typically assume the control IDs are static.

CodePudding user response:

Automation IDs are obtained from UIA (User Interface Accessibility), you should generally be able to count on them being the same from run-to-run of the same program, but note that a new version may or may not be "the same".

From the UIA documentation:

Identifies the AutomationId property, which is a string containing the UI Automation identifier (ID) for the automation element. When it is available, the AutomationId of an element must be the same in any instance of the application, regardless of the local language. The value should be unique among sibling elements, but not necessarily unique across the entire desktop. For example, multiple instances of an application, or multiple folder views in Microsoft Windows Explorer, can contain elements with the same AutomationId property, such as "SystemMenuBar". Although support for AutomationId is always recommended for better automated testing support, this property is not mandatory. Where it is supported, AutomationId is useful for creating a test automation script that runs regardless of the UI language. Clients should make no assumptions regarding the AutomationId values exposed by other applications. AutomationId is not guaranteed to be stable across different releases or builds of an application.

  • Related