|
新年将至,到了总结的日子。回顾几年来测试生涯的点滴,终觉某些东西还是总结下来的好。
近日计划将LR中常用函数,进行归纳和总结,并写出一些简单的示例。虽然在LR帮助文档中,均有这些函数的用法及示例程序,但仍希望对想学LR编程的朋友提供些帮助。希望高手勿喷!
所有示例均在LR8.1下运行通过。
有兴趣的朋友可共同学习研究,欢迎反馈。
个人新建Q群:288793120 。多年收集整理测试资料,慢慢整理后上传到51论坛及Q群中。
一、lr_advance_param(const char *param);
/*
---------------------
lr_advance_param(const char *param);
使指定的参数获取下一个可用值
示例程序中:参数WEB有两个值 baidu,bing ;
---------------------
*/
Action()
{
web_url("WEBSite",
"URL=http://www.{WEB}.com",
"Resource=0",
"Mode=HTML",
LAST);
lr_advance_param("WEB");
lr_message("下一个参数值为:%s",lr_eval_string("{WEB}"));
web_url("WEBSite",
"URL=http://www.{WEB}.com",
"Resource=0",
"Mode=HTML",
LAST);
return 0 ;
}
/*
输出结果为
---------------------
Starting action Action.
Action.c(7): Found resource "http://www.baidu.com/img/baidu_sylogo1.gif" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(7): Found resource "http://www.baidu.com/cache/global/img/gs.gif" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(7): Found resource "http://s1.bdstatic.com/r/www/cache/global/js/home-2.0.js" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(7): Found resource "http://s1.bdstatic.com/r/www/cache/global/js/tangram-1.3.4c1.0.js" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(7): Found resource "http://s1.bdstatic.com/r/www/cache/user/js/u-1.3.4.js" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(7): web_url("WEBSite") was successful, 24799 body bytes, 2268 header bytes, 38 chunking overhead bytes [MsgId: MMSG-26385]
下一个参数值为:bing
Action.c(17): Redirecting "http://www.bing.com" (redirection depth is 0) [MsgId: MMSG-26694]
Action.c(17): To location "http://cn.bing.com/" [MsgId: MMSG-26693]
Action.c(17): web_url("WEBSite") was successful, 15291 body bytes, 1329 header bytes, 18 chunking overhead bytes [MsgId: MMSG-26385]
Ending action Action.
---------------------
*/
二、lr_decrypt(const char *EncodedString)
/*
---------------------
char * lr_decrypt(const char *EncodedString)
解译密文,并返回解释后的值
示例程序中:反译出密文的值为 Welcome;
---------------------
*/
Action()
{
char chr[32] ,*stri;
stri = lr_decrypt("38620da61ca1093e7aa7ec");
lr_message("%s",stri);
return 0 ;
}
/*
输出结果为
---------------------
Starting action Action.
WELCOME
Ending action Action.
---------------------
*/
三、char *lr_eval_string( const char *instring );
/*
---------------------
char *lr_eval_string( const char *instring );
从程序参数中,返回字符串值
int lr_save_string( const char *param_value, const char *param_name);
示例程序中:
---------------------
*/
Action()
{
char *web;
lr_save_string("163","web");
lr_message("%s",lr_eval_string("the web value is {web} "));
return 0 ;
}
/*
输出结果为
---------------------
Starting action Action.
the web value is 163
Ending action Action.
---------------------
*/
四、lr_next_row( const char *dat_file );
/*
---------------------
int lr_next_row( const char *dat_file );
参数说明:参数化的文件名称 如username.dat
示例程序:
---------------------
*/
Action()
{
web_url("WEBSite",
"URL=http://www.{WEB}.com",
"Resource=0",
"Mode=HTML",
LAST);
lr_next_row("WEB.dat");
lr_message("下一个参数值为:%s",lr_eval_string("{WEB}"));
web_url("WEBSite",
"URL=http://www.{WEB}.com",
"Resource=0",
"Mode=HTML",
LAST);
return 0 ;
}
/*
输出结果为
---------------------
Action.c(10): Found resource "http://www.baidu.com/img/baidu_sylogo1.gif" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(10): Found resource "http://www.baidu.com/cache/global/img/gs.gif" in HTML "http://www.baidu.com" [MsgId: MMSG-26659]
Action.c(15): Notify: Transaction "baidu" ended with "Pass" status (Duration: 2.0035 Wasted Time: 0.9352).
下一个参数值为:bing
Action.c(31): Redirecting "http://www.bing.com" (redirection depth is 0) [MsgId: MMSG-26694]
---------------------
*/
五、lr_save_int( int value, const char *param_name);
/*
---------------------
int lr_save_int( int value, const char *param_name);
将整形值保存到参数 param_name 中
该函数会先将整形值转为string,然后保存到参数中,如果该参数不存在,则会自动创建
示例程序:
---------------------
*/
Action()
{
int num;
num = 5 ;
lr_save_int(num * 2,"param1");
lr_message("%s",lr_eval_string("{param1}"));
return 0 ;
}
输出结果为 10 ; |
|