JMeter快速造数之数据导入导出

导入数据

  • 输入表格格式如下
  • 创建CSV Data Set Config
  • 在Body Data中调用

    {
    "username": "${email}",
    "password": "123456",
    "client_id": "00bb9dbfc67439a5d42e0e19f448c7de310df4c7fcde6feb5bd95c6fac5a5afc",
    "scope": "all",
    "react_app_request": true
    }

导出数据

  • 创建BeanShell PostProcessor
    • 一般数据来源是接口的response内容
java 复制代码
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;
import org.json.JSONObject;
import org.json.JSONArray;

String response=prev.getResponseDataAsString();//取出接口的返回消息
JSONObject jsonstring=new JSONObject(response);//放进json对象里

String token=jsonstring.getString("refresh_token");
String email=jsonstring.getJSONObject("profile").getString("email");
String type=jsonstring.getString("user_type");
String school=jsonstring.getJSONObject("profile").getJSONObject("school").getString("name");
token = "Bearer " + token


String outputFile = "E:/Software/JMeter/tokenInfo.csv";
// before we open the file check to see if it already exists
boolean alreadyExists = new File(outputFile).exists();
	
try {
	// use FileWriter constructor that specifies open for appending
	CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');
	
	// if the file didn't already exist then we need to write out the header line
	if (!alreadyExists)
	{
		csvOutput.write("Email");
		csvOutput.write("Token");
		csvOutput.write("Type");
		csvOutput.write("School");
		csvOutput.endRecord();
	}
	// else assume that the file already has the correct header line
	
	// write out a few records
	csvOutput.write(email);
	csvOutput.write(token);
	csvOutput.write(type);
	csvOutput.write(school);
	csvOutput.endRecord();
	
	csvOutput.close();
} catch (IOException e) {
	e.printStackTrace();
}

备注:可以创建一个Debug PostProcessor进行调试代码

相关推荐
1candobetter1 天前
JMeter + ServerAgent 压测监控实践
jmeter
查拉图斯特拉面条2 天前
JMeter 实战技巧:JSON 数组筛选指定对象并剔除首尾大括号
jmeter·json
查拉图斯特拉面条2 天前
JMeter 实战:JSON 响应中文节点 + 数值精准断言(附真实接口案例)
jmeter·json
qq_4924484464 天前
Jmeter Transaction Controller(事务控制器) 的 TPS(每秒事务数)严格固定为 1
java·开发语言·jmeter
Rookie_hh4 天前
使用Jmeter进行性能测试
jmeter
qq_452396237 天前
第十四篇:《JMeter插件扩展:自定义函数与第三方插件》
开发语言·python·jmeter
qq_452396237 天前
第十三篇:《分布式压测:JMeter Master-Slave集群》
分布式·jmeter
qq_452396238 天前
第十一篇:《性能压测基础:JMeter线程模型与压测策略设计》
java·开发语言·jmeter
沫沫-小白8 天前
JMeter 上传固定文件时,如何修改 Content-Disposition 的 filename
jmeter
qq_452396239 天前
第六篇:《JMeter逻辑控制器:循环、条件和交替执行》
android·java·jmeter