Jmeter-过程脚本
1、根据正则表达式获取的结果保存
FileWriter fstream = new FileWriter("./message.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(vars.get("message")+"\n");
out.close();
fstream.close();
2、所有响应数据的保存
String response="";
String Str="message";
response=prev.getResponseDataAsString(); //获取响应数据
FileWriter fstream = new FileWriter("./message.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(response+"\n");
out.close();
fstream.close();
3、根据正则表达式提取的结果保存响应数据:messagess通过正则表达式提取结果
String Str;
Str=vars.get("messagess");
if (Str!="success"){
String response="";
response=prev.getResponseDataAsString(); //获取响应数据
FileWriter fstream = new FileWriter("./message.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("submitTaskItemQuestion "+response+"\n");
out.close();
fstream.close();
}
4、jmeter获取时间戳
System.currentTimeMillis()
jmeter 读取目录文件并且保存
//读取文件夹中所有文件名称
import java.io.File;
String path = "E:\\work\\JKPT\\svn\\jmeter\\StudentWOV1";// 读取文件夹路径
File f = new File(path);
FileWriter fstream = new FileWriter("E:\\work\\JKPT\\svn\\jmeter\\jkpt_test_bigdata\\file_name.csv",true); //读取文件名存储路径和
BufferedWriter out = new BufferedWriter(fstream);
if (!f.exists()) {
System.out.println(path + " not exists");
return;
}
File[] fa = f.listFiles();
for (int i = 0; i < fa.length; i++) {
File fs = fa[i];
if (fs.isDirectory()) {
System.out.println(fs.getName() + " [目录]");
out.write(fs.getName() + " [目录]"+"\n");
} else {
System.out.println(fs.getName());
out.write(fs.getName()+"\n");
}
}
out.close();
fstream.close();
5、jmeter 生成手机号
String account = "${__time(yyyyMMdd,)}"+UUID.randomUUID().toString().split("-")[0];
long timeStamp = System.nanoTime();
String phone=String.valueOf(timeStamp)+"${__threadNum}";
//String phone ="${__time(yyyyMMddhhmmssSS,)}${__threadNum}";
String after8bit =phone.substring(phone.length()-10);
String phoneNum="1"+"${__RandomFromMultipleVars(var130|var131|var132|var155|var156|var185|var186|var145|var176|var134|var135|var136|var137|var138|var139|var147|var150|var151|var152|var157|var158|var159|var178|var182|var183|var184|var187|var188|var133|var153|var177|var180|var181|var189)}"+after8bit ;
vars.put("phoneNum",phoneNum);
vars.put("account",account);