lr_save_datetime | 把当前日期和时间保存到一个参数中 |
lr_save_int | 把一个整数保存为参数 |
保存一个字符数组相对于字符串出现的部分。 | |
lr_save_string | 把一个字符串保存到参数中 |
lr_save_var | 把字符串的一部分内容保存为参数 |
lr_eval_string | 返回参数的实际内容或返回一个包含参数的字符串的实际内容 |
下面我们将对这些函数作一一说明,并举例实践。
void lr_save_datetime(const char *format, int offset, const char *name);
参数解释:
format | 所检索的日期/时间信息的格式 |
offset | 当前日期和时间的偏移量, 采用形式有: DATE_NOW, TIME_NOW, ONE_DAY, ONE_HOUR, ONE_MIN. 例如: TIME_NOW + ONE_HOUR |
name | 保存的参数名称,用来存储日期/时间信息。 |
例子:
运行结果为:
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(5): Tomorrow is 七月 06 2011
Ending action Action.
Ending iteration 1.
Ending Vuser...
int lr_save_int ( int value, const char *param_name);
参数解释:
value | 将要保存到参数得整数值 |
param_name | 保存的参数名称 |
例子:
运行结果为:
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(6): 10
Ending action Action.
Ending iteration 1.
Ending Vuser...
int lr_save_searched_string (const char *buffer, long buf_size, unsigned int occurrence, const char *search_string, int offset, unsigned int string_len, const char *parm_name );
参数解释:
The STRING or CARRAY buffer, part of whose contents you want to save. | |
buf_size | The buffer size. |
occurrence | The occurrence number of the search_string (0-based count). For example, if the search_string occurs three times, and you want the second occurrence, set occurrence to 1. |
offset | The number of characters to skip after the end of the search string occurrence. |
string_len | The number of characters to save. |
parm_name | Parameter name to be used in subsequent lr statements to refer to the saved information. Name is enclosed in double-quotes. |
例子:
Action() { char cBuff[] = " abc Emma Woodhouse abc Elizabeth Bennet abc William Price " ; lr_save_searched_string(cBuff, strlen(cBuff), 2 , " abc " , // Search for third occurrence of "abc" 1 , // Skip the space after "abc" 4 , // Put the next four characters... " Fannys_brother " ); // ... in parameter Fannys_brother. lr_output_message( " %s " ,lr_eval_string( " Fannys_brother={Fannys_brother} " )); return 0 ; }
运行结果为:
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(9): Fannys_brother=Will
Ending action Action.
Ending iteration 1.
Ending Vuser...
int lr_save_string (const char *param_value, const char *param_name);
int lr_save_var (const char *param_value, unsigned long const value_len, unsigned long const options, const char *param_name);
char *lr_eval_string (const char *instring );
以上三个函数我们经常会用在一起。例如:
例子:
Action() { lr_save_string( " testaaaab " , " InName " ); lr_output_message( " %d " ,strlen( " {InName} " )); lr_output_message( " %d " ,strlen( " {InName} " ) - 1 ); lr_save_var( lr_eval_string( " {InName} " ), strlen( " {InName} " ) - 1 , 0 , " ShortName " ); lr_output_message( " %s " ,lr_eval_string( " ShortName={ShortName} " )); lr_output_message( " ShortName=%s " ,lr_eval_string( " {ShortName} " )); return 0 ; }
Starting iteration 1.
Starting action Action.
Action.c(5): 8
Action.c(6): 7
Action.c(9): ShortName=testaaa
Action.c(10): ShortName=testaaa
Ending action Action.
Ending iteration 1.
*****注:在loadrunner中,字符串处理函数用的比较多,其用法也比较简单。多加以练习操作,在项目实践中可以很快的做到得心应手。*****