LoadRunner——LoadRunner接口测试的例子

    xiaoxiao2023-05-27  3

    转自:http://www.51testing.com/html/87/300987-805230.html

    做过一段时间的接口测试任务,下面把一段接口测试的脚本分享出来:

        Action() {

    //首先调用web_reg_find()这个注册函数,我们接口的正常返回结果都是<Code>0</Code>     web_reg_find("Search=Body", //定义查找范围     "SaveCount=result", //定义查找计数变量名称     "Text=<Code>0</Code>", //定义查找内容      LAST);

     //发送请求  web_submit_data("FollowersGetByName",   "Action=http://10.240.248.103:7004/Following/FollowersGetByName.ashx?",   "Method=POST",   "Referer=http://10.240.248.103:7004/Following/FollowerGetByName.ashx?",         "Mode=HTML",   ITEMDATA,

    //Name后面的值都是接口参数值,可以参考开发人员提供的接口设计文档或者录制脚本获得

    //接口的参数值一般都要参数化,尽可能的模拟真是场景   "Name=userid","Value={NewParam}",ENDITEM,   "Name=snsid","Value=6000",ENDITEM,   "Name=username","Value={myUserName}",ENDITEM,                 LAST);

      

    //刚才的web_reg_find()注册函数派上用处,可以对结果进行统计

      if (atoi(lr_eval_string("{result}")) > 0) //判断如果<Code>0</Code>                                                //字符串出现次数大于0         lr_output_message("Log on successful."); //在日志中输出Log on successful     else   //如果出现次数小于等于        lr_error_message("Log on failed"); //在日志中输出Log on failed

     return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1260761.html
    最新回复(0)