1. 涉及脚本机构:
1. 测试计划--Add--配置元件:添加用户自定义变量: 设置请求url
2. 线程组下-add 用户beanshell 脚本,配置随机参数
import org.apache.jmeter.config.Arguments;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.text.*;
String firstname ="张王李赵......";
String secondname = "一二三四..............";
String halfNumber = "1234567890";
vars.put("firstname",firstname);
vars.put("second",secondname);
vars.put("halfNumber",halfNumber);
long id = ${__Random(100000000,999999999,id)};
String transNo = "TRNO" + id.toString();
vars.put("transNo",transNo);
long id = ${__Random(100000000,999999999,id)};
String channelOrgID = "C-I_D" + id.toString();
vars.put("channelOrgID",channelOrgID);
String channelOrgID = "C-I_D" + id.toString();
vars.put("channelOrgID",channelOrgID);
//创建随机时间-- 时间格式:yyyyMMddHHmmss
try{
Date date = new Date(); //获取当前时间
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String insuredDate = sf.format(date);
Calendar cal = Calendar.getInstance(); //当前时间
cal.setTime(sf.parse(insuredDate));
cal.add(Calendar.DAY_OF_MONTH,-30);
String insuredDate = sf.format(cal.getTime());
vars.put("insuredDate",insuredDate);
}
catch(Exception e){
}
3. 线程组下-设置信息头,管理接口请求的头部信息
4. 后置beanshell: 编写读取接口返回的参数写入到txt 中,用来执行接口关联
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
String strPath = "C:/test/1.txt";
File file = new File(strPath);
File fileParent = file.getParentFile();
try{
if(!fileParent.exists()){
fileParent.mkdirs();
}
file.createNewFile();
FileWriter fw = new FileWriter(file, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(vars.get("lastName") + "," + vars.get("firstName"));
pw.flush();
fw.flush();
fw.close();
}
catch(Exception e){
}
未完。。。。。。。。。。。。。。。。。。
标签:实战,java,String,vars,接口,put,import,jmeter,id From: https://www.cnblogs.com/blowwind/p/17524273.html