How to Program with Tsl in Winrunner (2)
Introduction To WinRunner Basics
(Continued from previous question...)
How to Program with Tsl in Winrunner (2)
The const indicates that the declared value cannot be modified. The syntax of this declaration is:
[class] const name [= expression];
The class of a constant may be either public or static. If no class is explicitly declared, the constant is assigned the default class public.
The following syntax is used to define the class and the initial expression of an array. Array size need not be defined in TSL.
class array_name [ ] [=init_expression]
The array class may be any of the classes used for variable declarations (auto, static, public, and extern). Note that arrays are initialized once, the first time a function is run. If the user edits the array’s initialization values, the new values will not be reflected in
Subsequent test runs. To reset the array with the new initialization values, either interrupt test execution with the Stop command, or define the new array elements explicitly.
The return statement is used exclusively in functions. The syntax is:
return ( [expression] );
This statement passes control back to the calling function or test. It also returns the value of the evaluated expression to the calling function or test. If no expression is assigned to the return statement, an empty string is returned.
The texit statement can be used to stop a function or test run. The syntax is:
texit ([ expression ] );
Compiled modules, like a regular test user create in TSL, can be opened, edited, and saved. User indicate that a test is a compiled module in the General tab of the Test Properties dialog box, by selecting Compiled Module in the Test Type box. The content of a compiled module differs from that of an ordinary test. For example, it cannot include checkpoints or any analog input. The purpose of a compiled module is to store the user-defined functions which user use most frequently so that they can be quickly and conveniently accessed from other tests. Unlike an ordinary test, all data objects (variables, constants, arrays) in a compiled module must be declared before use. If the user makes changes to a function in a loaded compiled module, user must unload and reload the compiled module in order for the changes to take effect. A compiled module may contain the following elements:
Function definitions and declarations for variables, constants and arrays.
Prototypes of external functions
Load statements to other modules.
User can use the Function Viewer to load and unload compiled modules, to copy, paste and execute the functions of loaded compiled modules and tests, and to open loaded compiled modules and tests containing loaded functions. The Function Viewer toolbar provides the following options:
Load Enables user to load a compiled module.
Unload Unloads the currently selected compiled module.
Unload All Modules Unloads all compiled modules. This button does not have any effect on functions loaded from tests.
Copy Copies the selected function prototype to the clipboard.
Paste Copies and pastes the selected function prototype to the current cursor location in the test.
Execute Executes the selected function.
Go to Opens the selected compiled module, test, or function in the test Window.
Advantages of compile module
Compiled modules can improve the organization and performance of the tests. Since user debug compiled modules before using them, tests that call functions from these modules require less error-checking. In addition, calling a function that is already compiled is significantly faster than interpreting a function in a test script.
System and User Compiled Modules
A system compiled module is a closed module that is not visible to the tester. It is not displayed in the test window when it is loaded, cannot be stepped into, and cannot be stopped by a pause command. A system module is not unloaded when the user execute an unload statement with no parameters A user compiled module is the opposite of a system module in most respects. It is displayed when it runs and user can use all WinRunner debugging options to control the run. Generally, a user module is one that is still being developed. In such a module user might want to make changes and compile them incrementally.
Loading and Unloading a Compiled Module
User can load a module in one of three ways:
Use the Load or Unload toolbar buttons in the Function Viewer to load or unload a compiled module.
Load the module from a test script using the TSL load or reload functions.
Run the module script using the WinRunner Run commands to load a module into memory with all its functions. To unload a module loaded this way, click the Stop button.
(Continued on next question...)
Other Interview Questions