loadrunner模擬文件上傳代碼示例

Action(){
    long file_stream;
    char * PRPFILE =  "F:\\ELIFE保單號.txt";
	  char * num;
    char * PRPNum;
	  char * IP;

	  num = lr_eval_string("{num}");
	  IP = lr_get_vuser_ip();

	lr_start_transaction("elife-環球遊-團單-團單導入上傳");

	web_submit_data("commonUpload.do",
		"Action=http://11.207.60.3:8001/elife/policy/commonUploadAction/commonUpload.do",
		"Method=POST",
		"EncType=multipart/form-data",
		"RecContentType=text/html",
		"Referer=http://11.207.60.3:8001/elife/uploade.jsp",
		"Snapshot=t16.inf",
		"Mode=HTML",
		ITEMDATA,
//		"Name=sessionid", "Value=JS32100001EAJ1363727{CorrelationParameter_3}13031916{CorrelationParameter_4}", ENDITEM,
		"Name=sessionid", "Value=JS32100001EAJ{CorrelationParameter_4}", ENDITEM,
		"Name=uploadFile", "Value=E:\\elifetdimport.xls", "File=yes", ENDITEM,
		LAST);

	lr_output_message("session id: %s",lr_eval_string("{CorrelationParameter_4}"));
	lr_end_transaction("elife-環球遊-團單-團單導入上傳", LR_AUTO);

	lr_start_transaction("獲取保單號");

	web_submit_data("qingfenAction.do",
		"Action=http://11.207.60.3:8001/elife/elife/QingfenAction/qingfenAction.do",
		"Method=POST",
		"Referer=http://11.207.60.3:8001/elife/policy/eAJPolicyAction/addEAJpolicy.do",
		"Mode=HTML",
		ITEMDATA,
		"Name=proposalnos", "Value={CorrelationParameter_2}", ENDITEM,
		"Name=next", "Value=0.0075899769244481274", ENDITEM,
		LAST);

	if(strcmp(lr_eval_string("{CorrelationParameter_2}")," ")!=0){
		lr_end_transaction("獲取保單號", LR_PASS);
		PRPNum = lr_eval_string("{CorrelationParameter_2}");
		lr_log_message(" ---------------保單號:%s----------------",PRPNum);
			  if ((file_stream = fopen(PRPFILE, "a+")) == NULL ) {
		  lr_error_message("Cannot open %s", PRPFILE);
		  return -1;
		 }

		 fprintf(file_stream, "保單號:%s      發生在第%s次運行時    本機IP:%s\n", PRPNum,num,IP);
		 fclose(file_stream);
		 lr_log_message(" ---------------導出保單號:%s 成功,位置:%s----------------",PRPNum,PRPFILE);
	}else{
		lr_log_message("--------------獲取保單號失敗!-----------");
		lr_end_transaction("獲取保單號", LR_FAIL);
	}
return 0;
}
相關文章
相關標籤/搜索