Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Environment Variable values in Jmeter

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.

like image 234
Sylvia Lobo Avatar asked Aug 02 '17 05:08

Sylvia Lobo


People also ask

How do you access variables in JMeter?

You can access JMeter variables by going into thread groups and you can use them in any test element, except the test plan.

How do you print the value of a variable in JMeter?

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.

What is __ P in JMeter?

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}.


2 Answers

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
like image 165
Frederick Zhang Avatar answered Jan 03 '23 10:01

Frederick Zhang


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.

JMeter Plugins Custom Functions.

like image 36
Dmitri T Avatar answered Jan 03 '23 12:01

Dmitri T