当前位置: 代码迷 >> 综合 >> jmeter BeanShell 把数据追加写入文件,CSV Data Set Config做参数化
  详细解决方案

jmeter BeanShell 把数据追加写入文件,CSV Data Set Config做参数化

热度:92   发布时间:2023-12-17 03:17:49.0

问题:页面的两个数据不等的时候可能订单号对应的数据有问题,要把这种单找出来
在这里插入图片描述

找前端美女核实 车主收入, 车主实际收入对应的字段
接口返回数据手动做了简化后的样子在这里插入图片描述

BeanShell PostProcessor

import org.json.*;
String jsonResult = prev.getResponseDataAsString();
JSONObject jsonObject = new JSONObject(jsonResult);
String jsonObjectstring = jsonObject.get("data").toString();
vars.put("string_jsonArray",jsonObjectstring);
log.info(jsonObjectstring);

BeanShell

import org.json.*;var b = vars.get("string_jsonArray");
JSONObject jsondata = new JSONObject(b);
int driverFactIncome = (int) jsondata.get("driverFactIncome");// 车主实际收入:driverFactIncome
String orderSerial = (String) jsondata.get("orderSerial");
JSONObject jsondataaflcOrderExpenses = new JSONObject(jsondata.get("aflcOrderExpenses").toString());
int driverIncome = (int) jsondataaflcOrderExpenses.get("driverIncome");// 车主收入:aflcOrderExpenses.driverIncome
if (driverFactIncome == driverIncome) {
    Failure = false;log.error("执行成功");
} else {
    Failure = true;FileWriter fw = null;try {
    //如果文件存在,则追加内容;如果文件不存在,则创建文件File f=new File("F:/test.txt");fw = new FileWriter(f, true);} catch (IOException e) {
    e.printStackTrace();}PrintWriter pw = new PrintWriter(fw);pw.println(orderSerial);pw.flush();try {
    fw.flush();pw.close();fw.close();} catch (IOException e) {
    e.printStackTrace();}FailureMessage = "执行失败" +orderSerial;log.error("执行失败");}

CSV Data Set Config
在这里插入图片描述
有多少条订单设置多少线程
跑完后test.txt有数据了

  相关解决方案