Apache JMeter – samplerName Function

samplerName is an in-build function of Apache JMeter and its type is ‘Information’. This function simply returns the name of the sampler. By the way, JMeter in-build functions are divided into eight categories which are:

  1. Information
  2. Input
  3. Calculation
  4. Formatting
  5. Scripting
  6. Properties
  7. Variables
  8. Strings
Apache JMeter - samplerName Function

Let’s discuss about samplerName function:

Syntax: ${__samplerName}

Type: Information

Purpose: To get the name of the current sampler used in the JMeter script.

Example: If there are 2 samplers named Login and Logout under a Thread Group then ${__samplerName} will return the values like below:

Thread GroupSampler NameReturn Value
TG01Login${__samplerName} = Login
TG01Logout${__samplerName} = Logout

Input Argument: No input value can pass in the samplerName function.

Return Value: A string i.e. the name of the sampler.

Use: The samplerName function has a special use when you write some complex code in Groovy or Beanshell when it is used for Pre-Processors, Post-Processors and Assertions.

Limitation:

  1. The samplerName function does not work in any Configuration elements (e.g. User Defined Variables) as these are run from a separate thread. However some Configuration elements are referenced directly by samplers, such as the HTTP Header Manager and HTTP Cookie Manager, and in this case, the functions are resolved in the context of the HTTP Sampler. 
  2. It works only under the Thread Group level; not at the Test Plan level.

You may be interested:


Leave a Comment