需要从 json 中提取密钥并存储在 file.New 到 jmeter.Also 中,密钥是 dynamic.Used json jmes extrac 需要将结果存储到文件中
Need to extract keys from json and store in in a file.New to jmeter.Also the keys are dynamic.Used json jmes extrac need to store the result to a file
{
"csncnjcnsd-nvkmckmdks-930vbc":{}
"jvjdhjcsicn-bunwnc-nvn5477":{}
}
我能够在调试采样器的响应主体中看到带有 jmeter 属性的上述 ID,但我需要将其存储到 xlsx 文件中以获得进一步的 use.Any 帮助。
如果您需要将值存储到 .CSV 文件中 - 您可以使用 Sample Variables property and the Flexible File Writer
如果文件必须是“xlsx”——您将需要 Apache POI libraries in the JMeter Classpath and write the code in the suitable JSR223 Test Elements,这是一个示例:
def workbook = new org.apache.poi.hssf.usermodel.XSSFWorkbook();
def sheet = workbook.createSheet('Sheet1');
def row = sheet.createRow(0);
def cell = row.createCell(0);
cell.setCellValue(vars.get('your_variable_name_here'))
workbook.write(new File('your-filename-here.xlsx'))
您可以像这样使用 JSR223 后处理器:
def keys = "";
new groovy.json.JsonSlurper().parse(prev.getResponseData()).eachWithIndex{ def node, int idx ->
keys = keys + node.getKey() + "\r\n"
}
//Will save file to folder jmeter bin
def file1 = new File('response.txt')
file1.write(keys.toString())
结果:
{
"csncnjcnsd-nvkmckmdks-930vbc":{}
"jvjdhjcsicn-bunwnc-nvn5477":{}
}
我能够在调试采样器的响应主体中看到带有 jmeter 属性的上述 ID,但我需要将其存储到 xlsx 文件中以获得进一步的 use.Any 帮助。
如果您需要将值存储到 .CSV 文件中 - 您可以使用 Sample Variables property and the Flexible File Writer
如果文件必须是“xlsx”——您将需要 Apache POI libraries in the JMeter Classpath and write the code in the suitable JSR223 Test Elements,这是一个示例:
def workbook = new org.apache.poi.hssf.usermodel.XSSFWorkbook();
def sheet = workbook.createSheet('Sheet1');
def row = sheet.createRow(0);
def cell = row.createCell(0);
cell.setCellValue(vars.get('your_variable_name_here'))
workbook.write(new File('your-filename-here.xlsx'))
您可以像这样使用 JSR223 后处理器:
def keys = "";
new groovy.json.JsonSlurper().parse(prev.getResponseData()).eachWithIndex{ def node, int idx ->
keys = keys + node.getKey() + "\r\n"
}
//Will save file to folder jmeter bin
def file1 = new File('response.txt')
file1.write(keys.toString())
结果: