LR常用函数总结

上一篇 / 下一篇  2012-01-20 13:20:39 / 个人分类:lr

事务函数:51Testing软件测试网P7N3U.\7r$_ |J%m,X6AJ

lr_start_transaction();//标记事务的开始51Testing软件测试网aL w-gB.k6y*\[

lr_start_transaction();/*标记事务的结束,一般情况下,事务开始与结束联合使用*/51Testing软件测试网~,^!Tniy'i

lr_get_trans_instance_status();//得到事务的状态51Testing软件测试网T$H"MQ4Za

lr_get_transaction_think_time();//得到事务的指定思考时间,事务时间=整体事务时间-事务的

{*^ HUT9t|#J72047

lr_stop_transaction();//停止事务51Testing软件测试网y9I5X#`0B(m

日志函数:51Testing软件测试网gR&os8j

lr_debug_message();//发送调试信息到日志文件

)Gq&ihe J?72047

lr_error_message();//发送错误信息到LR输入窗口或日志文件里51Testing软件测试网5uA:ZA6o0zl'IqK

lr_get_debug_message();//返回当前调试的信息

|8I|)V vP72047

lr_log_message();//发送信息到用户日志文件51Testing软件测试网4bG \0F n(S hh@

lr_output_message();//发送信息到输出窗口或日志文件51Testing软件测试网@/e@dP

lr_vuser_status_message();//发送虚拟用户的状态到LR的Controller51Testing软件测试网^/j l-G b*s;{#bA*\}

运行时函数:

-Q{t1sl&a72047

lr_abort();//终止执行的脚本51Testing软件测试网1d8Y seGD k}

lr_continue_on_error();//当发生错误后运行的事件51Testing软件测试网mqkp^/RYW3z+c

lr_exit();//从scirpt.ation.iteration中退出51Testing软件测试网],Vby%C

lr_rendezvous_ex();//设置集合点51Testing软件测试网%j.`}_.UK

lr_think_time();//设置思考时间,在性能测试中为了更好模拟以后操作,可以根据实际生产环境设置思考时间。51Testing软件测试网-K/@!cGIm9R

lr_rendezous();//集合点,可以设置虚拟用户相同操作之前进行集合,通过集合点可以增加被测试应用的压力,从而达到压力测试的目的。51Testing软件测试网dke|m+[3S$V

lr_load_dll();//调用DLL文件

k tw ?|2\ Z x.z72047

例子:

0K*J9B7CM_5Z72047

lr_load_dll("user32.dll");

)k8D)p^]72047

MessageBoxA(NULL,"This isTestingMessage","message_caption",0);

n r`*Q\9X"K72047

return 0;

TjuFPba_'lx72047

系统信息函数:

H M;p8D.E(t\72047

lr_get_master_host_name();//返回运行Controller主机的名称

5TX8B5K/F\1t/T`I72047

lr_get_user_ip();//返回虚拟用户的IP地址51Testing软件测试网,r.C)T4\^s.m

lr_user_data_point();//录制用户自定义的数据样例51Testing软件测试网5LD:Y"o/mv

lr_user_data_point();// 记录自己的数据来进行分析,每次要记录一个点时,请使用该函数记录采样名称和值。系统将自动记录采样的时间。执行之后,可以使用用户等义的数据,点击图形分析结果

)spG)m4p72047

lr_get_host_name();//返回主机名

!e5_uH~_)tWQ1J72047

例子;

#h%}$yTA4sj72047

char * host;

w"q H_;|5L*EJ*m72047

host=lr_get_host_name();

#tC'^pO(Q72047

lr_output_message("Computer Name %s",host);

!Nq/}Y R'JE@72047

return 0;51Testing软件测试网3s t }:g l;G

WEB应用中常见函数51Testing软件测试网0Mx\+Jn

web_url();//根据函数中的URL属性加载对应的URL,不需要上下文。

(O)lNzM+^)g p-c72047

web_image();//模拟鼠标在指定图片上的单击动作。此函数必须在有前置操作的上下文中使用。

-o/qS,})q7S ^J i0o72047

Tips:在Toos—Recording Option,如果录制级别设为基于HMTL的录制方式时,web_image才会被录制到。

