参考链接:https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html

 

添加变量到jmeter

String n="hqj";
vars.put("n",n);

获取jmeter变量

String n =vars.get("n");

 

断言失败则打印响应信息

String jsonResult = prev.getResponseDataAsString();
String mobile=vars.get("mobile");
if (!jsonResult.contains("\"retCode\":\"0000\"" ) && !jsonResult.contains("\"retCode\":\"9999\"" )){
Failure = true;
FailureMessage = mobile+"断言失败"+jsonResult;
log.info(FailureMessage);
}

 

 

 接口响应信息

String str=prev.getResponseDataAsString();

String RequestHeaders = prev.getRequestHeaders(); // 获取请求头
String ResponseHeaders = prev.getResponseHeaders(); // 获取响应头
String responseCode = prev.getResponseCode(); // 获取响应码
String responseData = prev.getResponseDataAsString(); // 获取响应数据
String ContentType = prev.getContentType() //获取取样器响应Content-Type首部字段的值域(包含参数)

 

 

 

 

String iresponse = new String(ResponseData,"UTF-8");//中文乱码处理
log.info("请求头:"+ResponseHeaders);
log.info("请求url+参数:"+SamplerData);
log.info("响应码:"+ResponseCode);
log.info("响应信息"+iresponse);

posted on 2022-05-08 18:15  筑梦小小屋  阅读(62)  评论(0编辑  收藏  举报