原创

Loadrunner各种类型脚本实例

1、Tudedo协议-xml报文

vuser_init

#include "FDK.h"

vuser_init()
{

    #define username "usrname=monitor"
    #define passwd "passwd=monitor"

    static char *env_allow_array[] = { 
        "",
        "",
        NULL
    }; 


    //WSNADDR=//10.153.179.85:8801,TUXDIR=E:\\tuxedo
    fdk_connect_tux(env_allow_array, lr_eval_string("{WSNADDR}"), lr_eval_string("{TUXDIR}"), username, passwd);
    //fdk_connect_tux(env_allow_array, lr_eval_string("{WSNADDR}"), lr_eval_string("{TUXDIR}"), username, passwd);

    lrt_abort_on_error(); //if has ERROR stop now !

    /*test WSNADDR and TUXDIR 
    *******************************
    lr_message("ns1 = %s", lr_eval_string("?"));
    lr_message("ns2 = %s", lr_eval_string("?"));
    *******************************
    */



    return 0;


}

Action

Action()
{

    char*  sendBuf;
    char*  recvBuf;
    long recvLen=0;
    int TotalLen;

    sendBuf = lrt_tpalloc("STRING", "", 10000);
    recvBuf = lrt_tpalloc("STRING", "", 10000);


    sprintf(sendBuf,lr_eval_string( "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?>\n"
                            "<ROOT>\n"
                            "<ACCTID type=\"string\"></ACCTID>\n"
                            "<ACCTTYPE type=\"string\"></ACCTTYPE>\n"
                            "<BEGINDATE type=\"string\">20150101</BEGINDATE>\n"
                            "<ENDDATE type=\"string\">20150510</ENDDATE>\n"
                            "<SVCNUM type=\"string\">13739248661</SVCNUM>\n"
                            "<DEMAND type=\"string\">0</DEMAND>\n"
                            "</ROOT>\n"
                                    ));


    lr_start_transaction("Qpayrec_缴费记录查询");

    //lr_message("报文 = %s",sendBuf);

    TotalLen = strlen(sendBuf);

    //lr_message("报文长度 = %d",TotalLen);

    tpresult_int = lrt_tpcall("Qpayrec", (char *)sendBuf, TotalLen, (char **)&recvBuf, &recvLen, 0);

    //lr_message("aaaaaaa%s", recvBuf);

    fdk_save_search_LRBound_string(recvBuf, "<RETURN_CODE type=\"long\">", "</RETURN_CODE>", "RespondCode");


    if(strcmp("000000", lr_eval_string ("{RespondCode_1}")) == 0) 
    {
        lr_end_transaction("Qpayrec_缴费记录查询", LR_AUTO);
    }
    else
    {
        lr_end_transaction("Qpayrec_缴费记录查询", LR_FAIL);
        //fdk_save_search_LRBound_string(recvBuf,"<RETURN_CODE type=\"long\">","</RETURN_CODE>","RETURN_CODE");
        lr_error_message("RETURN_CODE = %s\n;Id reciveBuf:\n%s", lr_eval_string("{RETURN_CODE_1}"), recvBuf);
    }

    lrt_tpfree(sendBuf);
    lrt_tpfree(recvBuf);
    free(sendBuf);
    free(recvBuf);

    return 0;
}

2、Tuxedo协议-json报文-嵌套

vuser_init

#include "FDK.h"

vuser_init()
{

    #define username "usrname=111111"
    #define passwd "passwd=111111"

    static char *env_allow_array[] = { 
        "",
        "",
        NULL
    }; 



    fdk_connect_tux(env_allow_array, lr_eval_string("{WSNADDR}"), lr_eval_string("{TUXDIR}"), username, passwd);

    lrt_abort_on_error(); //if has ERROR stop now !

    /*test WSNADDR and TUXDIR 
    *******************************
    lr_message("ns1 = %s", lr_eval_string("?"));
    lr_message("ns2 = %s", lr_eval_string("?"));
    *******************************
    */


//10.153.195.36:10551
    //return 0;


}

