background image
<< Porting Tests - type statements | Porting Tests - Conditional compilation >>
Porting Tests - With global variables
<< Porting Tests - type statements | Porting Tests - Conditional compilation >>
268
User's Guide
13 P
ORTING
T
ESTS
TO
O
THER
GUI
S
Marking 4Test code as GUI-specific
// the msw class or the mac class?
The preceding example's ambiguity can be resolved by specifying a GUI
target with conditional compilation (so that, for example, only code for
msw gets compiled, in which case inst would be an instance of the msw
class myclass--conditional compilation is described next) or by
explicitly using a GUI specifier for the window, as follows:
// good style:
msw winclass myclass
mac winclass myclass
msw window myclass inst
With inheritance
When using GUI specifiers for parent classes, you must explicitly use the
GUI specifiers with the descendants:
msw95 winclass newclass
msw95 winclass subclass : newclass
msw95 window subclass inst
With global variables
Be careful when using GUI specifiers with global variables: SilkTest
initializes global variables before connecting to an Agent. This might not
give you the results you want if you are doing distributed testing.
Let's say that you are running tests on a remote machine that is listed in
Runtime Options. Because SilkTest initializes all global variables before
connecting to an Agent, any GUI specifier at the global level will initialize to
the host machine, not the target machine you want to test against.
For example, say the host machine is running Window 95 and the target
machine is running Windows NT 4.0. Consider the following script:
mswnt40 STRING sVar1 = SYS_GetEnv("UserName")
msw95 STRING sVar1 = SYS_GetRegistryValue
(HKEY_LOCAL_MACHINE,
"System\CurrentControlSet\Control",
"Current User")
main()
print(sVar1)
This script fails, with the error message
*** Error: Registry entry 'Current User' not found
because sVar1 is initialized to the value for the host system (the GUI specifier
msw95), not the target system (mswnt40).
So, if you want GUI specifiers on variables at the global level, put the
initialization of these variables in the main function or another function that
is called after the Agent is contacted.