Loadrunner Vugen脚本的变量和参数的转换.

LoadRunner Vugen脚本,语言是C语言编写的。Loadrunner脚本本身有参数的概念,这里的参数和C语言的变量不同。

 

以下是变量和参数的转换

转换主要使用:lr_save_string 和lr_eval_string以及""

变量转参数:lr_save_string

参数转变量:lr_eval_string以及""

 

详细说明:

1.定义变量,赋值字符串

    char source[30] = "value";

..

    char *source= NULL;

    source="Hello";

 

2.lr_save_string:将字符串保存到参数中的函数。

int lr_save_string (const char *param_value, const char *param_name);

param_value:给参数赋值的值,参数值

param_name:参数名称

int 返回类型

 

//定义1个参数,字符串保存成参数

lr_save_string("hello","param");

 

3.lr_eval_string:返回参数的实际内容字符串的函数

char * lr_eval_string (const char * instring );

 

//参数转换成字符串

lr_eval_string("{param}");   

 

4.参数[lr_save_string保存的参数]转换成变量

    char *tamp = NULL;      //定义1个空变量

    lr_save_string("hello","param");    //定义参数param,保存字符串hello到参数

    tamp=lr_eval_string("{param}");    //参数转换成字符串,赋值给变量

    lr_output_message("变量source的值是:%s",tamp);   //输出

 

5.参数[replace with a parameter]转换成变量的另外方法,加””

     char *tamp = NULL;    //定义空变量

     tamp="{param}";        //变量的字符串进行参数化replace with a parameter

     lr_output_message("x值的是:%s",tamp);    //输出

 

6.变量转换为参数

    char *source= NULL;    //定义空变量

    source="Hello";        //变量赋值

    lr_save_string(source,"param");   //变量保存为参数param

    lr_output_message("source值的是:%s",lr_eval_string("{param}"));   //转换为字符串输出

----------------------

1.定义变量,赋值字符串

char source[30] = "value";

//输出

lr_output_message("变量source的值是:%s",source);

执行结果:

Action.c(4): 变source量的值是:value

 

例子2:

    char x[30]="10";

    lr_output_message("x值的是:%s",x);

例子3:

    char *tamp = NULL;

    tamp="test";

lr_output_message("x值的是:%s",tamp);

例子4:

    char *tamp = NULL;

    tamp="{param}";  //[replace with a parameter]参数加上""变成字符串,给变量赋值。

    lr_output_message("x值的是:%s",tamp);

 

变量和参数的转换也可参考:

https://blog.csdn.net/micropatterning/article/details/80465779

 

 

发布了104 篇原创文章 · 获赞 5 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/fen_fen/article/details/87278156