LoadRunner字符串與參數的操作及轉換技巧 軟件測試
剛開始學LR時,經常搞不清楚變量和參數的區別與用法,最近在一次腳本編寫中,整理出來的一些小技巧,與大家一起分享。
//字符串復制
strcpy(str,"Hello ") ;
//字符串連接
strcat(str,"World !");
lr_message("str: %s",str);
//變量轉為參數,將變量str的值存到參數Param中
lr_save_string(str,"Param");
//參數復制
lr_save_string(lr_eval_string("{Param}"),"Param_1");
//參數轉為變量
strcpy(str1,lr_eval_string("{Param_1}"));
lr_message("str1: %s",str1);
//參數名稱格式化輸出到變量中
sprintf(str2,"{Param_%d}",1);
lr_message("str2: %s",lr_eval_string(str2));
運行結果:
str: Hello World !
vuser_init.c(14): Notify: Saving Parameter "Param = Hello World !"
vuser_init.c(19): Notify: Parameter Substitution: parameter "Param" = "Hello World !"
vuser_init.c(19): Notify: Saving Parameter "Param_1 = Hello World !"
vuser_init.c(24): Notify: Parameter Substitution: parameter "Param_1" = "Hello World !"
str1: Hello World !
vuser_init.c(30): Notify: Parameter Substitution: parameter "Param_1" = "Hello World !"
str2: Hello World !
原文轉自:http://www.anti-gravitydesign.com