o._/s A|i;SK72047

Web_link();//模拟鼠标在由若干个属性集合描述的链接上进行单击。此函数必须在前置动作的上下文中才可以执行。51Testing软件测试网0Jc@jG:C}1K.H

web_submit_form. ();//函数用来提交表单。此函数可能必须在前一个操作的上下文中执行。51Testing软件测试网0t ] y5jx

Tips:支持Web虚拟用户,不支持WAP虚拟用户。

+_y+R!n/t6|3`72047

web_submit_data();//函数处理无状态或者上下文无关的表单提交。它用来生成表单的GET或POST请求,这些请求与Form自动生成的请求是一样的。发送这些请求时不需要表单上下文。

"A0z1u(j*oWj72047

web_find();//此函数的作用是在HTML页面中查找指定的字符串。当指定的HTML请求全部完成以后,开始执行搜索过程,比web_reg_find要慢。51Testing软件测试网M n&o(Ea0W n

web_find函数在C语言的脚本中已经被web_reg_find所替代,web_reg_find运行速度比较快,而且在HTML-based和URL-based的录制方式中都可以使用。 在C语言脚本中,web_find是向后兼容的。Java和Visual Basic脚本中不再支持它。51Testing软件测试网PHrc8qdDW-Yq

web_image_check();//检查指定的图象是否在HTML页面中出现,此函数仅仅支持基于HTML的脚本。

D:Qt2]hX72047

web_reg_add_cookie();//是注册类型的函数。它首先注册一个搜索文本字符串的请求。检查动作在后续的Action函数之后进行。如果字符串被找到,就添加到cookie中。51Testing软件测试网B{&|9e?5[

web_reg_find();//属于注册函数,注册一个在web页面中搜索文本字符串的请求,在接下来的Action(象web_url)类函数中执行搜索。

,~,F }*u r&~ P72047

web_concurrent_start();//函数是并发组开始的标记。组中所有的函数是并发执行的。并发组的结束web_concurrent_end 函数。

N`g%S@Wrx72047

web_reg_save_param();//关联函数,通过关联可以在测试中保持动态值,从服务器返回的数据库中查找需要关联的数据。51Testing软件测试网,u'_ F T^.yQS4v1I

web_add-filter();// 过滤函数,用于对指定的URL进行过滤,分析URL加载那部分对性能有影响。界面操作Run-time Settings 下的 Internet Protocol的Download Filters。

^5r-a[Eo ^72047

web_custom_request();// 自定义请求函数,可以编写自定义请求格式进行接口功能测试51Testing软件测试网~w@8u xT

FTP /IMAP方面:

~1yVW-UI8NS.T0u72047

ftp_logon_ex();//针对特定会话登录到FTP服务器。51Testing软件测试网V3?u4I _/p9V

ftp_put_ex();//在FTP服务器上设置工作目录及上传文件。

rQ#zD$v:R"Hj ws72047

ftp_logout_ex();//注销当前FTP连接。51Testing软件测试网Y.yXAw"?e7r

imap_create();//创建新的邮件。51Testing软件测试网0}AR3Pp#W5kc g

imap_check();//邮件中请求检查点,实现并适用与邮箱内部的内务管理。51Testing软件测试网M*N C~z8d

Tips:针对IMAP的测试,把函数中的ftp替换成imap即可。

+@5Yg z{{!v!}/F9a72047

其它常用函数:51Testing软件测试网$}6VG8i7~_L"|Y)f

Lr_decrypt():LR中的解密函数51Testing软件测试网uR:D$T)pR

实例代码: lr_output_message("解密函数测试,解密后数值:%s",lr_decrypt("4e0942869c958e3e"));

XA0R0z2} PO~.U72047

Getenv():得到定义的环境变量值51Testing软件测试网/V:p%b]$Y\k

实例代码:

'Y(P7M HK72047

char *tmp,logfile[256],dlr_seperator;51Testing软件测试网 t8g5?.JxY

logfile;51Testing软件测试网&m yv2p ^#P8ow;i

//Create an environment variable51Testing软件测试网s-s xmBUC!H/hQ

