AI智能
改变未来

jmeter,beanshell比对参数值是否符合特定条件

先判断参数是否存在

if(lesson.containsKey(\"recordOssName\")){recordOssName = lesson.get(\"recordOssName\");}else{log.info(\"recordOssName不存在\");}

再判断参数值是否符合特定条件

int lessonId = lesson.get(\"lessonId\");if(recordOssName.contains(\"%\")){log.info(\"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\");log.info(\"recordOssName---->\"+recordOssName);log.info(\"courseDraftId---->\"+${courDraftId});}else{log.info(\"courseDraftId---->\"+${courDraftId}+\"lessonId--->\"+lessonId.toString()+\"视频通过\");}}

全部代码:

import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;String jsonContent = prev.getResponseDataAsString();JSONObject response = JSON.parseObject(jsonContent);JSONArray chapterList = response.getJSONObject(\"data\").getJSONArray(\"chapterList\");int clength = chapterList.size();//章节数log.info(\"clength==>\"+clength.toString());log.info(\"-----开始执行循环-----\"+${counter});System.out.println(\"-----开始执行循环-----\"+${counter});String recordOssName = \"\";int lessonId = 0;for(int i=0;i<clength;i++){JSONObject chapter = (JSONObject)chapterList.getJSONObject(i);//	log.info(\"chapter---->\"+chapter.toString());JSONArray lessonList = chapter.getJSONArray(\"lessonList\");int llength = lessonList.size();//课时数log.info(\"llength==>\"+llength.toString());for(int j=0;j<llength;j++){JSONObject lesson = (JSONObject)lessonList.getJSONObject(j);log.info(\"lesson---->\"+lesson.toString());if(lesson.containsKey(\"recordOssName\")){recordOssName = lesson.get(\"recordOssName\");}else{log.info(\"recordOssName不存在\");}//          if(lesson.containsKey(\"lessonId\")){//          	lessonId = lesson.get(\"lessonId\");//          	}else{//          		log.info(\"lessonId不存在\");//          		}if(recordOssName.contains(\"%\")){log.info(\"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\");log.info(\"recordOssName---->\"+recordOssName);log.info(\"courseDraftId---->\"+${courDraftId});}else{log.info(\"courseDraftId---->\"+${courDraftId}+\"视频--->\"+recordOssName+\"-->视频通过\");System.out.println(\"courseDraftId---->\"+${courDraftId}+\"视频--->\"+recordOssName+\"-->视频通过\");}}}log.info(\"-----循环end-----\");
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » jmeter,beanshell比对参数值是否符合特定条件