Action

Action()
{

    char*  sendBuf;
    char*  recvBuf;
    long recvLen=0;
    int TotalLen;

    sendBuf = lrt_tpalloc("STRING", "", 10000);
    recvBuf = lrt_tpalloc("STRING", "", 10000);


    //************************先调用获取业务流水***********************************/
    //json
    sprintf(sendBuf,lr_eval_string("{\"ROOT\":{\"UserAreaCode\":\"A\",\"OptType\":\"P\"}}")); 

    lr_start_transaction("getoptsn_获取流水");

    //lr_message("报文 = %s",sendBuf);

    TotalLen = strlen(sendBuf);

    //lr_message("报文长度 = %d",TotalLen);

    tpresult_int = lrt_tpcall("getoptsn", (char *)sendBuf, TotalLen, (char **)&recvBuf, &recvLen, 0);

    //lr_message("aaaaaaa%s", recvBuf);

    fdk_save_search_LRBound_string(recvBuf, "\"RETURN_CODE\":\"", "\",", "RespondCode");

    if(strcmp("000000", lr_eval_string ("{RespondCode_1}")) == 0) 
    {
        lr_end_transaction("getoptsn_获取流水", LR_AUTO);
    }
    else
    {
        lr_end_transaction("getoptsn_获取流水", LR_FAIL);
        lr_error_message("RETURN_CODE = %s\n;Id reciveBuf:\n%s", lr_eval_string("{RETURN_CODE_1}"), recvBuf);
    }

    //================获取业务流水,作为下次使用=======
    fdk_save_search_LRBound_string(recvBuf, "\"NewOptSn\":\"", "\"}", "RespondCodeSN");


    lr_save_var( lr_eval_string("{RespondCodeSN_1}"), 14, 0, "DateTime_1");

    //sprintf(sendBuf,lr_eval_string("{\"ROOT\":{\"ImSetAccount\":\"G\",\"LastOptTime\":\"{Current_time}{DateTime}\",\"Balance\":\"403.81\",\"LateFeeFavored\":\"1\",\"PayManner\":\"-1\",\"NoSMSFlag\":\"0\",\"GroupPayType\":\"0\",\"PayFlag\":\"\",\"PayNumStr\":\"\",\"TERMINALTYPE\":\"1\",\"PayPath\":\"0\",\"OptCode\":\"G\",\"INVCCOUNT\":\"1\",\"advanFlag\":\"\",\"INVCSTR1\":\"M2001    {RespondCodeSN_1}|安徽移动通信客户交费凭证|2013|12|25|潘霈晨|品牌标识:全球通|{Phone_NO}|||壹圆零角零分|1.00|项目|金额(元)|||本次交费|1.00|||||||||||上次结余|2006641.00|||本次结余|2006642.00|||||||||||||||||||||||||||||||||||截止到2013年06月20日已使用话费:0.00||||截止到2013年06月20日可用余额:2006642.00||||2013|12|01|2013|12|31|全椒县马厂镇黄庵佩武通信器材经营部|\",\"INVCSTRNEW1\":\"2013年06月20日|邮政通信业-电信|||收款方名称:中国移动通信集团安徽有限公司滁州分公司||||税务登记证号:341102743081745||||付款方名称:潘霈晨|品牌标识:全球通|||移动号码:{Phone_NO}||||合计金额:壹圆零角零分|¥ 1.00|||||||项目|金额(元)|||本次交费|1.00|||||||||||||||||||||||||||||||||||||||||||||||||||当前可用余额:2006642.00元||||流水号:{RespondCodeSN_1}|工号:M00000SYS|全椒县马厂镇黄庵佩武通信器材经营部||\",\"IN_DATA\":{\"DATA\":{\"DATA01\":\"1\",\"DATA02\":\"{RespondCodeSN_1}\",\"DATA03\":\"1\",\"DATA04\":\"{RespondCodeSN_1}\",\"DATA05\":\"\",\"DATA06\":\"\",\"DATA07\":\"\",\"DATA08\":\"111000001\",\"DATA09\":\"{ID_NO}\",\"DATA10\":\"{Contract_NO}\",\"DATA11\":\"001\",\"DATA12\":\"W1018884\",\"DATA13\":\"{Phone_NO}\",\"DATA14\":\"0.00\",\"DATA15\":\"0.00\",\"DATA16\":\"0.00\",\"DATA17\":\"5.00\",\"DATA18\":\"5.00\",\"DATA19\":\"{Current_time}{DateTime}\",\"DATA20\":\"20991231235959\",\"DATA21\":\"0\",\"DATA22\":\"F\",\"DATA23\":\"0\",\"DATA24\":\"A00000SYS\",\"DATA25\":\"111000000\",\"DATA26\":\"\",\"DATA27\":\"前台交费\",\"DATA28\":\"0\",\"DATA29\":\"\",\"DATA30\":\"1\",\"DATA31\":\"0\",\"DATA32\":\"1001\",\"DATA33\":\"0\",\"DATA34\":\"0\",\"DATA35\":\"5.00\",\"DATA36\":\"\",\"DATA37\":\"01020\",\"DATA38\":\"\",\"DATA39\":\"\",\"DATA40\":\"\",\"DATA41\":\"\",\"DATA42\":\"\",\"DATA43\":\"\",\"DATA44\":\"\"}}}}"));
    sprintf(sendBuf,lr_eval_string("{\"ROOT\":{\"ImSetAccount\":\"G\",\"LastOptTime\":\"{Current_time}{DateTime}\",\"Balance\":\"403.81\",\"LateFeeFavored\":\"1\",\"PayManner\":\"-1\",\"NoSMSFlag\":\"0\",\"GroupPayType\":\"0\",\"PayFlag\":\"\",\"PayNumStr\":\"\",\"TERMINALTYPE\":\"1\",\"PayPath\":\"0\",\"OptCode\":\"G\",\"INVCCOUNT\":\"1\",\"advanFlag\":\"\",\"INVCSTR1\":\"M2001    {RespondCodeSN_1}|安徽移动通信客户交费凭证|2013|12|25|潘霈晨|品牌标识:全球通|{Phone_NO}|||壹圆零角零分|1.00|项目|金额(元)|||本次交费|1.00|||||||||||上次结余|2006641.00|||本次结余|2006642.00|||||||||||||||||||||||||||||||||||截止到2013年06月20日已使用话费:0.00||||截止到2013年06月20日可用余额:2006642.00||||2013|12|01|2013|12|31|全椒县马厂镇黄庵佩武通信器材经营部|\",\"INVCSTRNEW1\":\"2013年06月20日|邮政通信业-电信|||收款方名称:中国移动通信集团安徽有限公司滁州分公司||||税务登记证号:341102743081745||||付款方名称:潘霈晨|品牌标识:全球通|||移动号码:{Phone_NO}||||合计金额:壹圆零角零分|¥ 1.00|||||||项目|金额(元)|||本次交费|1.00|||||||||||||||||||||||||||||||||||||||||||||||||||当前可用余额:2006642.00元||||流水号:{RespondCodeSN_1}|工号:M00000SYS|全椒县马厂镇黄庵佩武通信器材经营部||\",\"IN_DATA\":{\"DATA\":{\"DATA01\":\"1\",\"DATA02\":\"{RespondCodeSN_1}\",\"DATA03\":\"1\",\"DATA04\":\"{RespondCodeSN_1}\",\"DATA05\":\"\",\"DATA06\":\"\",\"DATA07\":\"\",\"DATA08\":\"111000001\",\"DATA09\":\"{Contract_NO}\",\"DATA10\":\"{ID_NO}\",\"DATA11\":\"001\",\"DATA12\":\"W1018884\",\"DATA13\":\"{Phone_NO}\",\"DATA14\":\"0.00\",\"DATA15\":\"0.00\",\"DATA16\":\"0.00\",\"DATA17\":\"5.00\",\"DATA18\":\"5.00\",\"DATA19\":\"{Current_time}{DateTime}\",\"DATA20\":\"20991231235959\",\"DATA21\":\"0\",\"DATA22\":\"F\",\"DATA23\":\"0\",\"DATA24\":\"A00000SYS\",\"DATA25\":\"111000000\",\"DATA26\":\"\",\"DATA27\":\"前台交费\",\"DATA28\":\"0\",\"DATA29\":\"\",\"DATA30\":\"1\",\"DATA31\":\"0\",\"DATA32\":\"1001\",\"DATA33\":\"0\",\"DATA34\":\"0\",\"DATA35\":\"5.00\",\"DATA36\":\"\",\"DATA37\":\"01020\",\"DATA38\":\"\",\"DATA39\":\"\",\"DATA40\":\"\",\"DATA41\":\"\",\"DATA42\":\"\",\"DATA43\":\"\",\"DATA44\":\"\"}}}}"));

    //************************开始交费***********************************/

    lr_start_transaction("jf000032_营业交费");

    //lr_message("报文 = %s",sendBuf);

    TotalLen = strlen(sendBuf);

    //lr_message("报文长度 = %d",TotalLen);

    tpresult_int = lrt_tpcall("jf000032", (char *)sendBuf, TotalLen, (char **)&recvBuf, &recvLen, 0);

    //lr_message("aaaaaaa%s", recvBuf);

    fdk_save_search_LRBound_string(recvBuf, "\"RETURN_CODE\":\"", "\",", "RespondCode");

    if(strcmp("000000", lr_eval_string ("{RespondCode_1}")) == 0) 
    {
        lr_end_transaction("jf000032_营业交费", LR_PASS);
    }
    else
    {
        lr_end_transaction("jf000032_营业交费", LR_FAIL);

        lr_error_message("RETURN_CODE = %s\n;Id reciveBuf:\n%s", lr_eval_string("{RETURN_CODE_1}"), recvBuf);
    }

    lrt_tpfree(sendBuf);
    lrt_tpfree(recvBuf);
    free(sendBuf);
    free(sendBuf);

    return 0;

}

