Json 如何在jmeter中将数组的每个值逐个解析为url
我有一个设想 用户日志 通过json路径提取器,我将所有预订ID作为一个数组获取Json 如何在jmeter中将数组的每个值逐个解析为url,json,jmeter,Json,Jmeter,我有一个设想 用户日志 通过json路径提取器,我将所有预订ID作为一个数组获取 ["75457052","75405285","75400251","75400246","75400252","75307496","75307497","75307498"] 现在用户需要像/reservation/id一样导航到数组中提到的所有id 如果在从上述url得到的响应中满足某些条件(例如destinationCount>1),那么它将返回该id并退出循环 我需要满足条件的第一个id我不确定JSON
["75457052","75405285","75400251","75400246","75400252","75307496","75307497","75307498"]
现在用户需要像/reservation/id一样导航到数组中提到的所有id
如果在从上述url得到的响应中满足某些条件(例如destinationCount>1),那么它将返回该id并退出循环
我需要满足条件的第一个id我不确定JSON路径提取器是否像regex那样将所有匹配的值公开为变量。您可以使用组合regex提取器和foreach控制器,如下所示
- 螺纹组
- 将返回保留id的HTTP采样器
- Regex后处理器匹配所有匹配的预订id
- Bean外壳处理器初始化destinationCount=0并初始化迭代器i=1
- foreach控制器
- ifcontroller(目标计数<1)
- 具有${reservation\u id}{u${i}的HTTP采样器
- Beanshell处理器将destinationCount设置为新值
- 将返回保留id的HTTP采样器
您可能希望查看屏幕强制转换,以确切了解regex提取器和foreach控制器是如何实现的。我的方法如下所示
Navigate to reservations to get all the reservation ids
Through regular expression extractor :-
Reference Name :- getreservationid
Regular expression:- "id": \"(.+?)\"
Match No :- -1
Template:- $1$
Then add foreach controller
input variable prefix :- getreservationid
output variable name :- reservationid
Then add http sampler to go to each reservationid :- /reservation/${reservationid}/home
Add json path extractor :- Name - numberOfLocations, JSON path :- $.payload.destinationGuide.numberOfLocations
Then add if controller ${numberOfLocations} > '1'
Then add the http sampler as example go to the weather page of that id :- /reservation /${reservationid}/weather
//I need to go only once to that weather page and then come out of for each controller
then add BSF post processor -> beanshell ( this is to remove all the variables so that it would come out from the foreach controller)
copy = new HashSet(vars.entrySet());
for (Iterator iter = copy.iterator(); iter.hasNext();) {
e = iter.next();
if ( e.getKey().startsWith("getreservationid") ) {
vars.remove(e.getKey());
}
}
我已经完成了Regex和Foreach,但我正在研究如何将输出数组的每个值从json路径提取器传递到Foreach控制器。