lr检查点

上一篇 / 下一篇  2017-06-23 15:17:21

LR脚本实例:

//登录事务开始

lr_start_transaction("trans_login");

//设置检查的内容,在savecount变量里面记录查找到的次数
web_reg_find("Text=欢迎您","SaveCount=loginss_count",LAST);

//登录(登录录制的自动生成代码)
web_submit_data("loginAction.do;jsessionid=16D156A310B3804B354123F7CDEE5211",
  "Action=http://****/loginAction.do;jsessionid={JSESSIONID2}",
  "Method=POST",
  ............
  LAST);

//检查登录是否成功。也可以使用:if(strcmp(lr_eval_string("{loginss_count}"),"0")==0)。strcmp、atoi都是C语言里面的函数。
if(atoi(lr_eval_string("{loginss_count}"))==0)

//打印出错误信息,同时把登录错误时的用户名、密码打印出来。也可以简单的:lr_output_message("login failed登录失败!");
   lr_error_message("login failed登录失败!username:%s,pwd:%s",lr_eval_string("{username}"),lr_eval_string("{pwd})"));
else
   lr_output_message("login successful登录成功!");

//登录事务结束

lr_end_transaction("trans_login", LR_AUTO);

网上摘录的web_reg_find用法:
web_reg_find
该函数的作用是“在缓存中查找相应的内容”,常用参数及含义如下:

web_reg_find("Search=Body", //定义查找范围

"SaveCount=ddd", //定义查找计数变量名称

"Text=aaaa", //定义查找内容

LAST);

使用该函数注意以下事项:

1、 位置

该函数写在要查找内容的请求之前,通常情况下写在如下六个函数之前:

Web_castom_request();web_image();web_link();web_submit_data();web_submit_form();web_url()

2、 使用技巧

在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到,下面举个例子来说明:(引用LR的帮助中的例子)

// Run the Web Tours sample

web_url("MercuryWebTours",

"URL=http://localhost/MercuryWebTours/",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

// Set up check for successful login by looking for "Welcome"

web_reg_find("Text=Welcome",

"SaveCount=Welcome_Count",

LAST);

// Now log in

web_submit_form("login.pl",

"Snapshot=t2.inf",

..........

LAST);

// Check result

if (atoi(lr__string("{Welcome_Count}")) > 0){ //判断如果Welcome字符串出现次数大于0

lr_output_message("Log on successful."); }//在日志中输出Log on successful

else{ //如果出现次数小于等于

lr_error_message("Log on failed"); //在日志中输出Log on failed

return(0); }


TAG:

 

评分:0

我来说两句

日历

« 2024-03-28  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 80425
  • 日志数: 94
  • 文件数: 1
  • 建立时间: 2017-04-14
  • 更新时间: 2020-11-17

RSS订阅

Open Toolbar