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进行调试代码

相关推荐
岁月失语唯石能言4 小时前
《 Web项目测试实战:博客系统的功能/接口/自动化/性能全流程测试报告》
自动化测试·功能测试·selenium·jmeter·接口测试·压力测试·性能测试
中国软件测试质量协会1 天前
国产性能测试工具:kylinPET高仿真与高并发性能测试技术深度解析——与JMeter、LoadRunner全面对比
测试工具·jmeter
拜托多多指教2 天前
【JMeter】外观设置(Mac)
jmeter
川石课堂软件测试9 天前
自动化测试常见的异常处理
python·jmeter·mysql·docker·容器·单元测试·grafana
wuhuhuan10 天前
JMeter 性能测试教程
jmeter
行者-全栈开发10 天前
JMeter + InfluxDB + Grafana:搭建生产级压测实时监控与告警体系
jmeter·grafana·时序数据库·influxdb·实时监控·backendlistener·告警性能测试
wuhuhuan11 天前
【JMeter 学习打卡 Day 7】从会用到会用对,完成一次完整压测
学习·jmeter
行者-全栈开发13 天前
JMeter 自定义 Sampler 开发:从零写 TCP 私有协议压测插件
jmeter·tcp协议·源码解析·插件开发·gradle构建·自定义sampler·abstractsampler
wuhuhuan13 天前
【JMeter 学习打卡 Day 5】控制流程和节奏的利器
学习·jmeter