Jmeter-比较/声明多个数据:来自JSON的数据与来自数据库的数据 [英] Jmeter - Compare/assert multiple data: Data from JSON against data from DB

查看:144
本文介绍了Jmeter-比较/声明多个数据:来自JSON的数据与来自数据库的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就我的任务而言,我需要将JSON中的数据与DB中的数据进行比较,但是我几乎没有疑问如何构建场景.我的情况是这样的:

For the purpose of my task i need to compare Data from JSON against data from DB, but i have few doubts how to build the scenario. My scenario is like:

1执行数据库查询

哪个返回动态集,如:

url secret
https://test1.com/  1234
https://test2.com/  1234
https://test3.com/  1234

基于此动态集,我驱动我的Loop控制器进行循环.在这里,每次调用都会产生不同的JSON,例如:

[
{
    "adminLink": "",
    "BTCAmount": 0,
    "lastName": "test",
    "amount": 1,
    "clientId": "e1d4ab18517711eaa84cfa163eb75a2c",
    "foundingSourceName": "test",
    "secretId": "2938663415",
    "txId": "",
    "mcTxId": "1079249234",
    "paymentAddress": "",
    "result": "transaction timed out",
    "firstName": "test",
    "phoneNumber": "",
    "currency": "USD",
    "refoundAmount": 0,
    "approveTime": 1582543463,
    "email": "",
    "status": 1,
    "timestamp": 1581938595
},
{
    "adminLink": "",
    "BTCAmount": 0,
    "lastName": "test",
    "amount": 550,
    "clientId": "ffe22f34742311eab73f06ed6719cf46",
    "foundingSourceName": "test",
    "secretId": "3096308675",
    "txId": "",
    "mcTxId": "1101155492",
    "paymentAddress": "",
    "result": "transaction timed out",
    "firstName": "test",
    "phoneNumber": "",
    "currency": "USD",
    "refoundAmount": 0,
    "approveTime": 1586355699,
    "email": "",
    "status": 1,
    "timestamp": 1585750862
}   
]

2从这个动态json中,我可以提取:mcTxId with:

2 From this dynamic json, i can extract: mcTxId with:

3. 对于每个单个mcTxId,我需要使用以下命令执行JDBC查询:

3. For every single mcTxId , i need to perform JDBC query using:

select *
FROM affiliate_transaction
WHERE affiliate_id = 1  and mctxid = '${mcTxId_1}'

哪个结果将显示:

我设法解决了循环控制器,并提取了每个mcTxId,但我陷入了嵌套循环逻辑中,并断言了每个数据.

I managed to solve up to Loop Controller, and extract every single mcTxId, but i am stuck to nested looping logic, and assert each data.

我如何比较/声明每个clientId& approveTime在API调用(json)和数据库查询之间,它们的数据集始终是动态的?

How can i compare/assert every single clientId & approveTime between API call(json) and DB query, where their data set is always dynamic?

我们非常感谢您的帮助. 很长的道歉

Any help is highly appreciated. Apologies for the long post

推荐答案

  1. 将查询更改为select client_id FROM affiliate_transaction WHERE affiliate_id = 1 and mctxid = '${mcTxId_1}'并将其存储到 JMeter变量类似于client_id_from_db

  1. Change your query to select client_id FROM affiliate_transaction WHERE affiliate_id = 1 and mctxid = '${mcTxId_1}' and store it into a JMeter Variable like client_id_from_db

使用 JSON提取器从API获取客户端ID并将其存储在client_id_from_api

Use JSON Extractor to get the client ID from the API and store it into a JMeter Variable like client_id_from_api

完成后,您应该可以使用响应断言来比较2个JMeter变量

Once done you should be able to compare 2 JMeter Variables using Response Assertion

这篇关于Jmeter-比较/声明多个数据:来自JSON的数据与来自数据库的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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