putenv("LOGFILE_NAME=lr_xiaolintest.txt");

Nv2m pK TP,i5i2z72047

//51Testing软件测试网&t%?0w3M)^t

if(tmp = (char*)getenv("TEMP"))

4k:G*RC tR8bb72047

lr_output_message("Temp Dir = %s",tmp);51Testing软件测试网.jO'^z*{

else{51Testing软件测试网&{l J`8l"W A)_

lr_output_message("TEMP environment variable undefined");51Testing软件测试网j`%]KnB!w&g

return -1;51Testing软件测试网 o'yNQ-L:z

}

5o {Z J'N5e'U%W72047

sprintf(logfile,"%s\\%s",tmp,(char*)getenv("LOGFILE_NAME"));

S#uUgJzJ72047

System():执行操作系统的命令51Testing软件测试网[~(WV$i[]BK

char filename[1024],command[1024];51Testing软件测试网ON:F V)N,n2F\s

char new_dir[] = "c:\\test";

xn!x%{ovBEn72047

//Create a directory udder root calledtestand make it the current dir51Testing软件测试网$m1J,bx+Gt-{hW

if(mkdir(new_dir))

M G"w,{$B5_\1Lh72047

lr_output_message("Create directory :%s failed",new_dir);51Testing软件测试网&]x)yCa.M@np

else51Testing软件测试网V%z;[#v/iQ6`C

lr_output_message("Create new directory %s",new_dir);51Testing软件测试网+^^'\z p6]1h

sprintf(filename,"%s\\%s",new_dir,"xialin.txt");

X8^1L+Vm%z72047

//Executr a dir /b command and directory it to a new_file

(O6U|^SC-g72047

sprintf(command,"dir /b c:\\ > %s /w",filename);51Testing软件测试网F? IsN/H-T;Q

system(command)

CLh+_o&|:Z+t72047

lr_output_message("Create new file %s",filename);

$lI)WP v6l4KY72047

Rand():得到一个整型的随机值(0到32767)

~1z |R jV72047

srand(time(NULL));

1w!j"n!OHtc X#P72047

//Generate a random number from 0-99

T"uO"M`Y5p72047

lr_output_message("A number between 0 and 99 is :%d\n",rand()%100);

;cnu8a_b'r72047

return 0;51Testing软件测试网7z-R{gnYl

Getdrive()and mkdir():返回当前驱动盘的名字。

Cv-a4V$H9F:?.l72047

int ch,drive,curdrive;51Testing软件测试网$u:~ A Z)c }

static char path[1024];51Testing软件测试网]QcO*R5X*Es's0A _

//Save current drive letter so it can be restored later

E4A%E&a]72047

curdrive = getdrive();51Testing软件测试网!r%W h9\v N$`

//If we can switch to the drive,it exists

`iM'qq X9t72047

lr_output_message("Available drives are:");51Testing软件测试网Z%lYiF#P

for(drive = 1;drive <= 26;drive++)51Testing软件测试网ZD2b(^W)v

if (!chdrive(drive))51Testing软件测试网1aU1@'S!x$S zX#n

lr_output_message("%c:",drive + 'A' -1);

Q t,V0Xy72047

chdrive(curdrive);//Restore original drive

7E%s1k,?:t*Nh ?72047

return 0;

"{3xxp%K6p V72047

Time():返回系统的时间51Testing软件测试网z;U2m8?'E,?Ed

typedef long time_t;

By0nd0Y#kh72047

time_t t;

uM JN3v)wyQD72047

//Get system time and display as number and string

)A[G.b;mE(zN72047

lr_message("Time in seconds since 1/1/88: %ld\n",time(&t));

;} T0I~.r&}9ma\72047

lr_message("Formatted time and date: %s",ctime(&t));

)MHLP9W72047

return 0;51Testing软件测试网8K#{%o%R~3_#X



TAG:

 

评分:0

我来说两句

日历

« 2023-08-16  
  12345
6789101112
13141516171819
20212223242526
2728293031  

数据统计

  • 访问量: 32863
  • 日志数: 104
  • 建立时间: 2011-10-10
  • 更新时间: 2012-04-12

RSS订阅

Open Toolbar