zoukankan      html  css  js  c++  java
  • jmeter 发送加密请求 beanshell断言 线程组间传递参数

    原文地址https://www.cnblogs.com/wnfindbug/p/5817038.html

    最近在做http加密接口,请求头的uid参数及body的请求json参数都经过加密再发送请求,加密方式为:ase256。所以,jmeter发送请求前也需要对uid及json参数进行加密。

    我这里是让开发写了个加密、解密的jar,jmeter直接调用这个jar包进行加密、解密。

    1、加解密的jar包放到jmeter的libext目录下

    2、在测试计划-->Add directory or jar to classpath 添加需要调用的jar包

    jmeter调用

    import com.changfu.EncryptAndDecryptInterface;  #导入加密类
    String json_str = "{"username":"amychen02","password":"F59BD65F7EDAFB087A81D4DCA06C4910","deviceNo":"355848069888942"}";  #请求的参数
    String enpost=EncryptAndDecryptInterface.getEncryptPost(json_str);  #将请求参数加密
    vars.put("enpost",enpost);   #数据存到jmeter变量中

     

    4、请求发送加密码的参数

    在http请求-->body data直接使用上一步加密后的参数变量enpost

    jmeter bean shell断言加密的响应信息(加密接口测试二)

    断言加密的响应信息

    1、在http请求-->添加-->断言-->bean shell 断言

    import com.changfu.EncryptAndDecryptInterface;  //导入jar包的EncryptAndDecryptInterface类
    import org.json.JSONObject; //导入
    String json_res = prev.getResponseDataAsString(); //获取上个响应信息
    String resb = EncryptAndDecryptInterface.getDecrypt(json_res);  //调用解密工具解密
    vars.put("resb",resb);  
    log.info("解密后的响应信息json="+resb);
    JSONObject resbonseJson = new JSONObject(resb); //解析json
    String status_str = resbonseJson.get("status").toString(); //截取status字段值
    vars.put("status_str",status_str);
    log.info("执行状态="+status_str);
    String result = "0";
    vars.put("result_str",result);
    if (!status_str.equals(result)) {   //响应信息的状态值status_str不等于0,则断言其他与实际值不一致
        Failure=true;       
        FailureMessage="statuscode与实际值不一致, 实际值为:"+status_str+", 响应信息: "+resb;
    }

     

    jmeter 线程组之间的参数传递(加密接口测试三)

    场景测试中,一次登录后做多个接口的操作,然后登录后的uid需要关联传递给其他接口发送请求的时候使用。

    1、在登录接口响应信息中提取uid字段值

      1>login请求 -->添加 -->后置处理器--> bean shell postprocessor

     

    2,在bean shell postprocessor提取uid

     
    import com.changfu.EncryptAndDecryptInterface;
    import org.json.JSONArray;
    import org.json.JSONObject;

    String json_res = prev.getResponseDataAsString(); //获取登录请求的响应信息
    String resb = EncryptAndDecryptInterface.getDecrypt(json_res);  //调用解密工具解密,对响应信息解密
    vars.put("resb",resb);  
    log.info("解密后的响应信息resb="+resb);
    JSONObject data_obj = new JSONObject(resb);   //解析json响应信息

    String uid_str = data_obj.get("result").get("id").toString();  //截取响应信息中uid的值 
    props.put("uid_str",uid_str);   //将uid_str数据存到变量中,这里用props.put,其他线程组可调用请该变量
    log.info("加密前的uid="+uid_str);

     

    需要传递的参数添加到用户参数

     3、在另一个线程组接收该变量uid_str

      1>线程组->添加-->前置处理器-->BeanShell PreProcessor
    import com.changfu.EncryptAndDecryptInterface;

    String uid_str = props.get("uid_str"); //获取登录传递的uid_str变量
    String enuid=EncryptAndDecryptInterface.getEncryptUID(uid_str);  //加密登录返回的uid
    vars.put("enuid",enuid);
    log.info("加密登录后返回的uid"+enuid);
  • 相关阅读:
    select下拉的value和option内值得获取
    express模块下GET和POST获取前台数据
    Node.js---fs模块
    Node.js---MySQL的增删改查
    Node.js--mysql的应用
    Node.js-router(将大服务拆分成一个个小服务)
    22
    窗口切换
    IO
    第一次实训作业
  • 原文地址:https://www.cnblogs.com/111testing/p/9950140.html
Copyright © 2011-2022 走看看