JMeter后置处理器BeanShellPostProcessor

举例:

import org.json.JSONArray;
import org.json.JSONObject;

FileWriter fstream = new FileWriter("D:\\filename.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
String response = prev.getResponseDataAsString();
log.info(response);
JSONObject data_obj = new JSONObject(response);
String list = data_obj.get("data").toString();
JSONArray jsonArray=new JSONArray(list);
log.info((jsonArray.length()).toString());
out.write("id,name,state\n");
for (int i=0; i<jsonArray.length(); i++){
	String str1 = (jsonArray.get(i)).toString();
	JSONObject object2 = new JSONObject(str1);
	out.write(object2.get("id").toString()+","+object2.get("name").toString()+","+object2.get("state").toString()+"\n");
	}
out.close();
fstream.close();

若需引用第三方jar包:

  1. 下载对应jar包
  2. 将jar包放置在lib/ext下(也可以直接放于lib下,但是测试计划中要引入该jar包;也可以放在任意位置,在配置文件中设置)
  3. 重启JMeter运行

你可能感兴趣的:(测试,java)