|
2#
楼主 |
发表于 2004-10-14 23:29:45
|
只看该作者
x = int(12.42);
The int function returns the integer portion of a positive, real number. Here, x is equal to 12.
The return value of a built-in function can also become part of an expression. When a function returns the value 0, the value of the expression is considered false. When it returns any other value, it is considered true. For example,
while (getline address < "clients.doc")
type (address "<kReturn>");
The getline function returns the value 1 if it succeeds, and 0 at the end of the file. Therefore, the while loop above continues until the end of the file is reached (the function returns the value 0).
Descriptive Programming
When you add an object to the GUI Map, WinRunner assigns it a logical name. You can add statements to your test that perform functions on these object. To add these statements, you usually enter the logical name of the object.
For example, in the statements below, Flight Reservation is the logical name of a window, and File;Open Order is the logical name of the menu.
set_window ("Flight Reservation", 5);
menu_select_item ("File;Open Order...");
You can also add statements to perform functions on objects without referring to the GUI Map. To do this, you need to enter more information in the description of the object in order to uniquely describe the object so that WinRunner can identify the object during the test run. This is known as: descriptive programming.
For example, suppose you recorded a purchase order in a flight reservation application. Then, after you created your test, an additional radio button group was added to the purchase order. Rather than recording a new step in your existing test in order to add to the object to the GUI Map, you can add a statement to the script that describes the radio button you want to select, and sets the radio button state to ON.
You describe the object by defining the object class, the MSW_class, and as many additional property:value pairs as necessary to uniquely identify the object.
The general syntax is:
function_name("{ class: class_value , MSW_class: MSW_value ,
property3: value , ... , propertyX: value }" , other_function_parameters ) ;
function_name: The function you want to perform on the object.
property:value: The object property and its value. Each property:value pair should be separated by commas.
other_function_parameters: You enter other required or optional function parameters in the statement just as you would when using the logical name for the object parameter.
The entire object description should surrounded by curly brackets and quotes: "{description}".
If you are not sure which properties and values you can use to identify an object, use the GUI Spy to view the current properties and values of the object.
The statement below uses descriptive programming to perform a button_set function on a radio button, to select a business class airline seat. When the test runs, WinRunner finds the radio button object with matching property values and selects it".
set_window ("Flight Reservation", 3);
button_set ("{class: radio_button, MSW_class: Button, label: Business}", ON);
Attribute/<prop_name> Notation
You can use the attribute/<prop_name> notation to identify Web objects in Internet Explorer according to its internal properties.
For example, suppose a Web page has the same company logo image in two places on the page:
<IMG src="logo.gif" LogoID="122">
<IMG src="logo.gif" LogoID="123">
You could identify the image that you want to click using descriptive programming by including the user-defined LogoID property in the object description as follows:
web_image_click("{class: object, MSW_class: html_rect, logoID: 123}" , 164 , 253 )
For more information about descriptive programming, see Descriptive Programming.
User- Defined Functions
In addition to the built-in functions it offers, TSL allows you to design and implement your own functions in test scripts. A user-defined function has the following structure:
[class] function name ( [mode] parameter... )
{
declarations;
statements;
}
Click one of the following buttons for more information on a topic in this Help module:
Function classes
Paramaters
Declarations
Return statement
Function Classes
The class of a function may be either public or static. If no class is explicitly declared, the function is assigned the default class public. A public function is available to all tests; a static function is available only to the test or compiled module within which the function was defined.
Parameters
Function parameters can be of mode in, out, or inout. For all non-array parameters, the default mode is in. The significance of each parameter type is as follows:
in: A parameter which is assigned a value from outside the function.
out: A parameter which passes a value from inside the function.
inout: A parameter which can be assigned a value from outside the function as well as pass on a value to the outside.
A parameter designated as out or inout must be a variable name, not an expression. Only a variable can be assigned a value in a function call, not an expression. For example, consider a function defined in the following manner:
function my_func (out p) {... }
Proper usage of the function call is: my_func (var_1);
Illegal usage of the function call is: my_func (arr[i] ); my_func (a+b);
because arr[i] and a+b are expressions.
Array parameters are designated by square brackets. For example, the following parameter list indicates that parameter a is an array:
function my_func (a[], b, c){
...
}
Array parameters can be either out or inout. If no class is specified, the default inout is assumed.
While variables used within a function must be explicitly declared, this is not the case for parameters.
Declarations
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. For syntax, see "Variable Declarations".
Return Statement
Any valid statement used within a TSL test script can be used within a function. In addition, the return statement is used exclusively in functions.
return [ expression ];
This statement halts execution of the called function and 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 attached to the return statement, an empty string is returned.) For additional information on functions, refer to your User's Guide.
External Function Declarations
The extern function declaration is used to declare functions that are not part of TSL, but reside in external C libraries. For more information on using C functions stored in external dlls, refer to your User's Guide.
The extern declaration must appear before the function can be called. The syntax of the extern function declaration is:
extern type function_name ( param1, param2,...);
The type refers to the return value of the function. Type can be one of the following:
char (signed and unsigned) float
short (signed and unsigned double
int (signed and unsigned) string (equivalent to C char*)
long (signed and unsigned)
Each parameter must include the following information:
[mode] type [name] [< size >]
mode The mode can be in, out, or inout. The default is in. Note that these values must appear in lower case.
type The type can be any of the values listed above.
name An optional name can be assigned to the parameter to improve readability.
size This information is required only for an out or inout parameter of type string. (See below.)
For example, to declare a function named set_clock that sets the time in a clock application, you write the following:
extern int set_clock ( string name, int time );
The set_clock function accepts two parameters. Since they are both input parameters, no mode is specified. The first parameter, a string, is the name of the clock window. The second parameter specifies the time to be set on the clock. The function returns an integer that indicates whether the operation was successful.
Once the extern declaration is interpreted, you can call the set_clock function the same way you call a TSL built-in function:
result = set_clock ( "clock v. 3.0", 3 );
If an extern declaration includes an out or inout parameter of type string, you must budget the maximum possible string size by specifying an integer size after the parameter type or (optional) name. For example, the statement below declares the function get_clock_string. It returns the time displayed in a clock application as a string value in the format "The time is..."
extern int get_clock_string ( string clock, out string time <20> );
The size should be large enough to avoid an overflow. If no value is specified for size, the default is 127. There is no |
|