在下面的脚本中,我试图在获得状态码200后中断for循环,但即使在收到状态码200后,请求仍会继续发生。
var getLibraries = host+'webcontents/libraries';
pm.sendRequest(getLibraries, function (err, response) {
var jsonData = response.json();
var library_id;
var statusCode;
var length = jsonData.contents.length;
for (var i = 0; i < length; i++ ){
library_id = jsonData.contents[i].id;
var getMLSConfigURL = host+'/library/'+library_id;
pm.sendRequest(getMLSConfigURL, function (err, response) {
statusCode = response.code;
if(statusCode == 200){
var mlsConfigData = response.json();
console.log('ID: ', mlsConfigData.id);
pm.environment.set("MLSConfigLib_Id", mlsConfigData.id);
return;
}
});
if(statusCode == 200){
break;
}
}
});
1条答案
按热度按时间92dk7w1h1#
如果你有你想要的条件,在FOR LOOP结束之前,把“i”变量设置为条件之后的长度(i = length),它将停止循环。