Loadrunder脚本篇——web_custom_request做接口测试

Posted 残~枫~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Loadrunder脚本篇——web_custom_request做接口测试相关的知识,希望对你有一定的参考价值。

一、POST + JSON格式参数

例:

 

web_custom_request("create",

 

"URL=http://xxx.xxx.x.xx:1600/ditui/agentshop",

 

"Method=POST",

 

"Resource=0",

 

"RecContentType=application/json",

 

"Referer=",

 

"Mode=html",

 

"EncType=application/json;charset=UTF-8",

 

"Body={\"agentId\":31,"


"\"contactName\":\"test\","


"\"contactPhone\":\"18259001421\","

 

"\"fullName\":\"赖大家家里蹲分公司1\","

 

"\"shortName\":\"Le3JxD\","

 

"\"vipEmail\":\"[email protected]\","

 

"\"shopType\":\"1\","

 

"\"address\":\"广东省深圳市宝安区华侨新村29-B座204\","

 

"\"businessScope\":\"3\","

 

"\"businessLicenseCode\":\"140100200567176\","

 

"\"businessLicenseUrl\":\"2016/01/04/fcd1bde5-f64f-4aa6-82c9-82b65cd7ccfd.jpg\","

 

"\"province\":\"620000\","

 

"\"city\":\"620200\","

 

"\"area\":\"620201\","

 

"\"headAddress\":\"广东省深圳市宝安区\","

 

"\"legalName\":\"袁国新\","

 

"\"idCard\":\"451202198403264276\","

 

"\"idCardStartDate\":\"2010-10-06\","

 

"\"idCardEndDate\":\"2020-10-06\","

 

"\"idCardFrontUrl\":\"2016/01/06/d342b28d-c62d-416e-b947-47e47ab95d08.jpg\","

 

"\"idCardBackUrl\":\"2016/01/06/f03e967a-168c-4ba6-ba99-04a3c6790bf6.jpg\","

 

"\"phoneNumber\":\"18259001421\"}",

 

LAST);

 

 

运行结果:

技术分享图片

 

 

说明:Body写法

1)参数都写在一行

"Body={"arg1":int_value1,"arg2":"str_value2",…, "argN":"valueN"}",

 

2)参数不都在同一行

"Body={"arg1":value1,"

        ""arg2":"str_value2","

        ""arg3":"str_value3","

         ……

        ""argN":"valueN"}",

 

 

二、POST + 非JSON格式参数

例:

web_custom_request("login",

        "URL=http://127.0.0.1:1080/WebTours/login.pl",

        "Method=POST",

        "Resource=0",

        "RecContentType=",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Mode=HTML",

        "EncType=application/x-www-form-urlencoded",          

        "Body=userSession=117812.897691373zAzAAAApQcfDzDzApAAfff&username=jo

jo&password=bean&login.x=0&login.y=0&JSFormSubmit=off",

        LAST);

 

运行结果:

 

技术分享图片

 

三、GET

例:

web_custom_request("view_active_page",       

        "URL=http://xx.xxxxx.xxxx.cn/index.php?xx=/xxxx/Lucky/Christport/sav

e_user_info/id/726/token/84222366b2592714538e50dc69398ad7/open_id/ous64uNjaBudzU00000751vYH9k/nickname/test_user/headimgurl/testurl",

        "Method=GET",

        "Resource=0",

        "RecContentType=Application/json",

        "Referer=",

        "Mode=HTML",

        "EncType=application/x-www-form-urlencoded;charset=UTF-8",

        "Body=",

        LAST);

 

一个完整的例子

Join_active()

{

    web_reg_save_param("result",

        "LB=result\":",

        "RB=,\"",

        "NotFound=ERROR",

        "Search=All",

        LAST);

 

    lr_rendezvous("join_active");

 

    //参与抽奖

    lr_start_transaction("join_active");

 

 

    web_custom_request("choujiang",

        "URL=http://xx.xxx.xxxx/index.php?s=/addon/Lucky/Christport/lucky/id/726/open_id/{open_id}/token/84222366b2592714538e50dc69398ad7",

        "Method=GET",

        "Resource=0",

        "RecContentType=Application/json",

        "Referer=",

        "Mode=HTML",

        "EncType=application/x-www-form-urlencoded;charset=UTF-8",

        "Body=",

        LAST);

 

if(strcmp("102",lr_eval_string("{result}"))==0 || strcmp("103",lr_eval_string("{result}"))==0)

    {

 

            lr_end_transaction("join_active", LR_PASS);

 

    }else{

 

            lr_end_transaction("join_active", LR_FAIL);

 

    }

    return 0;

 

}







以上是关于Loadrunder脚本篇——web_custom_request做接口测试的主要内容,如果未能解决你的问题,请参考以下文章

Loadrunder脚本篇——关联数组(参数数组)

Loadrunder脚本篇——web_custom_request函数介绍

Loadrunder脚本篇——Run-time Settings之Miscellaneous

Loadrunder脚本篇——web_custom_request做接口测试

loadrunder之脚本篇——int类型和字符串的相互转换

Loadrunder脚本篇——Run-time Settings之Preferences