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

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

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

#!/bin/bash

## JthreadCount:定义运行的线程数,在脚本中引用“${__P(threadCount,)}”
## JDurationTime:定义场景的运行时间(单位秒S),在脚本中引用“${__P(DurationTime,)}”
## --h:使用方法demo
## --r:运行脚本同时输出报告和日志文件
## --n:运行脚本不输出报告和日志文件


if [ $1 == "--h" ]; then
    ##使用的demo
    echo "./runTest.sh 运行指令(--r) JthreadCount(线程数) JDurationTime(场景运行时间) ScriptName(脚本)"
elif [ $1 == "--r" ]; then
    ##运行脚本,输出报告和日志文件
    ./jmeter.sh -n -JthreadCount=$2 -JDurationTime=$3 -t $4 -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 [ $1 == "--n" ]; then
    #运行脚本不输出报告和日志文件
    ./jmeter.sh -n -JthreadCount=$2 -JDurationTime=$3 -t $4
fi

使用demo:

#在jmeter的bin目录下执行:
./runTest.sh --n 2 30 performanceScript/testScript/demo.jmx

# 2 :线程数
# 30 :场景运行时间
# demo.jmx :要运行的脚本

在脚本中的设置:

 

posted @ 2017-06-26 20:03  veitch-w  阅读(1382)  评论(0编辑  收藏  举报