Jmeter 通過json Extracted 來獲取 指定的值的id
阿新 • • 發佈:2019-01-09
object data xxxx iphone6 repl phone ant valueof replace
在沒有 精確或模糊查詢的接口時可以使用jmeter 獲取指定的值的ID
1 import java.lang.String ; 2 String getTargetName="iphone632g"; 3 //判讀相應結果中是否包含指定值:iphone632g 4 boolean containsCategory=prev.getResponseDataAsString().contains(getTargetName); 5 vars.putObject("containsCategory",containsCategory); 6 if(containsCategory){ 7String [] categoryNameSplit="${categoryName_ALL}".split(",") ; 8 String [] categoryIDSplit = "${categoryID_ALL}".split(","); 9 for (int i=0 ; i<categoryNameSplit.length ;i++ ) { 10 //假如找到指定的分類就將該分類的id put 到變量中去 ; 11 if (categoryNameSplit[i].equals(getTargetName)) { 12log.info("i=========="+String.valueOf(i)); 13 log.info("categoryIDSplit["+i+"]="+categoryIDSplit[i]); 14 vars.put("categoryId",categoryIDSplit[i]); 15 break ; 16 } 17 } 18 }
19
1 log.info("${__jexl2(${mobilePhone}*2+4,)}"); 2 inta=${__jexl2(3*2+4,)}; 3 Integer b=${__jexl2(3*2+4,)}+${__jexl2(3*2+4,)}; 4 Integer b1=${__jexl2(${pim_interfaceType}+${pim_interfaceType})}; 5 log.info("b1=="+b1); 6 //${__jexl2(,)}+${__jexl2(,)} 返回結果可以是String 類型 或者 Integer 類型; 7 String value ="${__jexl2(3*2+4,)}+${__jexl2(3*2+4,)}" ; 8 log.info("value="+value); 9 //String + Integer 10 String value1 ="${__jexl2(3*2+4,)}"+${__jexl2(3*2+4,)} ; 11 log.info("value1="+value1); 12 Integer createOrderAfterlockQty3=Integer.parseInt("1")+${__jexl2(${quantity})}; 13 log.info("xxxxxxxxxxxxxxx=="+createOrderAfterlockQty3); 14 String concatItemId="\""+"${itemId_all}".replace(",", "\",\"")+"\"" ; 15 log.info("concatItemId="+concatItemId);
Jmeter 通過json Extracted 來獲取 指定的值的id