Stable Identifiers

A stable identifier for a UI control is an identifier that does not change between invocations of the control and between different versions of the application, in which the UI control exists. A stable identifier needs to be unique in the context of its usage, meaning that no other control with the same identifier is accessible at the same time. This does not necessarily mean that you need to use GUID-style identifiers that are unique in a global context. Identifiers for controls should be readable and provide meaningful names. Naming conventions for these identifiers will make it much easier to associate the identifier to the actual control.

Example: Is the caption a good identifier for a control?

Very often test tools are using the caption as the default identifier for UI controls. The caption is the text in the UI that is associated with the control. However, using the caption to identify a UI control has the following drawbacks:
  • The caption is not stable. Captions can change frequently during the development process. For example, the UI of the AUT might be reviewed at the end of the development process. This prevents introducing UI testing early in the development process because the UI is not stable.
  • The caption is not unique. For example, an application might include multiple buttons with the caption OK.
  • Many controls are not exposing a caption, so you need to use another property for identification.
  • Using captions for testing localized applications is cumbersome, as you need to maintain a caption for a control in each language and you also have to maintain a complex script logic where you dynamically can assign the appropriate caption for each language.