问题:有时候,我们需要把本地获取到的数字或字符串,在jmeter中拼接成email格式如:xxxxxx.@qq.com,来做为帐号进行操作
这是应该怎么办?
一, 创建一个请求,假设这个请求的传参要用到email格式
二,添加一个前置处理器,写beanshell
三,脚本如下:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
/*************定义变量***********************/
File file = new File("C://web//email.txt");
BufferedReader reader = null;
String tempString = null;
String str;
int num;
String str3="";
String str2="";
/*************读取本地文件***********************/
try {
reader = new BufferedReader(new FileReader(file));
tempString = reader.readLine();//tempString读文件
reader.close();
str=tempString.trim();//str取字符串
log.info(">>>>>>>>>>>" + str);
num=Integer.parseInt(str);//num转换str2为int型
//num=num+1;
str3= String.valueOf(num)+"@qq.com";//str3转换int型为string,拼接成email
log.info(">>>>email的值为>>>>>>>" + str3);
}catch (IOException e) {
e.printStackTrace();
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e1) {
}
}
}
//String str4=str3+"@qq.com";
//System.out.println("str4="+str4);
//try{
File file = new File("/users/mkyong/filename.txt");
if file doesnt exists, then create it
//if (!file.exists()) {
//file.createNewFile();
//}
//FileWriter fw = new FileWriter(file.getAbsoluteFile());
//BufferedWriter bw = new BufferedWriter(fw);
//bw.write(str3+"\n");
//bw.close();
//}catch(IOException e){
//e.printStackTrace();
//}
vars.put("emailtxt",str3);