简体   繁体   English

如何从JSON响应中提取ID并将其用作JMeter中另一个HTTP请求中的路径变量

[英]How to extract an ID from JSON response and use it as path variable in another HTTP requests in JMeter

I have a requirement where I will run a search API which will return me a list of object, each with unique 'facilityID'. 我有一个要求,我将在其中运行搜索API,该API将向我返回一个对象列表,每个对象均具有唯一的“ facilityID”。 I need to create a list of them and use them in another HTTP Delete Request. 我需要创建它们的列表,并在另一个HTTP Delete Request中使用它们。 I have to pass the values as path variable and there are multiple simultaneous threads. 我必须将值作为路径变量传递,并且有多个同时线程。

Example: Search API return following IDs: [18c2, 77v3, 45f1] 示例:搜索API返回以下ID:[18c2、77v3、45f1]

Now in my Delete HTTP Request, different threads should fetch an Id from the list and bind it to the path variable of the URL. 现在,在我的“删除HTTP请求”中,不同的线程应该从列表中获取一个ID并将其绑定到URL的路径变量。

I read about JSON extractor and am using following expression in Search API, 我阅读了有关JSON提取器的信息,并在Search API中使用了以下表达式,

$.result[*].facilityId

This should return me the list, but how do I make sure that each thread should pick one value from it and hit the API? 这应该返回给我列表,但是如何确保每个线程都应该从中选择一个值并访问API?

I assume you came up with the correct JSON Extractor configuration and got the following JMeter Variables, ie you can observe the next values for the Debug Sampler in the View Results Tree listener 我假设您提出了正确的JSON提取器配置,并获得了以下JMeter变量,即您可以在“ 视图结果树”侦听中观察“ 调试采样器”的下一个值

facilityId_1=18c2
facilityId_2=77v3
facilityId_3=45f1
facilityId_matchNr=3

在此处输入图片说明

If your goal is to run Delete requests concurrently for each thread - you can consider using __V() and __threadNum() functions combination - this way each JMeter thread will delete its own facilityId 如果您的目标是同时为每个线程运行Delete请求-您可以考虑使用__V()__threadNum()函数组合-这样,每个JMeter线程都会删除自己的facilityId ID

在此处输入图片说明

Check out Here's What to Do to Combine Multiple JMeter Variables for more information if needed. 如果需要,请查看“合并多个JMeter变量的操作”以了解更多信息。

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

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