Jmeter 通过json Extracted 来获取 指定的值的id

时间:2022-02-20 19:18:31

在没有 精确或模糊查询的接口时可以使用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){
 7 String [] 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)) {
12            log.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 int a=${__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);