You can use the Function search method to create a custom algorithm that locates controls that are stored in the application repository during playback. For example, you can use a search algorithm that includes and/or conditions. The function is executed during recording and playback and must return True to locate the control.
You may want to use the Function search method if a control is not located after you:
Note: Only use the Function method if you are familiar with creating functions and understand how changing search options can impact scripts. Scripts will not work if you use this search method incorrectly.
Creating the search function
1. Select a window or control in the Application Repository pane and choose File > Properties.
The Properties dialog box opens with the Search Method tab selected.
2. Select Function from the Search method list. The following code is automatically added to declare the function:
Function ControlName(controlData)
End Function
3. Add the function to use to locate the control.
4. Click OK to save the function.
ContainsRuntimeValue statement
Returns True or False to indicate if a property is defined for a control.
ContainsRuntimeValue(ControlData,"PropertyDisplayName")
ControlData
The snapshot control data (properties).
PropertyDisplayName
Property display name to find.
Returns the value of a control property. Use the ContainsRuntimeValue statement first to determine if the property is defined.
GetRuntimeValue(ControlData,"PropertyDisplayName")
ControlData
The snapshot control data (properties).
PropertyDisplayName
Property display name to find.
Note: The ContainsRuntimeValue and GetRuntimeValue statements can only be used with the Function search method.
A dialog box contains an Advanced>> button, which is a .NET Windows Forms push button control. When the button is clicked, the dialog box expands with additional controls and the button is replaced by a Simple<< button. When the Simple<< button is clicked, the dialog box is restored to its original state.
When you record a script, QA Wizard Pro captures both the Advanced>> and Simple<< buttons. You want QA Wizard Pro to recognize the buttons as the same button during playback so you merge them in the application repository and change the control name to AdvancedSimple.
Use the Function search method to locate the AdvancedSimple control. The control is only located if the function returns True. The following function returns True if the value of the control's SubType property is .NET PushButton and the value of the Text property is Advanced>> or Simple<<. The function returns False if the control was not located.
Function AdvancedSimple(controlData)
isAdvancedSimple = False
subType = GetRuntimeValue(controlData, "Subtype")
hasText = ContainsRuntimeValue(controlData, "Text")
If hasText and subType = ".NET PushButton" Then
text = GetRuntimeValue(controlData, "Text")
If text = "Advanced >>" or text = "Simple<<" Then
isAdvancedSimple = True
End If
End If
Return isAdvancedSimple
End Function