如何在jmeter中获取jdbc请求的数组响应? [英] how to get an array response of jdbc request in jmeter?

查看:571
本文介绍了如何在jmeter中获取jdbc请求的数组响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例我有我的JDBC请求,响应如下:

Example I have my JDBC Request and the response is like:

X     Y     Z
a1    b1    c1
a2    b2    c2
a3    b3    c3
a4    b4    c4
a5    b5    c5
.     .     .
.     .     .
.     .     .

如何获取x,y和z的所有值?

How can I get all the value of x, y and z?

然后我有HTTP请求,并且我将断言所有响应是否都与从JDBC选择的数据匹配.

then I have HTTP request and I'm going to assert if all the response is matched to the data selected from JDBC.

示例响应:

{
    {
        "x":"a1",
        "y":"b1",
        "z": "c1"
    },
    {
        "x":"a2",
        "y":"b2",
        "z": "c2"
    },
    {
        "x":"a3",
        "y":"b3",
        "z": "c4"
    },
    {
        "x":"a4",
        "y":"b4",
        "z": "c4"
    },
    {
        "x":"a5",
        "y":"b5",
        "z": "c5"
    },
    {
        "x":"a6",
        "y":"b6",
        "z": "c6"
    },
    {
        "x":"a7",
        "y":"b7",
        "z": "c7"
    },
    {
        "x":"a8",
        "y":"b8",
        "z": "c8"
    },
    .
    .
    .                     
    .
}

推荐答案

您应声明变量名称"字段,并声明结果变量名称,如下所示.

You should declare the "Variable Names" field and also declare a result variable name as shown below.

然后,您可以使用_1 _2方法访问它们.请在下面找到可在beanshell后处理器中使用的示例代码.

Then you can access them using the _1 _2 method. Please find below the sample code that you can use in the beanshell post processor.

import java.util.ArrayList;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;

ArrayList items = vars.getObject("result1");


for ( int i = items.size() - 1; i >= 0; i--) {
    JSONObject jsonitemElement = new JSONObject();
    jsonitemElement.put("x", vars.get("x_" + (i + 1)));
    jsonitemElement.put("y", vars.get("y_" + (i + 1)));
    jsonitemElement.put("z", vars.get("z_" + (i + 1)));
    log.info(jsonitemElement.toString());
}

由于要从HTTP请求的响应负载中获取这些值作为响应,因此应添加代码以在断言或后处理器中解析该JSON响应,并将其与上述示例代码中的元素进行比较.

Since you are getting these values as the response from the response payload of the HTTP request, you should add the code to parse that JSON response in an assertion or post processor and compare it with the elements from the above sample code.

要注意的一点-不同的应用程序以任何顺序发送目标JSON.因此,不能保证HTTP响应始终将响应发送为A1,B1,C1-A2,B2,C2等.它可以以A5,B5,C5等开头的任何顺序发送它们.使用哈希图或编写数组比较,以确保结果集与HTTp响应完全匹配.

A point to note - Different applications send the target JSON in any order. So, there is no guarantee that the HTTP response will always send the response as A1,B1,C1 - A2,B2,C2 etc. It can send them in any order starting with A5,B5,C5 etc. It is better to then use a hashmap or write your array comparison to ensure that your result set completely matches the HTTp response.

这篇关于如何在jmeter中获取jdbc请求的数组响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