jmeter-测试结果写回excel

jmeter测试结果写入excel表格中
添加BeanShell取样器,如下:
jmeter-测试结果写回excel_第1张图片
代码如下:

import java.text.SimpleDateFormat;
import java.util.Date;
import com.csvreader.CsvWriter;
import java.nio.charset.Charset;

Date tDate = new Date();
String testR = "不通过";
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
//System.out.println("**************"+sd.format(tDate)); 

testname = vars.get("testname");
path = vars.get("path");
testcase = vars.get("testcase");
testbody = vars.get("testbody");
fresult = vars.get("fresult");
error = vars.get("error");
//写入excel位置,路径:testpath,文件夹名称:testResult,excel名称:sd.format(tDate) + "_" + testname + ".csv"
testRF = vars.get("testpath") +"\\\\testResult\\\\" + sd.format(tDate) + "_" + testname + ".csv";

if (Integer.valueOf(prev.getResponseCode()) == 200 && !fresult.equals("[]"))
	testR = "通过";
	
FileWriter fstream = new FileWriter(testRF,true);
BufferedWriter out = new BufferedWriter(fstream);

//写入excel的内容包括:testname,path,testcase,error,testR
out.write(testname+","+ path + "," +testcase+"," +error+","+ testR);
//out.write(testname+","+ path + "," +testcase+"," + testR);
out.newLine();
out.close();
fstream.close();

这里说一下:执行之后,会生成excel表格,下次执行,表格要关闭状态,才能执行成功,不然会报错。

你可能感兴趣的:(jmeter-测试结果写回excel)