jmeter

后置处理器

json提取器

http://www.51testing.com/html/18/n-4461218.html

https://www.cnblogs.com/tudou-22/p/12579575.html

https://www.wenjianb.com/baike/6774.html

https://www.cnblogs.com/yuhuiqing/p/11784265.html

若需要多个条件过滤,需要&&连接多个条件,如下

$.data[?(@.schemaName!='performance_schema' && @.schemaName!='sys')].schemaName
$.data[?(@.JobStatus==3||@.JobStatus==4)]
//也可以使用正则表达式
$.data.data[?(@.bucketName=~/autobucket.*/)]

 

 

线程组传参问题:

通过JSON提取器 获得的变量只能用于本线程。可以在该提取器之后新加一个BeanShell后置处理器将JSON提取器中的变量存入property

 

  • 数组
${allrdsClusterIDs}为json提取器获取的所有id

BeanShell后置处理程序

可以直接写java脚本,实用性更强

https://blog.csdn.net/weixin_30859423/article/details/95674726?fps=1&locationNum=2

https://blog.csdn.net/evanzhang_z/article/details/102715619

${allIDs_matchNr}为${allIDs}的数量
import java.util.Arrays;
int count = ${allIDs_matchNr};
String[] totalIDS = new String [count];
for(i=1;i<=count;i++){
    String a = vars.get("allIDs_"+i);
    totalIDS[i-1] =  a;
}
String arr = Arrays.toString(totalIDS);
log.warn("arr:"+arr);
vars.putObject("totalIDS",arr);
  •  json

需要在测试计划中添加jar包

import com.alibaba.fastjson.*;
String all_configs = vars.get("ClusterConfigs");
String ClusterName=vars.get("ClusterName");
JSONArray json_array_configs = JSONArray.parseArray(all_configs);
JSONObject object = json_array_configs.getJSONObject(0);

JSONArray json_array_updated_configs = new JSONArray();//只修改第一个参数back_log
for(int i=0;i<json_array_configs.size();i++){
    JSONObject  object = json_array_configs.getJSONObject(i);
    if(i==0){
        object.remove("value");
        object.put("value","${__Random(0,65535,)}");
        log.warn("修改的参数为:"+object.toString());
    }
    object.put("url","nerv/nerv-rds/"+ClusterName+"/Mysql/config/variables/dev/variables.json");
    json_array_updated_configs.add(object);
}
log.warn(json_array_updated_configs.toString());
vars.put("update_configs",json_array_updated_configs.toString());

 

参数以空格分隔

脚本中通过bsh.args[0]获取。例如

String aa=bsh.args[0];

 

获取接口的响应数据

String str_json = prev.getResponseDataAsString();

 

逻辑控制器

while controller

在判断条件中如果引入变量需注意写法

${__javaScript(${My_value}<1)}
对字符串的条件判断语句 ${__javaScript('${orderid}'=='null')}
对数字的条件判断语句
${__jexl3(${fileCount}>${index},)}
${__javaScript(${count}==0)}

https://blog.csdn.net/ccc135/article/details/80658346

 https://www.jianshu.com/p/c46f473f3a6e

 

 

固定定时器

会在该接口执行前等待指定的毫秒数

 

JDBC连接

https://www.cnblogs.com/poloyy/p/13182706.html

 

 自带的函数

__RandomFromMultipleVars

获取系统时间__time ,时间加减__timeShift

 

linux中如何运行

https://www.cnblogs.com/jessicaxu/p/7555046.html

 

CSV data config

参数化JSON的数据

 json键值对需使用两个双引号包裹,如""key""

 对header处理

import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.control.Header;
// 获得请求头信息
HeaderManager headers = sampler.getHeaderManager();
// 打印删除指定请求头参数前的全部请求头信息
//log.info("删除前" + headers.getHeaders().getStringValue());
// 删除请求头指定的信息
sampler.getHeaderManager().removeHeaderNamed("Content-Type");
// 增加请求头
// Header myHeaderCT = new Header("Content-Type", "application/json");
// headers.add(myHeaderCT);
// 打印删除指定请求头参数后的全部请求头信息
log.info("删除后" + headers.getHeaders().getStringValue());
int tn = ctx.getThreadNum();
log.info("线程号:======= " + tn);

 

oss process sampler

用于执行脚本

 

posted on 2020-05-17 22:11  石墨方  阅读(78)  评论(0编辑  收藏  举报

导航