1

I've below setup, i've tried to pass the value from non-gui mode but it doesn't work.

  1. Config Element/User Defined Variable: portNum:8080
  2. Config Element/HTTP Request Defaults: Port Number: ${__P(portNum,${portNum})}
  3. I've created 2 If Controller something like below. It will execute those if controller if it match the port number First If Controller: ${__jexl3("${portNum}" == "8080")} Second If Controller: ${__jexl3("${portNum}" == "8888")}
  4. It works when i run it from GUI mode but not from command line c:\jmeter\apache-jmeter-5.2.1\apache-jmeter-5.2.1\bin> jmeter -DportNum=8888 c:\Jmeter\TestVariable.jmx

From the command line, i've set the portNum value with 8888. but it didn't work. Any ideas how to solve this?

2 Answers 2

1

-D command-line argument sets a Java System Property, you won't be able to get its value using __P() function, if you want to proceed - consider switching to i.e. __groovy() function which should look like:

${__groovy(System.getProperty('portNum'),)} 

otherwise consider moving from -D to -J which sets a JMeter Property which can be accessed your way.

More information:

Also according to JMeter Best Practices you should always be using the latest version of JMeter so maybe it worth considering upgrading.

0

You can pass the value of the portNum variable from the command line while running your JMeter script in non-GUI mode by using the following command:

jmeter -JportNum=8888 -n -t c:\Jmeter\TestVariable.jmx -l c:\Jmeter\results.jtl

Here, the -J option is used to set the value of a system property. The -n option runs JMeter in non-GUI mode and the -t option specifies the path to your JMeter script. The -l option specifies the path to the output results file.

Also, in the first If Controller, you need to change the condition to:

${__jexl3("${portNum}" == "8080")}

and in the second If Controller, you need to change the condition to:

${__jexl3("${portNum}" == "8888")}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.