background image
<< Class Hierarchy - Defining new attributes | Class Hierarchy - Defining new classes >>
Class Hierarchy - Default Button attribute
<< Class Hierarchy - Defining new attributes | Class Hierarchy - Defining new classes >>
312
User's Guide
16 E
XTENDING
THE
C
LASS
H
IERARCHY
Defining new attributes
Here is the 4Test code in the winclass.inc file that implements the Default
Button attribute:
attribute "Default button", VerifyDefaultButton, QueryDefaultButton
As this 4Test code examples shows, each attribute definition begins with the
attribute statement, followed by three comma-delimited values:
1
The text that you want to appear in the Attribute panel of the Verify
Window dialog. This text must be a string.
2
The method SilkTest should use to verify the value of the attribute at
runtime.
3
The method SilkTest should use to get the actual value of the attribute at
runtime.
Syntax
To add one or more attributes to an existing class, use the following syntax:
winclass ExistingClass : ExistingClass...
attribute_definitions
Each attribute definition must begin and end on its own line.
When you define a new attribute, you usually need to define two new
methods (steps 2 and 3 above) if none of the built-in methods suffice.
For example, to add a new attribute to the DialogBox class that verifies the
number of children in the dialog, you add code like this to your test frame (or
other include file):
winclass DialogBox:DialogBox
attribute "Number of children", VerifyNumChild, GetNumChild
integer GetNumChild()
return ListCount (GetChildren ()) // return count of children of dialog
hidecalls VerifyNumChild (integer iExpectedNum)
Verify (GetNumChild (), iExpectedNum, "Child number test")
As this example shows, you use the hidecalls keyword when defining the
verification method for the new attribute.
About the hidecalls keyword The keyword hidecalls hides the method
from the call stack listed in the results. Using hidecalls allows you to update
the expected value of the verification method from the results. If you don't
use hidecalls in a verification method, the results file will point to the frame
file, where the method is defined, instead of to the script. We recommend that
you use hidecalls in all verification methods so you can update the expected
values.