此处将查询到的所有id值保存在变量jobID中,查询到的个数保存在变量jobID_matchNr中,格式如下:
jobID_1=19962
.......
jobID_28=18922
jobID_29=18912
jobID_matchNr=29
beanshell脚本中对json提取器中参数的引用格式为:${json提取器保存的变量名},例如${jobID_1}、${jobID_2}、${jobID_matchNr}。
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; //清空文件 FileWriter clrfstream=new FileWriter("D:/02workspace/Jmeter/RPA性能测试脚本20210609/单接口/jobId.csv",false); BufferedWriter clrout=new BufferedWriter(clrfstream); clrout.write(""); clrout.close(); clrfstream.close(); //追加方式写入数据 FileWriter fstream=new FileWriter("D:/02workspace/Jmeter/RPA性能测试脚本20210609/单接口/jobId.csv",true); BufferedWriter out=new BufferedWriter(fstream); for (int i=1;i<=${jobID_matchNr};i++){ jobID_i="jobID_"+i; //log.info(jobID_i); String jobId= vars.get(jobID_i); //log.info(jobId); out.write(jobId+" "); } out.close(); fstream.close();