I want to parametrize the testdata path, result path, server and port by defining them in environment variable.
I was able to achieve this to certain extent with System.getenv("Jmeter_Result")
using it in BeanShell processor. But I need to use configuration element to fetch the value.
Can you kindly suggest.I am using Jmeter 3.1.
You can access JMeter variables by going into thread groups and you can use them in any test element, except the test plan.
JMeter Properties: set to true to print JMeter Properties, JMeter Variables: set to true to print JMeter Variables like ${foo} (all variables set so far in the script), System Properties: set to true to print Java System Properties.
Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function. When using \ before a variable for a windows path for example C:\test\${test}, ensure you escape the \ otherwise JMeter will not interpret the variable, example: C:\\test\\${test}.
According to https://jmeter.apache.org/usermanual/functions.html#what_can_do, ${__BeanShell( ... )}
may also help you on this issue.
For instance, one of our APIs needs OAuth2 authentication, and what I did was:
- Thread Group
- User Defined Variables
client_id = ${__BeanShell( System.getenv("client_id") )}
client_secret = ${__BeanShell( System.getenv("client_secret") )}
- Once Only Controller
- OAuth2 HTTP Request
- API HTTP Request
There is __env() function available via JMeter Plugins, it seems to be something you're looking for.
You can install __env()
and other custom JMeter Functions using JMeter Plugins Manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With