通过 bat 文件在 运行 时间将值传递给 JMeter 脚本

Passing values to JMeter script at run time through bat file

我需要在 运行 获取用户输入后将线程组、加速时间和循环计数传递给 JMeter 脚本。

为此,我创建了一个如下所示的 bat 文件:

@echo off
title Accepting User Inputs And Passing It To JMeter Scripts !!
echo Welcome To The World Of Performance Testing !!

set /p thread=Enter the count for thread groups: 
set /p rampup=Enter the ramp up peroid: 
set /p loopcount=Enter the loopcount:

set /p cd = "E:\apache-jmeter-3.2\bin"

%cd%\jmeter -n -t E:\apache-jmeter-3.2\bin\scripts\SampleTestPlan.jmx -l 
E:\apache-jmeter-3.2\bin\results\result1.csv -JThread=%thread% - 
JRampUp=%rampup% -JLoopCount=%loopcount%

pause

但我得到如下输出,它正在接受输入,但我无法通过重定向到位置 - 在非 GUI 模式下向 运行 Jmeter 启动命令E:\apache-jmeter-3.2\bin 使用.bat 文件。

在另一个(即 "fresh")中尝试 运行 您的脚本 terminal window,您的脚本看起来或多或少不错,可能是您有 %cd% 变量在其他地方定义,它会覆盖批处理脚本中的设置。


另请注意 according to JMeter Best Practices you should always be using the latest version of JMeter so consider upgrading to JMeter 5.0 (or whatever is the most recent version available at JMeter Downloads 页)尽快

在脚本中转到jmeter目录:

 E:
 cd E:\apache-jmeter-3.2\bin
 jmeter -n -t E:\apache-jmeter-3.2\bin\scripts\SampleTestPlan.jmx -l 
   E:\apache-jmeter-3.2\bin\results\result1.csv -JThread=%thread% - 
   JRampUp=%rampup% -JLoopCount=%loopcount%

@user7294900 - 在我的批处理文件中使用了以下内容 -

e:
cd apache-jmeter-3.2\bin

jmeter -n -t E:\apache-jmeter-3.2\bin\scripts\SampleTestPlan.jmx -l E:\apache-jmeter-3.2\bin\results\results1.csv -JThreads=%thread% -JRampUp=%rampup% -JLoopCount=%loopcount%

pause

您也可以使用 Start 的选项!

@Echo Off
Title Accepting user inputs and passing them to a JMeter Script
Echo Welcome To The World Of Performance Testing.
Set /P "thread=Enter the count for thread groups: "
Set /P "rampup=Enter the ramp up peroid: "
Set /P "loopcount=Enter the loopcount: "
Set "jmdir=E:\apache-jmeter-3.2\bin"
Start "" /B /D "%jmdir%" /Wait jmeter -n -t scripts\SampleTestPlan.jmx -l results\result1.csv -JThread=%thread% -JRampUp=%rampup% -JLoopCount=%loopcount%
Pause