Java SWT Custom Attributes

You can add custom attributes to a test application to make a test more stable. For example, in Java SWT, the developer implementing the GUI can define an attribute (for example, 'silkTestAutomationId') for a widget that uniquely identifies the widget in the application. A tester using Silk Test Workbench can then add that attribute to the list of custom attributes (in this case, 'silkTestAutomationId'), and can identify controls by that unique ID. 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 will change whenever another widget is added before the one you have defined already.

If more than one object is assigned the same custom attribute value, all the objects with that value will return when you call the custom attribute. For example, if you assign the unique ID, 'loginName' to two different text fields, both fields will return when you call the 'loginName' attribute.

Java SWT Example

If you create a button in the application that you want to test using the following code:
Button myButton = Button(parent, SWT.NONE);

myButton.setData("SilkTestAutomationId", "myButtonId");
To add the attribute to your XPath query string in your test, you can use the following query:
Dim button =
desktop.PushButton("@SilkTestAutomationId='myButton'")

To enable a Java SWT application for testing custom attributes, the developers must include custom attributes in the application. Include the attributes using the org.swt.widgets.Widget.setData(String key, Object value) method.