loadrunner socket指令碼不會錄製, 寫寫看
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);
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);
//結束髮送
//接收服務端發回的資料
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