Custom JMeter Functions

Download

In addition to standard JMeter functions we provide:

chooseRandomsince 1.0.1

This function choose single random value from the list of its arguments. The last argument is not taken into choice, it is interpreted as variable name to store the result.

Parameters:

  1. First value to choose from
  2. Second value to choose from
  3. ... any number of further choices ...
  4. Mandatory variable to store result

Example, choosing random color and assigning it to randomColor variable:

${__chooseRandom(red,green,blue,orange,violet,magenta,randomColor)}

doubleSumsince 0.4.2

This function used to compute the sum of two or more floating point values.

Parameters:

  1. First value to sum - required
  2. Second value to sim - required
  3. More values to sum - optional
  4. Last argument - variable name to store the result

Example, returning 8.3 and also saving it to variable sumVariable:

${__doubleSum(3.5, 4.7, sumVariable)}

envsince 1.2.0

This function used to get a value of environment variable. Returns value of environment variable if variable was defined, variable name instead (or default value) .

Parameters:

  1. First value is a name of environment variable - required
  2. Second argument - variable name to store the result - optional
  3. Third argument - default value if environment variable is not set - optional

Example, returning value of ENVVAR and also saving it to variable someVariable (or defaultValue if ENVVAR is not set):

${__env(ENV_VAR, someVariable, defaultValue)}

isDefinedsince 0.4.2

This function used to determine if variable was already defined. Returns 1 if variable was defined, 0 instead.

Parameters:

  1. First value is string constant, variable, or function call - required

Example, getting defined status for variable name 'testVar':

${__isDefined(testVar)}

MD5since 0.4.2

This function used to calculate MD5 hash of constant string or variable value.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Second argument - variable name to store the result

Example, calculating MD5 for 'test':

${__MD5(test)}

base64Encodesince 1.2.0

This function used to encode a constant string or variable value using Base64 algorithm.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Second argument - variable name to store the result

Example, encoding 'test string':

${__base64Encode(test string)}

base64Decodesince 1.2.0

This function used to decode a constant string or variable value from Base64 into string.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Second argument - variable name to store the result

Example, decoding that returns 'test string':

${__base64Decode(dGVzdCBzdHJpbmc=)}

strLensince 0.4.2

This function used to compute the length of constant string or variable value.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Second argument - variable name to store the result

Example, returning 11 and also saving it to variable lenVariable:

${__strLen(test string, lenVariable)}

Example, returning length of variable varName:

${__strLen(${varName})}

substringsince 0.4.2

This function is wrapper for Java String.substring method.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Begin index
  3. End index
  4. Optional variable to store result

Example, getting 'str' from 'test string':

${__substring(test string, 5, 8)}

strReplacesince 1.4.0

This function is wrapper for Java String.replace method.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Search substring
  3. Replacement
  4. Optional variable to store result

Example, getting 'banana dog orange' from 'banana apple orange':

${__strReplace(banana apple orange,apple,dog)}

strReplaceRegexsince 1.4.0

This function is wrapper for Java String.replaceAll method.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Search regular expression
  3. Replacement (can contain references to matched string parts, see Matcher.replaceAll)
  4. Optional variable to store result

Example, getting banana-apple-orange from banana apple orange:

${__strReplaceRegex(banana apple orange,' ',-)}

uppercase and lowercasesince 0.4.2

This functions used to transform the case of constant string or variable value.

Parameters:

  1. First value is string constant, variable, or function call - required
  2. Second argument - variable name to store the result

Example, transforming 'test' into 'TEST' and also saving it to variable someVariable:

${__uppercase(test, someVariable)}

iterationNumsince 1.2.1

Function returns the number of current iteration in thread group.

Function has no parameters.

ifsince 1.3.0

This function provides a == b ? a : b syntax.

Parameters:

  1. Actual value
  2. Expected value
  3. if condition true value
  4. if condition false value
  5. Optional variable to store result

Example, gettig different values for jmeter variable:

${__if(${size}, 5, ok, invalid)}