事务函数:
.}9Ptp9BZ$n.G,J0 lr_start_transaction();//标记事务的开始51Testing软件测试网Nrr
HXs
lr_start_transaction();/*标记事务的结束,一般情况下,事务开始与结束联合使用*/
Exs!L:}z:c~%F0 lr_get_trans_instance_status();//得到事务的状态
t3Jo2f7K5r7X;\`5b
p6s0 lr_get_transaction_think_time();//得到事务的指定思考时间,事务时间=整体事务时间-事务的
8v*p(]+PM2t P e0 lr_stop_transaction();//停止事务51Testing软件测试网
r&W&hK;i
E;hA#cs1a
日志函数:
%^_y2UPw0 lr_debug_message();//发送调试信息到日志文件51Testing软件测试网C7UU `F?(y$k E
lr_error_message();//发送错误信息到LR输入窗口或日志文件里
NO(e8M(t$N0 lr_get_debug_message();//返回当前调试的信息51Testing软件测试网
x z&^%a)T8}
lr_log_message();//发送信息到用户日志文件51Testing软件测试网 V/rK5?ZR
lr_output_message();//发送信息到输出窗口或日志文件
?j,AZV'`S?f1@0 lr_vuser_status_message();//发送虚拟用户的状态到LR的Controller51Testing软件测试网|8c~,na7k8[~H
运行时函数:
%y4q0V5?*D8dZ&g0 lr_abort();//终止执行的脚本51Testing软件测试网-g u9Qv/E{+SH7Nd^
lr_continue_on_error();//当发生错误后运行的事件
S|p.B9g"}U0 lr_exit();//从scirpt.ation.iteration中退出51Testing软件测试网8A#^8w9B6?
r
lr_rendezvous_ex();//设置集合点
[GA,~ t d~0 lr_think_time();//设置思考时间,在性能测试中为了更好模拟以后操作,可以根据实际生产环境设置思考时间。51Testing软件测试网"HC.@d2C/q
lr_rendezous();//集合点,可以设置虚拟用户相同操作之前进行集合,通过集合点可以增加被测试应用的压力,从而达到压力测试的目的。51Testing软件测试网XI1e5Hb
lr_load_dll();//调用DLL文件
8b%UtFG,?2z0 例子:51Testing软件测试网yw XN?
|&Q9]
lr_load_dll("user32.dll");51Testing软件测试网8bR6e|6}-~
MessageBoxA(NULL,"This is Testing Message","message_caption",0);
i'@xmbKM+k Q0 return 0;51Testing软件测试网9\1G4U$S(o@.VD
系统信息函数:
z {.T&k%g{*n8E|0 lr_get_master_host_name();//返回运行Controller主机的名称51Testing软件测试网8nK!kIC1`
lr_get_user_ip();//返回虚拟用户的IP地址
YX&W3Pi V0 lr_user_data_point();//录制用户自定义的数据样例
1T3[.@(B"I+Z/MC2r@-S0 lr_user_data_point();// 记录自己的数据来进行分析,每次要记录一个点时,请使用该函数记录采样名称和值。系统将自动记录采样的时间。执行之后,可以使用用户等义的数据,点击图形分析结果
D2~9c"b8iO
V1wQB0 lr_get_host_name();//返回主机名51Testing软件测试网/x)q
H5\rB%C$Rt
例子;51Testing软件测试网#\v'H2W-?i$w
char * host;51Testing软件测试网7d*^%`!YJ6P2r@
host=lr_get_host_name();
&\F:VN0K0XU0 lr_output_message("Computer Name %s",host);51Testing软件测试网w)QH2dPSaa%o
return 0;51Testing软件测试网8KVOV[ Pez9Cp
WEB应用中常见函数51Testing软件测试网JQ!x0P2CI"]Pr
web_url();//根据函数中的URL属性加载对应的URL,不需要上下文。51Testing软件测试网7zpZ3IV;D
web_image();//模拟鼠标在指定图片上的单击动作。此函数必须在有前置操作的上下文中使用。
$N-cO,N@V ?8`$cL0 Tips:在Toos—Recording Option,如果录制级别设为基于HMTL的录制方式时,web_image才会被录制到。51Testing软件测试网h0h |n.r1]K
Web_link();//模拟鼠标在由若干个属性集合描述的链接上进行单击。此函数必须在前置动作的上下文中才可以执行。
b1Pb7@jsA0web_submit_form. ();//函数用来提交表单。此函数可能必须在前一个操作的上下文中执行。51Testing软件测试网&xi*[1]`#ah}#FSR
Tips:支持Web虚拟用户,不支持WAP虚拟用户。
WI-J+K3Xd
d_u0web_submit_data();//函数处理无状态或者上下文无关的表单提交。它用来生成表单的GET或POST请求,这些请求与Form自动生成的请求是一样的。发送这些请求时不需要表单上下文。51Testing软件测试网)jg8K,LF(t,B3b
web_find();//此函数的作用是在HTML页面中查找指定的字符串。当指定的HTML请求全部完成以后,开始执行搜索过程,比web_reg_find要慢。
+@3pVXXE n(T3q/p J0web_find函数在C语言的脚本中已经被web_reg_find所替代,web_reg_find运行速度比较快,而且在HTML-based和URL-based的录制方式中都可以使用。 在C语言脚本中,web_find是向后兼容的。Java和Visual Basic脚本中不再支持它。
(A4ur^:_]$\0web_image_check();//检查指定的图象是否在HTML页面中出现,此函数仅仅支持基于HTML的脚本。51Testing软件测试网XJ"_
O0l0Y*Hf
web_reg_add_cookie();//是注册类型的函数。它首先注册一个搜索文本字符串的请求。检查动作在后续的Action函数之后进行。如果字符串被找到,就添加到cookie中。
4fg&BX V6L0web_reg_find();//属于注册函数,注册一个在web页面中搜索文本字符串的请求,在接下来的Action(象web_url)类函数中执行搜索。
"]m!Dsp0web_concurrent_start();//函数是并发组开始的标记。组中所有的函数是并发执行的。并发组的结束web_concurrent_end 函数。
4o7o} C3J@y!WL0web_reg_save_param();//关联函数,通过关联可以在测试中保持动态值,从服务器返回的数据库中查找需要关联的数据。51Testing软件测试网K9U0W4\9U;Q*B:_d|
web_add-filter();// 过滤函数,用于对指定的URL进行过滤,分析URL加载那部分对性能有影响。界面操作Run-time Settings 下的 Internet Protocol的Download Filters。51Testing软件测试网1xa$W-W0fZ
web_custom_request();// 自定义请求函数,可以编写自定义请求格式进行接口功能测试。51Testing软件测试网GKx8^ oa
FTP /IMAP方面:
? ^;eUd;T
r R6x0 ftp_logon_ex();//针对特定会话登录到FTP服务器。51Testing软件测试网Bv7P
Y#HV
ftp_put_ex();//在FTP服务器上设置工作目录及上传文件。51Testing软件测试网Gijf:X
ftp_logout_ex();//注销当前FTP连接。51Testing软件测试网yH)E~!]F(x$sJ
imap_create();//创建新的邮件。51Testing软件测试网5H%`
z-V F0HC
imap_check();//邮件中请求检查点,实现并适用与邮箱内部的内务管理。51Testing软件测试网9Wk:ilr6{
Tips:针对IMAP的测试,把函数中的ftp替换成imap即可。
O7H9G1[d#K/@O0 其它常用函数:51Testing软件测试网D(F
dh}
Lr_decrypt():LR中的解密函数51Testing软件测试网U*F,F2JW
实例代码: lr_output_message("解密函数测试,解密后数值:%s",lr_decrypt("4e0942869c958e3e"));51Testing软件测试网Q5\G Nu
Getenv():得到定义的环境变量值
8_$L1]`5V[)g0 实例代码: 51Testing软件测试网:j Uk:hu:o
char *tmp,logfile[256],dlr_seperator;51Testing软件测试网1NDQ6^S
logfile;
"[0BF$I3zi`a0//Create an environment variable
^GZ6a}7t5R0putenv("LOGFILE_NAME=lr_xiaolintest.txt");
+^&AG9ki[0//51Testing软件测试网%b{~cmiIu4R5BPv
if(tmp = (char*)getenv("TEMP"))
:Z@0d$B$a]
w0lr_output_message("Temp Dir = %s",tmp);51Testing软件测试网
a9o7U-p^#si
else{
B*iPC8Id+u0lr_output_message("TEMP environment variable undefined");51Testing软件测试网-F-\(e5V,S}KF
return -1;
!r.Q;d'ov*]k-|l0}
2_b,w_.~9M0sprintf(logfile,"%s\\%s",tmp,(char*)getenv("LOGFILE_NAME"));51Testing软件测试网3r{F]6r.q
System():执行操作系统的命令51Testing软件测试网Q
bKm@*C8tB3m
char filename[1024],command[1024];
/@tnJ#CE1\z2K\0 char new_dir[] = "c:\\test";
6N7ip0U8HG0 //Create a directory udder root called test and make it the current dir
$[RIW"e X7n0 if(mkdir(new_dir))51Testing软件测试网+xRN-tyE6NJ4I7E
lr_output_message("Create directory :%s failed",new_dir);
p&Yv}p
Z wL0 else51Testing软件测试网)L8Ms }8`%b
lr_output_message("Create new directory %s",new_dir);
eg
aBPW4Q]E0 sprintf(filename,"%s\\%s",new_dir,"xialin.txt");
]$p!g-e5idE;gc9g0 //Executr a dir /b command and directory it to a new_file
]:fY9p:E"@8F3J0 sprintf(command,"dir /b c:\\ > %s /w",filename);
4Dq;K3O-}1BE8S0 system(command)
N"Q%lW8k Q#`0 lr_output_message("Create new file %s",filename);51Testing软件测试网x9C
qeSx(~J
Rand():得到一个整型的随机值(0到32767)51Testing软件测试网1B:{(e/Pu;mZ,B
srand(time(NULL));
IJe6i;I0//Generate a random number from 0-9951Testing软件测试网N9qX)LM{
lr_output_message("A number between 0 and 99 is :%d\n",rand()%100);
q)f+Kh2F)g
Q0return 0;
(U^Ws1\$B0 Getdrive()and mkdir():返回当前驱动盘的名字。
l;k;@c`|0int ch,drive,curdrive;51Testing软件测试网*_Rw0]d"b?
static char path[1024];51Testing软件测试网#}
\f^'D
//Save current drive letter so it can be restored later51Testing软件测试网H9C{l_
x
curdrive = getdrive();
h2m}/__2?0//If we can switch to the drive,it exists51Testing软件测试网_a0wmjk U
lr_output_message("Available drives are:");
6]N0P Zluj0for(drive = 1;drive <= 26;drive++)51Testing软件测试网){OBjhiFa
if (!chdrive(drive))
p
B9Q;q%k{y0lr_output_message("%c:",drive + 'A' -1);51Testing软件测试网co0|8Mrn})Z pe
chdrive(curdrive);//Restore original drive
8dP4I%ZZ;N/y4uiQ0return 0;
X3v B|f0 Time():返回系统的时间51Testing软件测试网;l;nxWu;b
typedef long time_t;
/bQydj
]!O0time_t t;
wTp s6e i*R-S;\0//Get system time and display as number and string51Testing软件测试网g E\a1@W:B~&A3T
lr_message("Time in seconds since 1/1/88: %ld\n",time(&t));51Testing软件测试网$U1JB1R|7v+{+V_
lr_message("Formatted time and date: %s",ctime(&t));
.LD:J[O*`[$g k0return 0;51Testing软件测试网n,p(Xd1t