jMeter - Functions

JMeter functions are special values that can populate fields of any Sampler or other element in a test tree.
A function call looks like this −
A function call looks like this −
${__functionName(var1,var2,var3)}

_functionName matches the name of a function. For example ${__threadNum}.
_functionName matches the name of a function. For example ${__threadNum}.
If a function parameter contains a comma, then make sure you escape this with "\" as shown below −
If a function parameter contains a comma, then make sure you escape this with "\" as shown below −
${__time(EEE\, d MMM yyyy)}

Variables are referenced as −
Variables are referenced as −
${VARIABLE}

Following table lists a group of functions loosely grouped into types −
There are two kinds of functions −

User-defined static values (or variables)
Built-in functions


There are two kinds of functions −
User-defined static values (or variables)
User-defined static values (or variables)
Built-in functions
Built-in functions
User-defined static values allow the user to define variables to be replaced with their static value when a test tree is compiled and submitted to be run.
User-defined static values allow the user to define variables to be replaced with their static value when a test tree is compiled and submitted to be run.
The variables cannot be nested; i.e ${Var${N}} does not work.
The variables cannot be nested; i.e ${Var${N}} does not work.
The __V (variable) function (versions after 2.2) can be used to do this − ${__V(Var${N})}. 
The __V (variable) function (versions after 2.2) can be used to do this − ${__V(Var${N})}. 
This type of replacement is possible without functions, but it is less convenient and less intuitive.
This type of replacement is possible without functions, but it is less convenient and less intuitive.
Functions and variables can be written into any field of any test component.
The following functions should work well in a test plan −
intSum
longSum
machineName
BeanShell
javaScript
jexl
random
time
property functions
log functions
Functions which are used on the Test Plan have some restrictions. JMeter thread variables will have not been fully set up when the functions are processed, so variable names passed as parameters will not be set up and variable references will not work. Hence, split() and regex() and the variable evaluation functions will not work. The threadNum() function will not work and it does not make sense at test plan level.
Referencing a variable in a test element is done by bracketing the variable name with '${' and '}'.
Referencing a variable in a test element is done by bracketing the variable name with '${' and '}'.
Functions are referenced in the same manner, but by convention, the names of functions begin with "__" to avoid conflict with user value names.
Functions are referenced in the same manner, but by convention, the names of functions begin with "__" to avoid conflict with user value names.
Some functions take arguments to configure them, and these go in parentheses, comma-delimited. If the function takes no arguments, the parentheses can be omitted. For example −
Some functions take arguments to configure them, and these go in parentheses, comma-delimited. If the function takes no arguments, the parentheses can be omitted. For example −
${__BeanShell(vars.put("name"\,"value"))}

Alternatively, you can define your script as a variable, e.g. on the Test Plan −
Alternatively, you can define your script as a variable, e.g. on the Test Plan −
SCRIPT     vars.put("name","value")

The script can then be referenced as follows −
The script can then be referenced as follows −
${__BeanShell(${SCRIPT})}

The Function Helper Dialog is available from JMeter's Options tab.
Using the Function Helper, you can select a function from the pull down, and assign values for its arguments. The left column in the table provides a brief description of the argument, and the right column is where you write the value for that argument. Different functions take different arguments.
Using the Function Helper, you can select a function from the pull down, and assign values for its arguments. The left column in the table provides a brief description of the argument, and the right column is where you write the value for that argument. Different functions take different arguments.
Once you have done this, click the “Generate" button, and the appropriate string is generated, which you can copy-paste into the test plan wherever you need to.
Once you have done this, click the “Generate" button, and the appropriate string is generated, which you can copy-paste into the test plan wherever you need to.
Some variables are defined internally by JMeter. They are −
COOKIE_cookiename − contains the cookie value.
COOKIE_cookiename − contains the cookie value.
JMeterThread.last_sample_ok − whether or not the last sample was OK − true/false. Note − this is updated after PostProcessors and Assertions have been run.
JMeterThread.last_sample_ok − whether or not the last sample was OK − true/false. Note − this is updated after PostProcessors and Assertions have been run.
START variables.
START variables.
Some built-in properties are defined by JMeter. These are listed below. For convenience, the START properties are also copied to variables with the same names.
START.MS − JMeter start time in milliseconds.
START.MS − JMeter start time in milliseconds.
START.YMD − JMeter start time as yyyyMMdd.
START.YMD − JMeter start time as yyyyMMdd.
START.HMS − JMeter start time as HHmmss.
START.HMS − JMeter start time as HHmmss.
TESTSTART.MS − test start time in milliseconds.
TESTSTART.MS − test start time in milliseconds.
Note that the START variables / properties represent JMeter startup time, not the test start time. They are mainly intended for use in file names etc.

    59 Lectures 
     9.5 hours 

 Rahul Shetty

    54 Lectures 
     13.5 hours 

 Wallace Tauriac

    23 Lectures 
     1.5 hours 

 Anuja Jain

    12 Lectures 
     1 hours 

 Spotle Learn
 Print
 Add Notes
 Bookmark this page