3、WebService接口-json报文-Http调用

Action

Action()
{

    lr_start_transaction("QryNoInfoByNo_资源查号码信息");

    web_reg_save_param("Return_Code","LB=RETURN_CODE\":\"","RB=\",",LAST);

    web_custom_request("sGSQ_QueryScore", 
        //"URL=http://10.152.30.101:51300/esbWS/rest/MainService_QT",
         "URL=http://152.55.249.46:51000/esbWS/rest/MainService", 
        "Method=POST",
        "TargetFrame=", 
        "Resource=1", 
        "RecContentType=text/html", 
        "Referer=", 
        "Mode=HTML", 
        "EncType=application/json",
        "Body={ \"ROOT\": { \"REQUEST_METHOD\": \"QryNoInfoByNo\", \"BAT_ID\": \"\", \"SEND_TIME\": \"\", \"REQUEST_INFO\": { \"PHONE_NO\": \"{Phone_no}\", \"OP_CODE\": \"1000\", \"RES_STATUS\": \"0\", \"LOGIN_NO\": \"M3ABB0076\", \"CHECK_FLAG\": \"1\" } } }",
        LAST);

   // lr_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
    if(strcmp("0000", lr_eval_string ("{Return_Code}")) == 0) 
    {
        lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_AUTO);
    }
    else
    {
        lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_FAIL);
        lr_error_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
    }


    return 0;
}

