You can create custom classes for custom controls for which
Silk Test Workbench does not offer any dedicated support. Creating custom classes offers the following advantages:
- Better locators for scripts and visual tests.
- An easy way to write reusable code for the interaction with the custom control.
Example: Testing the
UltraGrid Infragistics control
Suppose that a custom
grid control is recognized by
Silk Test Workbench as the generic class
Control. Using the custom control support of
Silk Test Workbench has the following advantages:
- Better object recognition because the custom control class name can be used in a locator.
- Many objects might be recognized as
Control. The locator requires an index to identify the specific object. For example, the object might be identified by the locator
//Control[13]. When you create a custom class for this control, for example the class
UltraGrid, you can use the locator
//UltraGrid. By creating the custom class, you do not require the high index, which would be a fragile object identifier if the application
under test changed.
- You can implement reusable playback actions for the control in scripts.
-
When you are using custom classes, you can encapsulate the behavior for getting the contents of a grid into a method by adding
the following code to your custom class, which is the class that gets generated when you specify the custom control in the
user interface.
Typically, you can implement the methods in a custom control class in one of the following ways:
- You can use methods like
Click,
TypeKeys,
TextClick, and
TextCapture.
- You can dynamically invoke methods on the object in the AUT.
- You can dynamically invoke methods that you have added to the AUT. This is the approach that is described in this example.
You can use the following code to call the static method that is defined in the example in
Adding Code to the Application Under Test to Test Custom Controls. The method
GetContents is added into the generated class
UltraGrid.
' VB code
Partial Public Class UltraGrid
Public Function GetContents() As IList
Return Invoke("UltraGridUtil.GetContents", Me)
End Function
End Class
When you define a class as a custom control, you can use the class in the same way in which you can use any built-in class,
for example the
Dialog class.
' VB code
Dim ultraGrid As UltraGrid = mainWindow.UltraGrid("@automationId='my grid'")
Dim contents = ultraGrid.GetContents()