LoadRunner断言:正确结果有多种情况

用过lr的都知道,我们可以用web_reg_find这个注册函数判断某个请求的返回中是否有我们要找的内容,这就是检查点

但是,如果正常的情况有多种,该如何断言呢?

我们可以设置其他货币资金包括哪些内容多个检查点,把每个检查点获取到的结果数量相加,如果大于0,就表示请求成功,然后通过if条件,人工判断事务是否成功。

示例代码

Action()
{
int res = 0;
//int int_res = 0;
//char * string_res = (char*)calloc(100,sizeof(char)); // 请求存储空间

//设置检查点
web_reg_find("Text=\"code\":\"00\"","SaveCount=c00",LAST);
web_reg_find("Text=\"code\":\"8016\"","SaveCount=c8016",LAST);
web_reg_find("Text=\"code\":\"8017\"","SaveCount=c8017",LAST);
//web_reg_find("Text=\"code\":\"8001\"",LAST);

//获取response响应信息
//web_reg_save_param("response","LB=","RB=",LAST);

lr_start_transaction("payPause");
web_custom_request("activityHandler",
"URL=http://127.0.0.1:8081/payPause",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"Body={\"tokenId\":\"{tokenId}\",\"cardNo\":\"62010101{userAccount}\"}",
LAST);

res = atoi(lr_eval_string("{c00}"))+atoi(lr_eval_string("{c8016}"))+atoi(lr_eval_string("{c8017}"));

//下面四行是调试信息,int和string需要互转
//sprintf(string_res,"%d",res); //int转string
//lr_output_message("string_res = %s",string_res);
//int_res = atoi(string_res); //string转int,其实这里不需要转了,因为res已经是int,这里只是再次体现string如何转int
//lr_output_message("int_res = %d",int_res);

if (res > 0){
//lr_output_message("事务成功");
lr_end_transaction("payPause",LR_PASS);
}

  else{
  //lr_error_message("事务失败");
  lr_end_transaction("payPause",LR_FAIL);
}

//lr_convert_string_encoding(lr_eval_string("{response}"),LR_ENC_UTF8,"GBK","result");
//输出response响应信息
//lr_output_message( "返回response响应信息:%s",lr_eval_string("{result}"));

//lr_end_transaction("payPause", LR_AUTO);

return 0;
}

声明:如有侵权,请联系删除。

=========json解析==================== 升职加薪 ==========================