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

相关推荐
菩提树下的打坐11 小时前
性能测试进阶:从 JMeter 基线到 SLO 驱动的压测体系
学习·jmeter
zzz_23682 天前
ShopXO 商城系统测试报告:功能、后台管理、异常状态与 JMeter 性能验证
jmeter
小白上线*^_^*2 天前
Jmeter从入门到精通指南
软件测试·测试工具·jmeter·接口测试·测试工程师
zzz_23685 天前
码上面试平台测试报告:功能、后台管理、异常状态与 JMeter 性能验证
jmeter·面试·职场和发展
郑重其事,鹏程万里6 天前
JMeter组件说明
jmeter
川石课堂软件测试6 天前
安全测试|服务器安全加固方法
服务器·功能测试·测试工具·jmeter·mysql·web安全·单元测试
测试员周周9 天前
【skills5】一份 spec 生成 k6/JMeter/Locust:性能压测 + 全站截图,上线前的双保险
功能测试·网络协议·测试工具·jmeter·http·自动化·集成测试
余防9 天前
jmeter-接口测试
jmeter
小红帽子Alkaid10 天前
JMETER提取接口返回的token
数据库·redis·jmeter