简体   繁体   English

如何比较负载运行器中 API 的 json 响应?

[英]How to Compare the json response of API in load runner?

I need to reproduce the Race conditions scenario where same API is giving multiple response.我需要重现相同 API 给出多重响应的竞争条件场景。 Here we need to compare the API response and end it as fail transaction if the response are not matching or different from the original response.这里我们需要比较 API 响应,如果响应与原始响应不匹配或不同,则将其作为失败事务结束。

Need help on how to script this on load runner tool.需要有关如何在负载运行工具上编写脚本的帮助。 I am able to capture the response and save it as a parameter.我能够捕获响应并将其保存为参数。 But how do I compare it with the original response?但是我如何将它与原始响应进行比较?

Also the response is in JSON format and hence I was not able to use the STRCMP function.响应也是 JSON 格式,因此我无法使用 STRCMP function。

You have an expected response as a string.您有一个字符串形式的预期响应。 You have a captured response as a string.您将捕获的响应作为字符串。 You compare two strings.你比较两个字符串。 Just make sure you have all of the same formatting characters in your expected result as you have in your captured response只需确保预期结果中的格式字符与捕获的响应中的格式字符相同

Found the solution.找到了解决方案。

if (strcmp(lr_eval_string("{pComparisonString}"),lr_eval_string("{response}")) == 0) if (strcmp(lr_eval_string("{pComparisonString}"),lr_eval_string("{response}")) == 0)

{ {

lr_end_transaction("transaction", LR_PASS); lr_end_transaction("交易", LR_PASS);

} else } 别的
{ {

lr_output_message("The parameter value is %s", lr_eval_string("{pComparisonString}")); lr_output_message("参数值为%s", lr_eval_string("{pComparisonString}")); lr_end_transaction("transaction", LR_FAIL); lr_end_transaction("交易", LR_FAIL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM