当前位置: 代码迷 >> 综合 >> loadrunner socket脚本不会录制, 写写看
  详细解决方案

loadrunner socket脚本不会录制, 写写看

热度:88   发布时间:2023-12-14 14:04:30.0

loadrunner socket脚本编写:[loadrunner 录制脚本不会用,也不是很懂,还是写吧]

1、创建 windows socket 脚本,如图这样子

2、Action 中的脚本:

 

#include "lrs.h"

Action()
{
    char *noticeReply;
    char *result;
    int rc=0;
    int receive_code;
    //建立socket
    rc=lrs_create_socket("socket0","TCP","RemoteHost=127.0.0.1:8082",LrsLastArg);
    if (0==rc) {
        lr_output_message("Socket was successfully created ");
    }
    else
    {
        lr_output_message("An error occurred while creating the socket, Error Code: %d",rc);
    }

    //开始事务
    lr_start_transaction("socket_trans");

    //发送数据
    lrs_send("socket0","buf0",LrsLastArg); 

    //结束发送
    //lrs_disable_socket("socket0", DISABLE_SEND);

    //接收服务端发回的数据
    receive_code=lrs_receive("socket0","buf1",LrsLastArg); 

    //实时接收返回报文,截取返回报文,字符串中第64位以后的4个字符,四个0000
     lrs_save_param("socket0",NULL,"noticeReply",61,4);

    // 处理中文乱码的问题
     lr_convert_string_encoding(lr_eval_string("<noticeReply>"),"utf-8",NULL,"result");

    //打印处理完中文乱码后的信息
    lr_output_message("correlation=%s",lr_eval_string("<result>"));

    //我返回的报文中四个0000为成功,所以这样判断
    if (strcmp(lr_eval_string("<result>"),"0000")==0){
        lr_end_transaction("socket_trans",LR_PASS);
    }
    else
    {
        lr_end_transaction("socket_trans",LR_FAIL);
    }
    //关闭打开的socket
    lrs_close_socket("socket0");

    return 0;
}

3、data.ws文件中实例,根据自己的情况改

;WSRData 2 1

send buf0 40

"00000032{'name':'zyw','address':'12345'}"

recv buf1 256

-1

4、遇到的问题。

①、接收到返回的数据,中文乱码。

 lr_convert_string_encoding(lr_eval_string("<noticeReply>"),"utf-8",NULL,"result");

②、判断脚本事物是否成功的标志的获取,百度下这个方法,好好理解换一下

 lrs_save_param("socket0",NULL,"noticeReply",61,4);

③、修改报文响应成功的标志

strcmp(lr_eval_string("<result>"),"0000")==0

  相关解决方案