4、Webservice接口-xml报文-http调用

Action

Action()
{

    lr_start_transaction("QryNoInfoByNo_资源查号码信息");

    web_reg_save_param("Return_Code","LB=RETURN_CODE type=\"string\">","RB=<",LAST);

    web_url("callService", 
        "URL=http://10.152.30.95:51000/esbWS/services/MainService/callService?pin=<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?><ROOT>   <REQUEST_METHOD type=\"string\" >QryNoInfoByNo</REQUEST_METHOD><BAT_ID type=\"string\" ></BAT_ID>   <SEND_TIME type=\"string\" ></SEND_TIME> <REQUEST_INFO><PHONE_NO type=\"string\" >{Phone_no}</PHONE_NO><OP_CODE type=\"string\" >1000</OP_CODE><RES_STATUS type=\"string\" >0</RES_STATUS><LOGIN_NO type=\"string\" >M3ABB0076</LOGIN_NO><CHECK_FLAG  type=\"string\" >1</CHECK_FLAG></REQUEST_INFO></ROOT>", 
        "TargetFrame=", 
        "Resource=1", 
        "RecContentType=application/xml", 
        "Referer=", 
        "Snapshot=t1.inf", 
        LAST);

    // lr_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));

    if(strcmp("0000", lr_eval_string ("{Return_Code}")) == 0) 
    {
            lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_AUTO);
    }
    else
    {
            lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_FAIL);
            lr_error_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
    }

    return 0;
}

