性能壓測之 Loadrunner 接口代碼設計

筆者在進行 Loadrunner 壓測時,編寫 http接口測試代碼時,對於post 請求 經常使用到2個函數:web

• web_submit_data() json

• web_custom_request()api

現將性能代碼分享以下:app

1、 關於 web_submit_data() 函數ide

web_reg_find("Text=\"success\":true", 函數

"SaveCount=spz_Count", 

        LAST );

lr_start_transaction("spz");

web_submit_data("spz.htm", 

"Action={url}/api/flow/FlowListFrom?ticket={ticket}", 

"Method=POST", 

"Mode=HTML", 

ITEMDATA, 

"Name=pageSize", "Value=10", ENDITEM, 

"Name=pageNumber", "Value=1",ENDITEM,  

LAST );

if (atoi(lr_eval_string("{spz_Count}")) > 0){ post

lr_output_message("spz successful."); 

     lr_end_transaction("spz", LR_PASS);

     } 

  else{ 

     lr_end_transaction("spz", LR_FAIL);

  } 

2、關於 web_custom_request() 函數

 web_add_header("User-Agent","Mozilla/6.0 (Macintosh; Intel Mac OS X 12_19_9) AppleWebKit/63.86 (KHTML, like Gecko) Chrome/62.100 Safari/637.3");

  web_reg_find("Text=\"success\":true", 

        "SaveCount=code_Count", 

        LAST );

lr_start_transaction("code");

  web_custom_request("code",
  "Method=POST",
  "URL={url}/api/getItemByCode?ticket={ticket}",
  "RecContentType=application/json", 
  "EncType=application/json", 
  "Mode=HTML",
  "body={\"scope\": \"native\",\"itemCode\":\"TxtSet0\"}",
  LAST);

  if (atoi(lr_eval_string("{code_Count}")) > 0){ 

     lr_output_message("code successful."); 

     lr_end_transaction("code", LR_PASS);

     } 

  else{ 

     lr_end_transaction("code", LR_FAIL);

  }
相關文章
相關標籤/搜索