英文好的帮我看下这个怎么翻译!关于TSL的!
感觉是不是跟C++有点类似啊???The in Operator
The in operator is used to determine if a subscript exists in an array.
subscript in array;
returns the value 1 if the subscript exists, and 0 if it does not. It can be used in a conditional statement, like the one below which checks whether the element with the subscript new exists in the array menu_array:
if ("new" in menu_array)
The operator in should be used rather than the following statement:
if (menu_array["new"]= "")...
because this statement causes the element to be created, if it does not already exist. (Recall that array elements are created the first time they are mentioned.)
The in operator can also be used for multidimensional arrays.The subscript of the element is enclosed in parentheses, as in the following statement:
if (("new.doc", 12) in multi_array)...
for ( element in array ) statement
Causes the element to be set to the subscript of each element in the array.The statement is executed once for each element of the array, and the loop is terminated when all elements have been considered.The order in which the subscripts are read is undefined.The sample script below reads an array for which each element is a date and time string.A for loop is used to print to the screen each of the elements of the array.
for (i in date_array)
print ("the date was " & date_array);
Specifying a Starting Subscript
TSL allows you to assign values to array elements starting from a specific subscript number. You specify the starting subscript in the array initialization. Remember that the array subscripts are zero-based梩he first subscript number is 0.
abc[ ] = {starting subscript = value1, value2, value3... }
For example, if the array size is ten, you can assign values to the last five elements of the array:
public abc[ ] = {5 = 100,101,102,103,104}
As a result, the abc array receives the following values:
abc=100
abc=101
abc=102
abc=103
abc=104
Array Functions
TSL provides two array functions: delete and split. The delete function removes an element from an array; split splits a string into fields and stores the fields in an array. Note that since TSL arrays are associative, deleting one element does not affect any other element. For instance, if you delete the element a from an array with three elements, a and a will not be affected.
Input-Output
TSL provides a number of built-in functions that allow you to read and write to files or to the screen.
ForUNIX products, the sprintf function returns a formatted string to a variable.
For WinRunner and other PC products, use the file_open function to open a file for reading and writing. The file_printf function writes to a file, and file_getline reads from a file.The file_close function closes a file that you opened with file_open.
There are two functions that generate output within the testing environment. The report_msg function prints a user-defined string expression to the test run report.The pause function stops the test run and displays a string expression in a message box on the screen.
Comments
A number sign (#) indicates that all text from this point to the end of the line is a comment.Comments can appear within statements that extend beyond one line, or can stand alone on a line of test script.The TSL interpreter does not process comments.For example,
# Type the date
i=1;
while (i<=31) # number of days in month
type ("The date is January " & i++ & ", 1994");
Note that a number sign (#) that appears within a string constant is not considered a comment; for instance, a="#3".
Built-in Functions
TSL provides numerous built-in functions that perform a range of tasks. To call a built-in function from within a test script, use the following syntax:
function ( [ parameters ] );
Many TSL functions perform operations on objects in your application. When you use these functions, one of the function parameters indicates the object on which the function should be performed. If the object is in the GUI Map, you can indicate the object by its logical name.You can also indicate objects by specifying object properties and values that describe the object.This is known as descriptive programming.
Most built-in functions return a value. This value can be assigned to a variable. For example,
[ Last edited by yedi007 on 2004-10-15 at 22:53 ] 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:
function name ( 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 );my_func (a+b);
because arr 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:
type [< 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 maximum size.
TSL identifies the function in your C code by its name only.You must pass the correct parameter information from TSL to the C function.TSL does not check parameters: if the information is incorrect, the operation fails.
In addition, your C function must adhere to the following conventions:
?Any parameter designated as a string in TSL must be associated with a parameter of type char* in C.
?Any parameter of mode out or inout in TSL must be associated with a pointer in C.For instance, a parameter out int in TSL must be associated with a parameter int* in the C function.
?For WinRunner the external function must observe the standard Pascal calling convention export far Pascal.
For example, the following declaration in TSL:
extern int set_clock (string name, inout int time);
must appear as follows in C:
int _far _pascal _export set_clock (char* name, int* time )
Reserved Words
WinRunner contains reserved words. In addition to the words listed below, all TSL functions are reserved words in WinRunner.
Note that you can change the color and appearance of reserved words in WinRunner抯 script editor. You can also modify the list of reserved words. For more information, refer to the "Customizing the Test Script Editor" chapter in the WinRunner User抯 Guide. 2004-10-14 23:28..........
2年了
我的英文购不好的了
没想到 没有人有闲心会一句一句翻译出来得。你不可能是每句都看不懂吧?
把你不会得贴出来,才有可能给你翻译出来。。。。。。。
楼主要懂得提问技巧。。。
页:
[1]