5、WebService接口-Soap调用

需要导入wsdl文件或者地址
Action

#include "FDK.h"
Action()
{

    lr_start_transaction("QuickPayment");

    web_service_call( "StepName=callService_101",
        "SOAPMethod=QuickPayment|QuickPaymentHttpSoap11Endpoint|callService",
        "ResponseParam=response",
        "Service=QuickPayment",
        "ExpectedResponse=SoapResult",
        "Snapshot=t1431587102.inf",
        BEGIN_ARGUMENTS,
        "pin=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                        "<ROOT>\n"
                            "<STATUS type=\"string\">D</STATUS>\n"
                            "<ORDER_ID type=\"string\">{date_time}{random}</ORDER_ID>\n"
                            "<ACJFCODE type=\"string\">ACJF10902</ACJFCODE>\n"
                            "<ACJFSEQ type=\"string\">01</ACJFSEQ>\n"
                            "<PAY_CHN type=\"string\">09</PAY_CHN>\n"
                            "<BANK_CODE type=\"string\">ACJF10902</BANK_CODE>\n"
                            "<LOGIN_NO type=\"string\">{Login_no}</LOGIN_NO>\n"
                        "<REGIN_NO type=\"string\"/>\n"
                        "<OPT_CODE type=\"string\"/>\n"
                        "<PERCENT type=\"string\">99</PERCENT>\n"
                        "<PAY_PERSON type=\"string\">{Phone_no}</PAY_PERSON>\n"
                        "<PAY_PERSON_TYPE type=\"string\">1</PAY_PERSON_TYPE>\n"
                        "<ISROLLBACK type=\"string\"/>\n"
                        "<IN_DATA>\n"
                            "<DATA>\n"
                                "<FOREIGNSN type=\"string\">{date_time}{random}</FOREIGNSN>\n"
                                "<FOREIGNTIME type=\"string\">20150513192520</FOREIGNTIME>\n"
                                "<PAY_ID type=\"string\">{Phone_no}</PAY_ID>\n"
                                "<PAY_ID_TYPE type=\"string\">1</PAY_ID_TYPE>\n"
                                "<PAY_AMOUNT type=\"string\">5000</PAY_AMOUNT>\n"
                            "<DISCOUNT type=\"string\"/>\n"
                        "<CHARGEMONEY type=\"string\"/>\n"
                        "<ACTIVITYNO type=\"string\"/>\n"
                        "<PRODUCTNO type=\"string\"/>\n"
                        "<RESERVE1 type=\"string\"/>\n"
                        "<RESERVE2 type=\"string\"/>\n"
                        "<RESERVE3 type=\"string\"/>\n"
                        "<RESERVE4 type=\"string\"/>\n"
                        "<RESERVE5 type=\"string\"/>\n"
                        "</DATA>\n"
                        "</IN_DATA>\n"
                        "</ROOT>\n",


        END_ARGUMENTS,


        BEGIN_RESULT,
        "return=Param_return_Code",
        END_RESULT,
        LAST);

        //lr_log_message("Param_return_Code=%s", lr_eval_string("{Param_return_Code}"));

        fdk_save_search_LRBound_string(lr_eval_string("{Param_return_Code}"), "RETURN_CODE type=\"long\">", "</RETURN_CODE>", "Return_Code");

        //lr_log_message("Return_Code=%s", lr_eval_string("{Return_Code_1}"));

        //判断返回是否正确
        if(strcmp("000000", lr_eval_string ("{Return_Code_1}"))==0)
        {
            lr_end_transaction("QuickPayment", LR_AUTO);
        }
        else
        {
            lr_end_transaction("QuickPayment", LR_FAIL);
            //fdk_save_search_LRBound_string(recvBuf,"<RETURN_CODE type=\"long\">","</RETURN_CODE>","RETURN_CODE");
            lr_error_message("Id reciveBuf:\n%s", lr_eval_string("{Param_return_Code}"));
        }


    return 0;
}

