在Loadrunner中提供了C对字符串出了的相关功能函数,如下:
lr_save_datetime | 把当前日期和时间保存到一个参数中 |
lr_save_int | 把一个整数保存为参数 |
lr_save_searched_string | 保存一个字符数组相对于字符串出现的部分。 |
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 2011Ending 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): 10Ending 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 );
参数解释:
buffer | 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. |
search_string | The string to search for in the buffer. |
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. |
例子:
运行结果为:
Running Vuser...
Starting iteration 1.Starting action Action.Action.c(9): Fannys_brother=WillEnding 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 );
以上三个函数我们经常会用在一起。例如:
例子:
Starting iteration 1.
Starting action Action.Action.c(5): 8Action.c(6): 7Action.c(9): ShortName=testaaaAction.c(10): ShortName=testaaaEnding action Action.Ending iteration 1.*****注:在loadrunner中,字符串处理函数用的比较多,其用法也比较简单。多加以练习操作,在项目实践中可以很快的做到得心应手。*****