Things are often used in the performance test of loadrunner. To judge the server performance through things, how can we know that things are passed?
The functions of things passing and failing are as follows:
lr_end_transaction("thing", LR_PASS); //adopt lr_end_transaction("thing", LR_FAIL); //fail lr_end_transaction("thing", LR_AUTO); //Auto identify pass or fail
To judge, there must be judgment syntax. loadrunner uses the syntax of c language, so its code can be written in this way
if (expression) { lr_end_transaction("thing", LR_PASS); } else{ lr_end_transaction("thing", LR_FAIL); }
The next step is more important. What is the expression and how we should judge the passage of things. Here we use a function
//The whole return value is intercepted according to the left and right boundaries, and exists in the variable result web_reg_save_param("result", "LB={", "RB=}", "Search=Body", LAST);
Each interface will have a return value. The return header or the returned body can be used as the scope of search. Here, the body is used. If there is "operation succeeded" in the returned result, the thing passes. We can print it out and watch it in the background. Note that the return value with Chinese needs special processing
/The returned value is in Chinese and needs to be transcoded. The transcoded value exists msg in lr_convert_string_encoding(lr_eval_string("{result}"),"utf-8",NULL,"outmsg"); //Print return value lr_output_message("After transcoding outmsg----%s",lr_eval_string("{outmsg}")); n=strlen(lr_eval_string("{outmsg}")); lr_output_message("%d",n);
It's a bit lazy here. It's troublesome to intercept characters, so we can directly judge whether things pass by the returned character length.
All codes are as follows:
//The whole return value is intercepted according to the left and right boundaries, and exists in the variable result web_reg_save_param("result", "LB={", "RB=}", "Search=Body", LAST); //Interface to things lr_start_transaction("thing"); web_submit_data("web_submit_data", "Action=https://www.baidu.hhh.com/api/agggnee/relwulncy/getContactPhoneInfo", "Method=POST", "TargetFrame=", "RecContentType=application/json", "Referer=", ITEMDATA, "Name=caseManageId", "Value={caseManageId}", ENDITEM, LAST); //The returned value is in Chinese and needs to be transcoded. The transcoded value exists in msg lr_convert_string_encoding(lr_eval_string("{result}"),"utf-8",NULL,"outmsg"); //Print return value lr_output_message("After transcoding outmsg----%s",lr_eval_string("{outmsg}")); n=strlen(lr_eval_string("{outmsg}")); lr_output_message("%d",n); if (n==37) { lr_end_transaction("thing", LR_PASS); } else{ lr_end_transaction("thing", LR_FAIL); }