6、Rest请求-Http调用

Action

Action()
{

    lr_start_transaction("QryNoInfoByNo_资源查号码信息");

    web_reg_save_param("Return_Code","LB=RETURN_CODE\":\"","RB=\",",LAST);

    web_custom_request("sGSQ_QueryScore", 
        //"URL=http://10.152.30.101:51300/esbWS/rest/MainService_QT",
         "URL=http://152.55.249.46:51000/esbWS/rest/MainService", 
        "Method=POST",
        "TargetFrame=", 
        "Resource=1", 
        "RecContentType=text/html", 
        "Referer=", 
        "Mode=HTML", 
        "EncType=application/json",
        "Body={ \"ROOT\": { \"REQUEST_METHOD\": \"QryNoInfoByNo\", \"BAT_ID\": \"\", \"SEND_TIME\": \"\", \"REQUEST_INFO\": { \"PHONE_NO\": \"{Phone_no}\", \"OP_CODE\": \"1000\", \"RES_STATUS\": \"0\", \"LOGIN_NO\": \"M3ABB0076\", \"CHECK_FLAG\": \"1\" } } }",
        LAST);

   // lr_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
    if(strcmp("0000", lr_eval_string ("{Return_Code}")) == 0) 
    {
        lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_AUTO);
    }
    else
    {
        lr_end_transaction("QryNoInfoByNo_资源查号码信息", LR_FAIL);
        lr_error_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
    }


    return 0;
}

7、Socket接口

Action

#include "lrs.h"


Action()
{
    char *recvbuf;
    int revclen=0;
    int rc;
    lr_start_transaction("TEST");

    //创建socket连接
    rc=lrs_create_socket("socket0", "TCP", "RemoteHost=10.243.29.114:12130",  LrsLastArg);

    if(rc==0){

        lr_output_message("Socket was successfully created");
    }

    else{

        lr_output_message("An error occurred while creating the socket,Error Code:%d",rc);

    }


    // 发送消息
    lrs_send("socket0", "buf0", LrsLastArg);
    lrs_receive("socket0", "buf1",  LrsLastArg); 
    lrs_get_last_received_buffer("socket0",&recvbuf,&revclen);

    //根据字节数参数化取值
    //lrs_save_param_ex("socket0", "received", "buf1", 87, 6,"ebcdic", "param_1_ex"); 

    //根据左右边界参数化取值
    lrs_save_searched_string ("socket0", NULL, "param_1_ex", "LB/BIN=~!~", "RB/BIN=~!~", 1, 0, -1); 

    if(strcmp("0000", lr_eval_string ("<param_1_ex>")) == 0){

        lrs_close_socket("socket0");
        lr_end_transaction("TEST", LR_AUTO);
    }
    else
    {
            lr_end_transaction("TEST", LR_FAIL);
            lr_error_message("errorinfo:%s", recvbuf);

    }

    lrs_free_buffer(recvbuf);

    return 0;
}

data.ws

;WSRData 2 1

