How to Program with Tsl in Winrunner (1)
Introduction To WinRunner Basics
(Continued from previous question...)
How to Program with Tsl in Winrunner (1)
User can easily add functions to the test scripts using WinRunner’s visual programming tool, the Function Generator.
The Function Generator provides a quick, error-free way to program scripts. Function Generator helps the user to
Add Context Sensitive functions that perform operations on a GUI object or get information from the application being tested.
Add Standard and Analog functions that perform non-Context Sensitive tasks such as synchronizing test execution or sending user-defined messages to a report.
Add Customization functions that enable users to modify WinRunner to suit the testing environment.
User can add TSL statements to the test scripts using the Function
Generator in two ways: by pointing to a GUI object, or by choosing a function from a list. If the user selects the Insert Function command and point to a GUI object, WinRunner suggests an appropriate Context Sensitive function and assigns values to its arguments. User can accept this suggestion, modify the argument values, or choose a different function altogether. If the user has pointed to an object that is not in the GUI map, the object is automatically added to the temporary GUI map file when the generated statement is executed or pasted into the test script.
Modifying the Default Function in a Category
In the Function Generator, each function category has a default function. When the user generates a function by clicking an object in the application, WinRunner determines the appropriate category for the object and suggests the default function. If the user wants to frequently use a function other than the default user can make it the default function. User can set as default from the Function Generator which remains the default function in its category until it is changed or until the end of the WinRunner session. User can permanently save changes to the default function setting, by using TSL function
generator_set_default_function (category_name, function_name);
ategory_name An existing category.
function_name An existing function.
The generator_set_default_function function is used exclusively with the Function Generator. It sets a default function for a category in the utility. If the user does not define a default function, WinRunner automatically chooses the first function in the list as the default function.
The called test must be stored in the same directory as the main test or include a full pathname within quotation marks. Alternatively, the called test can be stored in a directory specified in the search path. To set the search path for called tests, choose Tools > General Options > Folders category, or use the corresponding search path testing option with the setvar function. User can parameterize a call statement using the eval function in order to call several tests and the relevant parameters for each within a single call loop. The call statement is not a function. Therefore, it does not appear in the Function Generator. User can use the call statement from a test to call other WinRunner tests. User can use the call statement from a scripted component to call other scripted components. User cannot call a scripted component from a test or vice versa. The call statement opens and runs a test or scripted component from within another test or scripted component.
call test_name ( [ parameter1, parameter2, ... parametern ] );
test_name The full file path of the test to invoke.
parameter The parameter values to supply to the called test.
The call statement invokes a test from within another test script
call_close test_name ([parameter1, parameter2 ... parametern]);
The call_close statement invokes a test from within another test script, and closes the called test when WinRunner completes the test and returns to the main test. If the called test is already open when the main test is run, call_close will not close the called test.
User can expand WinRunner’s testing capabilities by creating users defined TSL functions. User can use these user-defined functions in a test or a compiled module. The main advantage of using function is it can be called from anywhere in a test script. Since it is already compiled, execution time is accelerated. A user-defined function has the following structure:
[class] function name ([mode] parameter...)
The class of a function can be static, public or external.
A static function is available only to the test or module within which the function is defined.
Once the user executes a public function, it is available to all tests, for as long as the test containing the function remains open. If the user wants to create a function that will be available to many tests, user should place it in a compiled module. Once the user has loaded a compiled module, its functions are available for all tests until user unload it. If no class is explicitly declared, the function is assigned the public class.
An external function behaves like a public function, except that while its declaration is in the local test or compiled module, its implementation code resides in an external source.
Parameters need not be explicitly declared. They can be of mode in, out, or in out .For all non-array parameters, the default mode is in. For array parameters, the default is in out. User can define up to 15 parameters in a user-defined function. The significance of each of these parameter types is as follows:
in A parameter that is assigned a value from outside the function.
out A parameter that is assigned a value from inside the function.
In out A parameter that can be assigned a value from outside or inside the function.
Declaration is usually optional in TSL. In functions, however, variables, constants and arrays must all be declared. Variables used by a function must be declared. The declaration for such a variable can be within the function itself, or anywhere else within the test or module. Variable declarations have the following syntax:
class variable [= init_expression];
The init_expression assigned to a declared variable can be any valid expression. If an init_expression is not set, the variable is assigned an empty string. The class defines the scope of the variable. It can be one of the following:
Auto An auto variable can be declared only within a function and is local to that function. It exists only for as long as the function is running. A new copy of the variable is created each time the function is called.
Static A static variable is local to the function, test, or compiled module in which it is declared. The variable retains its value until the test is terminated by an Abort command. This variable is initialized each time the definition of the function is executed.
Public A public variable can be declared only within a test or module, and is available for all functions, tests, and compiled modules.
Extern An extern declaration indicates a reference to a public variable declared outside of the current test or module.
(Continued on next question...)
Other Interview Questions