1.jmeter 新建线程组、Java Request、BeanShell Assertion、View Results Tree
2、在BeanShell Assertion中贴入代码:
import org.apache.jmeter.extractor.json.jsonpath.JSONManager;
import java.util.List;
JSONManager js= new JSONManager();
String jsonString="{\"timeStamp\":1695348189596,\"code\":200,\"dataVersion\":\"20230922100309\",\"x-amz-meta-dv\":1695348189000,\"dataFreshVersion\":\"20230922100309\",\"message\":\"success\",\"body\":{\"ABTEST_MODULE\":{\"engines\":\"http://10.0.0.01/hwtestdatavo/jsYpdz/1/1.txt\",\"ruleList\":null,\"engineJs\":[{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/4c60/f0/audio-video-server_runtime.ff752e23.bundle.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"ABTEST_MODULE\",\"fileMd5\":\"a688e9a35a295c3cf57c7bf772f05eb2\",\"version\":\"20230906203310\",\"url\":\"http://10.0.0.01/hwtestdatavo/4c60/f0/audio-video-server_runtime.ff752e23.bundle.js\",\"iosStartPrdVersion\":222,\"name\":\"测试刷新缓存999\",\"adStartPrdVersion\":111,\"id\":\"JS38DDD67ADB704B569C56B5D8EE14D2\",\"judge\":\"client\",\"adEndPrdVersion\":-1},{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/65b0/53/audio-video-server_encodeabmodulejs.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"ABTEST_MODULE\",\"fileMd5\":\"c503027770575b3ffd991f4544bf341f\",\"version\":\"20230904172153\",\"url\":\"http://10.0.0.01/hwtestdatavo/65b0/53/audio-video-server_encodeabmodulejs.js\",\"iosStartPrdVersion\":111,\"name\":\"测试刷新缓存01\",\"adStartPrdVersion\":111,\"id\":\"JS50CB87BEA16B4E7EB038FA36A5291C\",\"judge\":\"client\",\"adEndPrdVersion\":-1},{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/65b0/53/audio-video-server_encodeabmodulejs.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"ABTEST_MODULE\",\"fileMd5\":\"c503027770575b3ffd991f4544bf341f\",\"version\":\"20230904153857\",\"url\":\"http://10.0.0.01/hwtestdatavo/65b0/53/audio-video-server_encodeabmodulejs.js\",\"iosStartPrdVersion\":111111111,\"name\":\"测试刷新缓存\",\"adStartPrdVersion\":111111111,\"id\":\"JS2D0F26FE3C3140559FEFDB041B86EA\",\"judge\":\"client\",\"adEndPrdVersion\":-1},{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/9efa/c5/audio-video-server_ab.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"ABTEST_MODULE\",\"fileMd5\":\"0847d76a60c408dc31f951b3f87e21ac\",\"version\":\"20230818174046\",\"url\":\"http://10.0.0.01/hwtestdatavo/9efa/c5/audio-video-server_ab.js\",\"iosStartPrdVersion\":1,\"name\":\"ABTest\",\"adStartPrdVersion\":1,\"id\":\"JSF9F0354754A449C4A31FFDD4C151C4\",\"judge\":\"client\",\"adEndPrdVersion\":-1}],\"version\":1695312015928},\"USER_GROUP_MODULE\":{\"engines\":null,\"ruleList\":[{\"checkType\":\"1\",\"id\":\"UGR59C1220BAF5048D78A425D0303C56\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR59C1220BAF5048D78A425D0303C56.json\"},{\"checkType\":\"1\",\"id\":\"UGR48F857A042EB405A9F7A2F435002F\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR48F857A042EB405A9F7A2F435002F.json\"},{\"checkType\":\"1\",\"id\":\"UGR10C894E6E9BA4F8785E12C2FE6C8D\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR10C894E6E9BA4F8785E12C2FE6C8D.json\"},{\"checkType\":\"1\",\"id\":\"UGR8E6926CCC71B4964BFF1F9B9F1705\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR8E6926CCC71B4964BFF1F9B9F1705.json\"},{\"checkType\":\"1\",\"id\":\"UGR9C0294C456034C1F8354D87DD0FB0\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR9C0294C456034C1F8354D87DD0FB0.json\"},{\"checkType\":\"0\",\"id\":\"UGR1C3F9868799744169D135E83313CB\",\"version\":1695193636248,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR1C3F9868799744169D135E83313CB.json\"},{\"checkType\":\"1\",\"id\":\"UGRAD5CC90F0D464120B4A51DC95E31F\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRAD5CC90F0D464120B4A51DC95E31F.json\"},{\"checkType\":\"1\",\"id\":\"UGR7F1A3C8D15A64E8197ABC6B658A87\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR7F1A3C8D15A64E8197ABC6B658A87.json\"},{\"checkType\":\"1\",\"id\":\"UGR60D61EA053964D94A43CDD4DEE3C1\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR60D61EA053964D94A43CDD4DEE3C1.json\"},{\"checkType\":\"1\",\"id\":\"UGR5863260E610548AFB7BE54D8B411F\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR5863260E610548AFB7BE54D8B411F.json\"},{\"checkType\":\"1\",\"id\":\"UGRB1B46106293046D0BBB21E575A4F0\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRB1B46106293046D0BBB21E575A4F0.json\"},{\"checkType\":\"1\",\"id\":\"UGR27BC722E3E1B4F619EE5DEAD4DD39\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR27BC722E3E1B4F619EE5DEAD4DD39.json\"},{\"checkType\":\"1\",\"id\":\"UGRA3F9C6F6E5D34788BD206B4B47F8B\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRA3F9C6F6E5D34788BD206B4B47F8B.json\"},{\"checkType\":\"1\",\"id\":\"UGRFE855FE7B312434DB1C3973B31A37\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRFE855FE7B312434DB1C3973B31A37.json\"},{\"checkType\":\"1\",\"id\":\"UGRE97F2A3F230946D9A199B1A14EB21\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRE97F2A3F230946D9A199B1A14EB21.json\"},{\"checkType\":\"1\",\"id\":\"UGR935BA8FA7FDC4F05A15A6E059FA55\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR935BA8FA7FDC4F05A15A6E059FA55.json\"},{\"checkType\":\"1\",\"id\":\"UGRCA3792D28455445FAA254A764730B\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRCA3792D28455445FAA254A764730B.json\"},{\"checkType\":\"1\",\"id\":\"UGRF8F899412ECD453388E254AD4D8B2\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRF8F899412ECD453388E254AD4D8B2.json\"},{\"checkType\":\"1\",\"id\":\"UGR9D7F895168B74755A3F33FAA26549\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR9D7F895168B74755A3F33FAA26549.json\"},{\"checkType\":\"1\",\"id\":\"UGR227417BC68C849019255516BD7D7B\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR227417BC68C849019255516BD7D7B.json\"},{\"checkType\":\"1\",\"id\":\"UGR419D05499D7C4AD38EBB12398E23B\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR419D05499D7C4AD38EBB12398E23B.json\"},{\"checkType\":\"1\",\"id\":\"UGRC187E68D8D2542A5B4788950C0436\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRC187E68D8D2542A5B4788950C0436.json\"},{\"checkType\":\"1\",\"id\":\"UGRFEE4F194116243ED84F2DB975AE9A\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGRFEE4F194116243ED84F2DB975AE9A.json\"},{\"checkType\":\"1\",\"id\":\"UGR873C7E58ED434D32AD708A334CF71\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR873C7E58ED434D32AD708A334CF71.json\"},{\"checkType\":\"1\",\"id\":\"UGR075AD0268424470EBF57087EC8A68\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR075AD0268424470EBF57087EC8A68.json\"},{\"checkType\":\"1\",\"id\":\"UGR4EA524BCC9E847B9BB44A99DDE2A8\",\"version\":1695190946516,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR4EA524BCC9E847B9BB44A99DDE2A8.json\"},{\"checkType\":\"1\",\"id\":\"UGR35DDC08491834BF1A87BB0129EDD6\",\"version\":1695190621268,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR35DDC08491834BF1A87BB0129EDD6.json\"},{\"checkType\":\"1\",\"id\":\"UGR742358A36C114A4A8794AF5C15BB5\",\"version\":1,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR742358A36C114A4A8794AF5C15BB5.json\"},{\"checkType\":\"0\",\"id\":\"UGR3A9403FBC3F74747B5322A12950A1\",\"version\":1695193152283,\"url\":\"http://10.0.0.01/hwtestdatavo/audio-video-server/UGR3A9403FBC3F74747B5322A12950A1.json\"}],\"engineJs\":[{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/f5db/49/audio-video-server_data_appsource_appplugins_js_20220815175547_encodejs.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"USER_GROUP_MODULE\",\"fileMd5\":\"c991b3e4653582384a08c84ccbbb8c0b\",\"version\":\"20230809100059\",\"url\":\"http://10.0.0.01/hwtestdatavo/f5db/49/audio-video-server_data_appsource_appplugins_js_20220815175547_encodejs.js\",\"iosStartPrdVersion\":111,\"name\":\"111\",\"adStartPrdVersion\":111,\"id\":\"JSE5AAECD6E448474D8103C68DF03493\",\"judge\":\"client\",\"adEndPrdVersion\":-1},{\"bakUrl\":\"http://10.0.0.01/hwtestdatavo/f5db/49/audio-video-server_data_appsource_appplugins_js_20220815175547_encodejs.js\",\"checkType\":null,\"iosEndPrdVersion\":-1,\"module\":\"USER_GROUP_MODULE\",\"fileMd5\":\"c991b3e4653582384a08c84ccbbb8c0b\",\"version\":\"20230807150015\",\"url\":\"http://10.0.0.01/hwtestdatavo/f5db/49/audio-video-server_data_appsource_appplugins_js_20220815175547_encodejs.js\",\"iosStartPrdVersion\":111,\"name\":\"111\",\"adStartPrdVersion\":111,\"id\":\"JS9BBD54065E1E434FBFF062071346E7\",\"judge\":\"client\",\"adEndPrdVersion\":-1}],\"version\":null}}}";
//表达式相关https://blog.csdn.net/weixin_44169484/article/details/104979985
//$.data.student[?(@.isVIP==true)]表示提取student数组中,isVIP属性=true的元素的值。
//指定数组下的某个字段的值
String jsonPath="$.body.USER_GROUP_MODULE.ruleList[?(@.id=='UGR1C3F9868799744169D135E83313CB')].url";
//对象
String jsonPath="$.body.USER_GROUP_MODULE.ruleList";
//数组
String jsonPath="$.body.USER_GROUP_MODULE.ruleList[0]";
//数字
String jsonPath="$.x-amz-meta-dv";
//多个值
String jsonPath="$.body.USER_GROUP_MODULE.ruleList[*]";
List list=js.extractWithJsonPath(jsonString,jsonPath);
if(!list.isEmpty()){for(String s:list){log.info(s);}}
3.执行结果如下
脚本地址:
链接:https://pan.baidu.com/s/1paaCcjlqT3YufMazVHuA0g
提取码:2f2p