send buf0 5
    "000209~!~01~!~01~!~L<Ram_No>8621<Time>~!~13655536203~!~12310006999867~!~12~!~00~!~S01~!~101~!~M0AAA0H01~!~~!~38~!~~!~60016~!~10000~!~~!~1~!~12288~!~2500~!~U1~!~20161001000000~!~20161214235959~!~1~!~LLBP0820~!~"
recv buf1 908
""


-1

8、WEB-HTTP/HTML脚本

Action

Action()
{
    lr_start_transaction("秒杀业务");


    web_add_cookie("WEBTRENDS_ID=11.11.11.11-1477658331.175031; DOMAIN=www.xx.xx.cn");

    web_add_cookie("WT_FPC=id=202c8214ec2beda87021477658706449:lv=1477658716342:ss=1477658706449; DOMAIN=www.xx.xx.cn");

    web_url("zd_title_1.html", 
        "URL=http://act.xxxxx.cn:8000/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t8.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=style/images/qg_title_bg.png", ENDITEM, 
        "Url=images/gotop.png?t=1477673349787", ENDITEM, 
        "Url=http://www.xx.xx.cn/webtrends/dcs.gif?&dcsdat=1477673349772&dcssip=act.xxxxx.cn&dcsuri=/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html&WT.co_f=20f9a3aab89725ce2941477673350421&WT.Branch=sc_cp&WT.es=http%253A%252F%252Fact.xxxxx.cn%253A8000%252Factivity%252Fdeploy%252FCPMS%252Fflash%252FAC20161028194926%252Fzd_title_1.html&WT.host=act.xxxxx.cn&WT.vt_f=2", ENDITEM, 
        "Url=http://www.xx.xx.cn/webtrends/dcs.gif?&dcsdat=1477673356128&dcssip=act.xxxxx.cn&dcsuri=/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html&WT.co_f=26f950d7975ab46cea91477673356128&WT.Branch=sc_cp&WT.es=http%253A%252F%252Fact.xxxxx.cn%253A8000%252Factivity%252Fdeploy%252FCPMS%252Fflash%252FAC20161028194926%252Fzd_title_1.html&WT.host=act.xxxxx.cn&WT.vt_f=2&WT.event=JavaScript%253A%25E9%25A9%25AC%25E4%25B8%258A%25E6%258A%25A2&WT.dl=22&WT.nv=scroll_content_20161028235105&"
        "WT.pos=277x147", ENDITEM, 
        "Url=http://www.xx.xx.cn/webtrends/dcs.gif?&dcsdat=1477673356130&dcssip=act.xxxxx.cn&dcsuri=/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html&WT.co_f=2b46c8f9c3ecb93f2411477673356130&WT.Branch=sc_cp&WT.es=http%253A%252F%252Fact.xxxxx.cn%253A8000%252Factivity%252Fdeploy%252FCPMS%252Fflash%252FAC20161028194926%252Fzd_title_1.html&WT.host=act.xxxxx.cn&WT.vt_f=2&WT.event=%2520msq&WT.nv=xsms20160527", ENDITEM, 
        "Url=http://www.xx.xx.cn/webtrends/dcs.gif?&dcsdat=1477673361908&dcssip=act.xxxxx.cn&dcsuri=/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html&WT.co_f=24af6782512b7292aae1477673361908&WT.Branch=sc_cp&WT.es=http%253A%252F%252Fact.xxxxx.cn%253A8000%252Factivity%252Fdeploy%252FCPMS%252Fflash%252FAC20161028194926%252Fzd_title_1.html&WT.host=act.xxxxx.cn&WT.vt_f=2&WT.event=JavaScript%253A%25E7%25A1%25AE%25E8%25AE%25A4&WT.dl=22&WT.nv=pop-1&WT.pos=151x197", ENDITEM, 
        LAST);

    web_submit_data("getStockInfo.do", 
        "Action=http://act.xxxxx.cn:8000/activity/flash/getStockInfo.do?rd=1477673349885", 
        "Method=POST", 
        "RecContentType=text/html", 
        "Referer=http://act.xxxxx.cn:8000/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html", 
        "Snapshot=t9.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=actId", "Value=AC20161028194926", ENDITEM, 
        "Name=periodId", "Value=05c0c6e3ddfe460e90ea34c00c175b4d", ENDITEM, 
        "Name=acProductId", "Value=a1497ecfe6944819b23f2cadfef21902", ENDITEM, 
        EXTRARES, 
        "Url=http://download1.operacdn.com/res/servicefiles/browserjsfiles/mobile/browserjs-Mobile-12.10-20160602.js", "Referer=", ENDITEM, 
        LAST);

    //{"code":"000000",
    web_reg_save_param("Return_Code","LB=\"code\":\"","RB=\",",LAST);


    lr_rendezvous("秒杀开始");


    lr_start_transaction("点击抢购");


    web_custom_request("index.do", 
        "URL=http://act.xxxxx.cn:8000/activity/flash/index.do?rd=1477673356130&actId=AC20161028194926&platformId=CPMS&productId=a1497ecfe6944819b23f2cadfef21902&keyWords=Unlimited&acType=flash&operatorType=0&productType=QTDD", 
        "Method=POST", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://act.xxxxx.cn:8000/activity/deploy/CPMS/flash/AC20161028194926/zd_title_1.html", 
        "Snapshot=t11.inf", 
        "Mode=HTML", 
        "EncType=", 
        LAST);

    if(strcmp("000000", lr_eval_string ("{Return_Code}")) == 0) 
        {
            lr_end_transaction("点击抢购", LR_PASS);
        }
        else
        {
            lr_end_transaction("点击抢购", LR_FAIL);

            lr_error_message("RETURN_CODE = %s\n", lr_eval_string("{Return_Code}"));
        }

    lr_end_transaction("秒杀业务", LR_AUTO);

    return 0;
}

