Apache JMeter Pre-defined Functions
Functions are a very basic idea in the field of software that perform some predefined activity by accepting some input and providing the desired result.
Additionally, Apache JMeter has a number of built-in functions that speed up and simplify a variety of basic coding and arithmetic processes.
How can I use or call JMeter functions?
The JMeter function’s format is described below:
${__functionName(var1,var2,var3)}
You must first be aware of the proper name for the function. To call a function, type the right function name, a dollar sign ($), a curly brace open (), and two underscores (__). Add the arguments next, separating them with a comma, then put them in brackets (), and finally close the curly brace ().
For instance, ${__intSum(2,4)}
Where functionName is intSum, input parameters 2 and 4 are enclosed in brackets, and the function is called.
The precise parameters change depending on the function. The brackets can be omitted for functions that don’t require any parameters.
For instance, ${__threadNum}
Make sure to escape any commas in function parameters with “” or else JMeter will interpret them as parameter delimiters.
For instance, ${__time(EEEE, yyyy-mm-dd,)}
Information Type Functions:
These functions are used to retrieve values or information from the system or JMeter, according to the Apache JMeter Function List
1. Obtaining the thread number using threadNum
threadGroupName: Obtaining the thread group name
samplerName: To obtain the label for the sampler.
machineIP: To find the machine’s local IP address machineName: To find the time and the local machine name: to obtain the present time in many formats.
timeShift: To obtain a date with the provided number of seconds, minutes, hours, or days added in a variety of formats.
To retrieve a log or display a message (and return the value), use the log command.
logn: To retrieve a message’s log or display it (empty return value)
2. Functions for Input Type
Read and write operations are performed using these functions.
To read a line from a file, use StringFromFile.
FileToString: reading a whole file
To read from a CSV-delimited file, use CSVRead.
XPath: to read from a file using an XPath expression
Write a string to a file using StringToFile.
3. Functions of the Calculation Type
Some fundamental mathematical processes use these functions.
counter: To create a number digest that increases: Create a digest (SHA-1, SHA-256, or MD5)
Add int numbers with intSum.
adding long numbers with longSum
To produce a random number, at random
To produce random dates within a defined date range, use RandomDate.
To extract an element from the values of a group of variables separated by |, use the RandomFromMultipleVars function.
RandomString UUID: Create a random type to produce a random string. 4 UUID
4. Function for Formatting Types:
This function is used for formatting.
dateTimeConvert: Changes a date or time from one format to another.
5. Properties Type Function:
These operations are carried out on JMeter or user-defined properties using these functions.
isPropDefined: To determine whether a property is present.
property: examining a property
P stands for “read a property” (shorthand).
setProperty: JMeter property setting
isVarTo determine whether a variable is present
6. Scripting Type Function:
These are used for scripting and validation at the coding level.
Apache Groovy script execution
BeanShell: How to execute a BeanShell script
JavaScript (Nashorn): To process JavaScript
evaluation of a Commons Jexl2 expression
evaluation of a Commons Jexl3 expression
7. Functions of the “String Type”:
These are used to operate with strings.
char: From a list of numbers, create Unicode char values by changingCase: To switch between cases after various modes
To encrypt texts using ORO regular expression quote meta chars, use escapeHtml or escapeOroRegexpChars.
escapeXml: To XML-encode texts.
regexUse a regular expression to encode and parse the previous response.
unescape: To handle strings that contain Java escape characters (such as n and t),
unescapeHtml: Decoding HTML-encoded strings
To decode an application/x-www-form-urlencoded string, use urldecode.
To convert a string to an application/x-www-form-urlencoded string, use the urlencode command.
TestPlanName: This command will yield the name of the current test plan.
8. Functions of the type of variables:
These functions are used to manipulate variables.
split: variable separation from a string
eval: evalVar is used to evaluate a variable expression. To assess a variable-stored expression
V: determining a variable name
Utilise – Function Assistant Dialogue
In the ‘Tools’ tab of the JMeter UI, JMeter provides the Function Wizard dialog to make things clearer and more useful.
You can choose a function from the dropdown list and specify the value of its arguments using the function wizard.
The argument is briefly described in the left column of the table, and the value of that argument is entered in the right column.
Note that different functions require different arguments.
Clicking the “Generate” button after specifying the arguments will generate the appropriate string for you to copy.
Copied functions can now be pasted anywhere in the test plan.
Use the predefined Apache JMeter function mentioned above to optimize your JMeter script.