• jmeter beanshell断言 判断 且写入txt文件


    import org.json.*;
     
    //获取上一个请求的返回值
    String response = prev.getResponseDataAsString();
    //将返回值转换为json
    JSONObject responseJson = new JSONObject(response);
    
    log.info("message的值:" + ResponseCode);
    
    if("200".equals(ResponseCode)) {   //判断请求码是否为200
        FailureMessage = "新用户输出";
    
    //有效用户写入txt
    	FileWriter token = new FileWriter("/Users/lucax/Desktop/探月压测协助/获取用户token+报名/b2c新用户.txt",true);
    	BufferedWriter out = new BufferedWriter(token);
    	out.write(vars.get("u_id")+',');
    	out.write(vars.get("phone")+',');
    	out.write(vars.get("token")+"
    ");
    	out.close();
    	token.close();
    //	log.info("message的值:" + 1111111111);
     }else{
        Failure = true; 
        FailureMessage = "旧用户抛弃";
    //    log.info("message的值:" + 2);
       } 

    prev.setDataEncoding("utf-8"); //解决响应乱码问题
    String json = prev.getResponseDataAsString();
    if(json.contains(""status":0")){           -------这个貌似是获取相应是否包含
      Failure=false;
    }else{
      Failure=true;
      FailureMessage=json;
    }

    参考:https://blog.csdn.net/yiqin3399/article/details/87857385

    参考:https://blog.csdn.net/tomoya_chen/article/details/77981707

    要下载一个jar包   链接: https://pan.baidu.com/s/1Qe6r-y4wO6WT-aiyWkaAFQ 提取码: qvn9 复制这段内容后打开百度网盘手机App,操作更方便哦

    放到jmeter的 lib目录下

    图例:

    获取json里面的值对比

    import org.json.*;
    String response = prev.getResponseDataAsString();
    JSONObject responseJson = new JSONObject(response);
    
    
    if("2743".equals(responseJson.getString("termIds"))) {
    	FailureMessage = "新用户输出";
    	FileWriter token = new FileWriter("/Users/lucax/Desktop/b2c用户伪造--探月压测协助/获取用户token+报名/new_out2.txt",true);
    	BufferedWriter out = new BufferedWriter(token);
    	out.write(vars.get("uid")+',');
    	out.write(vars.get("phone")+'
    ');
    	out.close();
    	token.close();
    }else{
    	Failure = true; 
    	FailureMessage = "旧用户抛弃";
    }
    

      

  • 相关阅读:
    测试用例(等价类和边界值方法)
    缺陷报告的组成
    软件测试QA、QC、QM的关系与区别
    软件的开发模式
    软件工程及生命周期
    互联网产品类型与产品工具
    canvas 时钟
    test2
    test121212
    关于iOS和OS X废弃的API你需要知道的一切
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/14771472.html
Copyright © 2020-2023  润新知