• 【测试工具】Jmeter常用beanshell


    1,jemter打印超过预期响应时间的耗时

    int time = prev.getTime(); //获取接口响应时间

    if(time > 3000){                 //判断如果响应时间大于3秒则输出相关内容

    FileWriter fstream = new  FileWriter("/home/PerfSpace/04project/errLog/TimeLong.txt",true);

    BufferedWriter out = new BufferedWriter(fstream);

    out.write("=================================开始===================================");        

    out.write(System.getProperty("line.separator"));        

    out.write("接口响应时间(ms):");

    out.write(prev.getTime().toString());        //将int类型响应时间转成string并输出

    out.write(System.getProperty("line.separator"));        

    out.write("请求头信息是:");

    out.write(prev.getRequestHeaders());     //(我测试的流水号在header里)输出响应头信息,正常可以输出流水号、响应报文、参数化的某个变量等,   

    out.write(System.getProperty("line.separator"));        

    out.write("=================================结束===================================");        

    out.write(System.getProperty("line.separator"));        

    out.close();

    fstream.close();        

    }

    2,jemter的beanshell断言,并打印报错信息

    String resp = prev.getResponseDataAsString();
    String code = prev.getResponseCode();
    String reqDate = prev.getSamplerData();
    String time="${__time(yyyy-MM-dd HH:mm:ss,)}";

    if ("200".equals(""+code) == false){  //判断响应是否包含200;也可以判断字符串:if((response.contains("\"bindStatus\":\"Y\""))) 
    Failure = true;
    String[] ss = resp.split("\n");
    FailureMessage = ss[0];
    FileWriter fstream = new FileWriter("/home/PerfSpace/03project/errLog/ATH文件下载Error.txt",true);   //打开要写入文件的路径和名称
    BufferedWriter out = new BufferedWriter(fstream); 
    out.write("===================================began================================");
    out.write("请求时间:"+vars.get("time"), "请求报文:"+reqDate);
    out.write(System.getProperty("line.separator"));       //换行符,避免内容打印到一行,不方便查看
    out.write("响应时间:"+vars.get("time"),"接口响应:"+FailureMessage);
    out.write(System.getProperty("line.separator"));
    out.write("===================================over================================");
    out.write(System.getProperty("line.separator"));
    out.close();
    fstream.close();
    }
    else {
    Failure = false;
    }

  • 相关阅读:
    Python 模拟超市收银抹零行为
    MySql模糊查询大全
    Unity UGUI的Image(图片)组件的介绍及使用
    基于单电阻采样的电流重构
    Redis面试题(四)
    java使用ws.schild.jave将视频转成mp4
    优秀的 OKR 案例参考
    [CISCN 2023 初赛]go_session
    编写第一个Go程序
    IDEA2022.1创建maven项目,规避idea2022新建maven项目卡死,无反应问题
  • 原文地址:https://blog.csdn.net/m0_49428126/article/details/127437442