Defining which Custom Locator Attributes to Use for Recognition

The Open Agent includes a sophisticated locator generator mechanism that guarantees locators are unique at the time of recording and are easy to maintain. Depending on your application and the frameworks that you use, you might want to modify the default settings to achieve the best results and stable recognition of the controls in your application. You can use any property that is available in the respective technology as a custom attribute, given that the property is either a number, like an integer or a double, a string, an item identifier, or an enumeration value.

A well-defined locator relies on attributes that change infrequently and therefore requires less maintenance. Using a custom attribute is more reliable than other attributes like caption or index, since a caption will change when you translate the application into another language, and the index might change when another object is added.

In xBrowser, WPF, Java SWT, and Swing applications, you can also retrieve arbitrary properties, such as a WPFButton that defines myCustomProperty, and then use those properties as custom attributes. To achieve optimal results, the application developers can add a custom automation ID to the controls that you want to interact with in your test. In Web applications, the application developers can add an attribute to controls that you want to interact with, such as <div myAutomationId=”my unique element name” />. This approach can eliminate the maintenance associated with locator changes. Or, in Java SWT, the UI developer can define a custom attribute, for example testAutomationId, for a widget that uniquely identifies the widget in the application. You can then add that attribute to the list of custom attributes, in this case testAutomationId, and you can then identify controls by that unique ID. This approach can eliminate the maintenance associated with locator changes.

If more than one objects have the same custom attribute value assigned, all the objects with that value will be returned when you call the custom attribute. For example, if you assign the unique ID loginName to two different text boxes, both text boxes will be returned when you call the loginName attribute.

To define which custom attributes of a locator should be used for the recognition of the controls in your AUT:
  1. Click Options > Recorder and then click the Custom Attributes tab.
  2. From the Select a tech domain list box, select the technology domain for the application that you are testing.
    Note: You cannot set custom attributes for Flex or Windows API-based client/server (Win32) applications.
  3. Add the attributes that you want to use to the list. If custom attributes are available, the locator generator uses these attributes before any other attribute. The order of the list also represents the priority in which the attributes are used by the locator generator. If the attributes that you specify are not available for the objects that you select, Silk Test Classic uses the default attributes for the application that you are testing. Separate attribute names with a comma.
  4. Click OK. You can now record or manually create a test case.