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 小时前
JMeter性能测试工具·下
开发语言·测试工具·jmeter
程序员三藏11 小时前
Jmeter自动化测试
自动化测试·软件测试·python·测试工具·jmeter·测试用例·接口测试
小小测试开发11 小时前
JSR223后置处理程序用法详解:JMeter复杂响应处理的终极方案
jmeter
小小测试开发1 天前
JMeter XPath提取器用法详解:XML/HTML响应数据提取神器
xml·jmeter·html
weixin_440730503 天前
jmeter请求头和参数总结
jmeter
2501_924064116 天前
2025数据库性能测试工具:Utest、JMeter、HammerDB 等主流方案推荐
数据库·测试工具·jmeter·数据库性能测试·数据库负载测试·数据库压测工具·jmeter 压力测试
小小测试开发6 天前
JMeter JSR223预处理程序全攻略:用Groovy解锁复杂场景自动化
运维·jmeter·自动化
卖个几把萌6 天前
【08】JMeter从文本中读取多个参数
测试工具·jmeter
海梨花6 天前
又是秒杀又是高并发,你的接口真的扛得住吗?
java·后端·jmeter
小小测试开发6 天前
JMeter HTTP URL重写修饰符用法详解:解决会话传递与URL参数动态处理
网络协议·jmeter·http