j:Gph[6nnj0今天琢磨了一下LoadRunner的变量、参数的输出与相互转化的问题,写一例题:51Testing软件测试网#fS5W,y
^#YS)qD
51Testing软件测试网-^
LnUKnQR
pc:s/********** 参数和变量传递 ***********/
%Iz4_ ~7j%hwB^4S@0Variable( )
/]5d3o;P/V| `0{
wrxvo&Qf0:xre\qB.WMW0 char* ip =lr_get_vuser_ip();//获取当前用户的IP地址,保存在IP变量里。51Testing软件测试网s*?jb!\PS
char* gname =lr_get_host_name();//获取当前用户的机器名,保存在GNAME变量里。51Testing软件测试网/Kh_,F6Hfb
y+EgYP(p0 if(ip)51Testing软件测试网"O{4Pt0u
xu"B
/* 参数转变量 */ //RunTime是已定义的参数,下文也可以直接调用51Testing软件测试网qb:hKuA+qqF
lr_vuser_status_message("Ip地址: %s ,参数 : %s",ip,lr_eval_string("{RunTime}"));51Testing软件测试网[|G A|#UV
else51Testing软件测试网d0c,N ]#rd Q*H
lr_vuser_status_message("未启动IP欺骗……");
c
w+`zwK WA0`e"? NR%j#}7\;L_0/* 变量转参数 */
3~K WGB-C0 lr_save_string(gname, "GN" );//把变量IP存在“GN”参数里,下文可以直接用 {GN} 调用。51Testing软件测试网X[ r
HX D$w
DS
NW;x0/* 参数输出 */51Testing软件测试网$C-HC'Nr:n
web_submit_data("StatusReporter",
b R:~@R8Cf+{3B*e
?0 "Name=title", "Value={RunTime}",ENDITEM,51Testing软件测试网o#G3a9K7x2X
"Name=content", "Value={GN}",ENDITEM,51Testing软件测试网0[t,j.p%iv
LAST);
A'PF4Ol%o0cL"~ DPKY8c0/* 变量输出 */51Testing软件测试网wg$A/w1fPS
lr_output_message("当前IP地址: %s ",ip);
`-C1dd"{^$q)o+Q0mW)q|l5L0 lr_think_time(2);//停顿两秒便于观察。51Testing软件测试网;vd%s?,x(V
51Testing软件测试网]'xI/J.c)Y4Es}_;X return0;51Testing软件测试网.{$S$vl7QH+ei
y
}51Testing软件测试网|$dlph
/*********************END***************************/51Testing软件测试网A&p.Zho%L`
W*CJ"sw(J0这段代码,虽然很简单,但已含概了变量与参数的转化与输出。51Testing软件测试网t2[@7gf,_ E#F'x3e/ks