jmeter no-gui模式动态传递场景参数

时间:2022-04-10 19:07:56

jmeter进行性能压测时,有时候需要在linux上no-gui模式下运行,为了在no-gui模式下更方便的设置脚本的运行的场景,

将脚本的线程数,运行时间设置为动态参数,可以在脚本运行时动态设置“线程数”和“场景运行时间”;详情如下:

#!/bin/bash

## JthreadCount:定义运行的线程数,在脚本中引用“${__P(threadCount,)}”
## JDurationTime:定义场景的运行时间(单位秒S),在脚本中引用“${__P(DurationTime,)}”
## --h:使用方法demo
## --r:运行脚本同时输出报告和日志文件
## --n:运行脚本不输出报告和日志文件 if [ $ == "--h" ]; then
##使用的demo
echo "./runTest.sh 运行指令(--r) JthreadCount(线程数) JDurationTime(场景运行时间) ScriptName(脚本)"
elif [ $ == "--r" ]; then
##运行脚本,输出报告和日志文件
./jmeter.sh -n -JthreadCount=$ -JDurationTime=$ -t $ -j $PWD/result/$(date +%y%m%d%H%M%S)_test_log.log -l $PWD/result/$(date +%y%m%d%H%M%S)_test_result.jtl
elif [ $ == "--n" ]; then
#运行脚本不输出报告和日志文件
./jmeter.sh -n -JthreadCount=$ -JDurationTime=$ -t $
fi

使用demo:

#在jmeter的bin目录下执行:
./runTest.sh --n performanceScript/testScript/demo.jmx # :线程数
# :场景运行时间
# demo.jmx :要运行的脚本

在脚本中的设置:

jmeter no-gui模式动态传递场景参数