Jmeter BeanShell 变量的获取和日志打印简记
${__setProperty(token,${token_info},)} //将局部变量token_info的值保存到全局变量token中
${__setProperty(id_,${id},)}
${__setProperty(msg_,${msg},)}
//设置变量 vars.put()
vars.put("msg_1","哈哈哈");
//获取变量的值 vars.get()
log.info("********************JSON提取器-局部变量msg值为:" + vars.get("msg"));
log.info("********************在BeanShell设置的局部变量msg_1的值为:" + vars.get("msg_1"));
//设置全局变量的值 props.put(“name”,“value”)
props.put("val","全局变量");
//获取全局变量的值 props.get(“val”)
log.info("********************全局变量id_值为:" + ${__P(id_,)});
log.info("********************登录接返回的token值为:" + props.get("token"));
log.info("********************在BeanShell设置的全局val变量值为:" + props.get("val"));
//获取前面取样器的值
log.info(prev.getRequestHeaders()); //获取请求头的信息
log.info(prev.getSamplerData()); //获取请求内容
log.info("code: " + prev.getResponseCode()); //获取响应码
log.info(prev.getResponseDataAsString()); //获取相应内容,返回字符串
//log.info("");
//获取上下文的变量 ctx.getProperties()
log.info("ctx.getProperties()");
//控制台打印,需要到控制台才能看见打印的内容
System.out.println("控制台打印");
System.out.println(ctx.getProperties());
//打印INFO、ERROR级别的日志,在jmeter日志
log.info("============打印INFO级别的日志===================");
log.error("============打印ERROR级别的日志===================");