性能测试分享?LoadRunner篇
作者:网络转载 发布时间:[ 2014/1/3 10:29:11 ] 推荐标签:性能测试 LoadRunner
后附上我写的信用卡支付的脚本:
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import lrapi.lr;
import http.HttpClient4;
import http.HttpParameter;
import http.HttpResp;
import http.JsonUtil;
import http.Testcredit;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import java.util.Random;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.yeepay.g3.utils.common.encrypt.AES;
import com.yibao.utils.des3.RSA_Encrypt;
public class Actions
{
public String aes;
Date d = new Date();
Testcredit tc = new Testcredit();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
HttpParameter parameter = new HttpParameter();
public int init() throws Throwable {
String url = "http://xxxxx/xxxxx/consult";
HttpClient4 client =HttpClient4.createDefault();
String data = "";
Calendar now = Calendar.getInstance();
now.setTime(d);
String dateline=format.format(now.getTime());
System.out.println(dateline);
Date date = format.parse(dateline);
String dates=date.getTime()/1000+"";
System.out.println(dates);
try {
data = AES.encryptToBase64(dates, "<aes>");
} catch (Exception e) {
e.printStackTrace();
}
parameter.add("data", data);
parameter.add("merchantaccount", "<merchant>");
HttpResp resp = new HttpResp();
try{
resp=client.doPost(url, parameter, "utf-8");
String respStr= resp.getText("utf-8");
System.out.println(respStr);
aes=AES.decryptFromBase64(respStr, "<aes>");
System.out.println("aes="+aes);
} catch (Exception e) {
e.printStackTrace();
}
client.shutdown();
return 0;
}//end of init
public int action() throws Throwable {
StringBuilder sb = new StringBuilder("");
Random rd = new Random();
for(int i=1;i<=6;i++){
int sr=rd.nextInt(9);
sb.append(String.valueOf(sr));
}
String key=sb.toString();
int rds=rd.nextInt(999999);
lr.start_transaction("pay");
lr.rendezvous("pay");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://xxxxxxxx/xxxxxxx/api/bankcard/credit/pay");
System.out.println(aes);
String PUBLIC_KEY=aes;
System.out.println("PUBLIC_KEY"+PUBLIC_KEY);
String encryptkey = "0123456789"+key;
String merchantAccount = "<merchant>";
//民生
String cardNo = "6XXXXXXXXXXXXXX";
String validthru = "XXXX";
String cvv2 = "XXX";
String phone = "13466745431";
String orderId = rds+"334234223"+key;
System.out.println(orderId);
Integer transtime = (int)(System.currentTimeMillis()/1000);
Integer currency = 156;
String amount = "50";
String productcatalog = "1";
String productName = "123";
String productDesc = "小丸子";
String userIp = "123.45.45.45";
String identityId = "a";
Integer identityType = 6;
String other = "eeee";
String data = "{"merchantaccount":"" + merchantAccount
+"","cardno":"" + cardNo
+ "","validthru":"" + validthru
+ "","cvv2":"" + cvv2
+ "","phone":"" + phone
+ "","orderid":"" + orderId
+ "","transtime":" + transtime
+ ","currency":" + currency
+ ","amount":" + amount
+ ","productcatalog":"" + productcatalog
+ "","productname":"" + productName
+ "","productdesc":"" + productDesc
+ "","userip":"" + userIp
+ "","identityid":"" + identityId
+ "","identitytype":" + identityType
+ ","other":"" + other + ""}";
data = AES.encryptToBase64(data, encryptkey);
try {
method.setParameter("merchantaccount", merchantAccount);
method.setParameter("data", data);
method.setParameter("encryptkey", RSA_Encrypt.encrypt(encryptkey, PUBLIC_KEY));
client.executeMethod(method);
System.out.println(method.getStatusLine());
String respStr = method.getResponseBodyAsString();
System.out.println(respStr);
String result = AES.decryptFromBase64(respStr, encryptkey);
System.out.println(result);
method.releaseConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}
lr.end_transaction("pay", lr.AUTO);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11