我有一个场景
用户登录
通过json路径提取器我将所有预留ID作为数组
["75457052","75405285","75400251","75400246","75400252","75307496","75307497","75307498"]
现在用户需要像/ reservation / id一样导航到数组中提到的所有ID
如果在响应中从上面的url获得某些条件符合(例如说destinationCount> 1)那么它将返回该id并退出循环。
我需要第一个符合标准的ID
答案 0 :(得分:1)
我不确定JSON路径提取器是否将所有匹配的值公开为变量,就像regex一样。您可以使用组合正则表达式提取器和foreach控制器,它们看起来如下所示。
您可能需要查看these屏幕强制转换,以确切了解正则表达式提取器和foreach控制器的实现方式。
答案 1 :(得分:0)
我的方式如下
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());
}
}