9、WEB-HTTP/HTM java脚本

Action


/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */

import lrapi.*;

public class Actions
{

    public int init() throws Throwable {
        return 0;
    }//end of init


    public int action() throws Throwable {
        String url = "http://localhost:8080/AutoTest/";

        lr.start_transaction("登录");

        web.reg_save_param("return_code_login",new String[]{
                           "LB={\"returnCode\":",
                           "RB=","SaveOffset=0","SaveLen=1",
                           "LAST"});

        web.submit_data("loginAction",
                       "Action="+url+"user-toLogin",
                       new String[]{
                       "Method=POST",
                       "RecContentType=application/json",
                       "Mode=HTML"
                       },
                       new String[]{
                       "Name=username","Value=admin",web.ENDITEM,
                       "Name=password","Value=q708162543",web.ENDITEM,
                       web.LAST
                       });

        if(lr.eval_string("{return_code_login}").equals("0")){
            lr.end_transaction("登录",lr.AUTO);
        }else{
            lr.error_message("登录失败:returnCode="+lr.eval_string("{return_code_login}"));
            lr.end_transaction("登录",lr.FAIL);
        }


        lr.start_transaction("获取登录信息");
        web.reg_save_param("return_code",new String[]{
                           "LB={\"returnCode\":",
                           "RB=","SaveOffset=0","SaveLen=1",
                           "LAST"});
        web.url("localhost", 
                "URL="+url+"user-getLoginUserInfo", 
                new String[]{ 
                    "TargetFrame=", 
                    //"TargetBrowser=Mercury Technologies", 
                    "Resource=0", 
                    "RecContentType=application/json", 
                    "Snapshot=t1.inf", 
                    "Mode=HTML", 
                    "LAST"});

        if(lr.eval_string("{return_code}").equals("0")){
            lr.end_transaction("获取登录信息", lr.AUTO);
        }else{
            lr.error_message(lr.eval_string("{return_code}"));
            lr.end_transaction("获取登录信息", lr.FAIL);
        }    

        return 0;
    }//end of action


    public int end() throws Throwable {
        return 0;
    }//end of end
}

附:公用函数库 FDK.h

下载地址: https://wwxe.lanzouj.com/iKBpS1e99v9e

正文到此结束