Override JMeter Variable from Command Line

Q

How to Override a JMeter Variable from Command Line? I want to run the same test plan multiple times by changing the value of a variable I defined in the test plan.

✍: FYIcenter.com

A

JMeter command line does not allow you to override any variables you defined in the test plan.

But it allows you to override any JMeter property. So you that you indirectly override a test plan variable through a JMeter property by following this tutorial.

1. Run JMeter and open "\fyicenter\Facebook-Login-Test-7.jmx".

2. Click on "Facebook Login Test Plan", and add a variable called "password".

Name: password
Value: ${__P(pw,NoOneKnows)}

The expression in the value field, ${__P(pw,NoOneKnows)}, calls the JMeter built-in function __P(), which returns the value from a JMeter property called "pw", or "NoOneKnows" if the "pw" is not defined.

3. Click on "POST Login & Password" sampler, and update the "password" value to be "${password}, which takes the value from the test plan variable "password".

4. Save the test plan as "\fyicenter\Facebook-Login-Test-8.jmx" and run it from a command line twice. For the second run, "-J" option is used to provide value to a JMeter property.

>\fyicenter\jmeter\bin\jmeter -n -t Facebook-Login-Test-8.jmx
	(run the test plan with default password)
	
>\fyicenter\jmeter\bin\jmeter -n -t Facebook-Login-Test-8.jmx -J pw=Abcd1234
	(run the test plan with a given password)

Now you can repeat the test with different passwords at the command line.

The picture below shows you how to use the "-J" command line option to override a JMeter property, which can be passed to a test plan variable:
Override Variable via Property at Command Line

 

Running JMeter in Command Line Mode

⇒⇒Apache JMeter Tutorials

2017-12-04, 184👍, 0💬