jmeter 中用python 实现请求参数的随机

首先需要下载插件来让jmeter支持python脚本

下载地址:https://www.jython.org/download,下载完成后放到jmeter安装目录的lib文件夹下

放置完成后需要重启jmeter,添加JSR223 PreProcessor,Language下拉框中多2项

选择第一项,添加python脚本,脚本中metrics_ids3和metrics_weidu3的值为列表

复制代码
import json  
import random  
  
# 原始的metrics id和维度列表  
m***s_ids = ${metrics_ids3}
m***s_weidus=${metrics_weidu3}
  
# 生成随机组合的函数  
def generate_random_combination(ids):  
 return random.sample(ids, random.randint(1, len(ids)))  
  
# 生成随机组合指标和维度
chosen_m***s_ids = generate_random_combination(m***s_ids)
chosen_m***s_weidus = generate_random_combination(m***s_weidus)   
  
# 将chosen_metrics_ids赋值给randomMet***s  
randomMet***Ids = chosen_met***s_ids
randomWeidus= chosen_met***s_weidus

# 打印到JMeter日志中(可选)  
#log_message = "Random Met***s IDs: " + str(randomMet***Ids) +" Random weidus:"+str(randomWeidus)
## 使用print语句在JMeter日志中输出
#print(log_message)    
  
# 构造整个请求体  
body = {  
    "chosenM***sIds": chosen_met***s_ids,  
    "chosenD***Ids":[] ,  
    "timeP***tion": {  
        "statTime": "m***",  
        "beginTime": "202*-02",  
        "endTime": "202*-01"  
    },  
    "printSql": False,  
    "pageNum": -1  
}  
  
# 将整个body转换为JSON格式的字符串  
body_json = json.dumps(body)  
  
# 将body_json设置为JMeter变量  
vars.put("requestBodyJson", body_json)

在http请求中添加body${requestBodyJson}

添加View Results Tree,运行脚本,查看结果

相关推荐
卖个几把萌3 小时前
【11】JMeter在GUI页面修改语言后右上角不显示线程数和持续时间问题解决
测试工具·jmeter
张永清-老清3 小时前
每周读书与学习->JMeter性能测试脚本编写实战(四)-利用JMeter对MySQL数据库查询进行性能测试
学习·jmeter·性能调优·jmeter性能测试·性能分析·每周读书与学习
Jul1en_9 小时前
【性能测试工具】JMeter下载安装、编辑环境变量和中文配置
测试工具·jmeter
一碗面4212 天前
Jmeter的进阶功能
jmeter
月明长歌4 天前
从零构建高并发测试体系:JMeter 接口压测与全链路实战指南
jmeter
一碗面4215 天前
Jmeter的基本使用
jmeter
余防6 天前
jmeter使用
jmeter
maqiang_7206 天前
jmeter做压力测试如何找到软件瓶颈
jmeter·压力测试
少云清7 天前
【软件测试】1_性能测试实战 _商城项目介绍
jmeter·性能测试
少云清7 天前
【软件测试】8_性能测试实战 _执行测试脚本
jmeter·性能测试·测试脚本执行