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

相关推荐
kebeiovo2 天前
常用的几种测试工具:selenium,jmeter,jenkins
selenium·测试工具·jmeter
AIZHINAN3 天前
如何使用 JMeter 进行接口测试。
jmeter·接口测试
程序员小远3 天前
基于jmeter+perfmon的稳定性测试记录
自动化测试·软件测试·python·测试工具·jmeter·职场和发展·测试用例
文人sec3 天前
性能测试-jmeter9-直连数据库
数据库·测试工具·jmeter
IDOlaoluo3 天前
apache-jmeter-5.1.1安装部署与使用教程(小白一看就会)
jmeter·apache
文人sec5 天前
性能测试-jmeter7-元件提取器
python·jmeter·prometheus·模块测试
坚定信念,勇往无前7 天前
Jmeter元件的加载顺序
jmeter
明月与玄武11 天前
Docker化性能监控平台搭建:JMeter+InfluxDB+Grafana全攻略
jmeter·docker·grafana
程序员杰哥11 天前
Jmeter+Jenkins接口压力测试持续集成
自动化测试·软件测试·python·测试工具·jmeter·jenkins·压力测试