2
votes

I need to pass thread group, ramp up time and loop count to a JMeter script at run-time after getting the inputs from the user.

For this I have created a bat file like below:

@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

But I'm getting the output as below, it's accepting the inputs but I'm unable to launch the command to run Jmeter in non-GUI mode by redirecting to location - E:\apache-jmeter-3.2\bin using the .bat file.

enter image description here

4
cd is reserved for current directory, so you use %cd%, which is not the same as %cd % that you set using set /p cd = .... The space before = can be included as part of the variable name.michael_heath

4 Answers

1
votes

Go to directory of jmeter in script:

 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%
1
votes

Try running your script in another (i.e. "fresh") terminal window, your script looks more or less good, it might be the case you have %cd% variable defined somewhere else and it overrides the setting from the batch script.


Also be aware that 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 page) as soon as possible

1
votes

You may be able to use Start's options too!

@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
0
votes

@user7294900 - Have used below thing in my batch file -

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