Table of contents
1.
Introduction
2.
What are JMeter Functions?
2.1.
Syntax
3.
How to Create JMeter Test Plan?
4.
How to Add Sampler?
5.
How to Add Listener?
6.
Save and Execute Test Plan
7.
Verify the Output
8.
Frequently Asked Questions 
8.1.
What does the counter function do?
8.2.
What is the use of JMeter?
8.3.
What does the slash signify while entering the path?
8.4.
What is the job of the BeanShell function?
8.5.
What is the significance of parenthesis while writing the syntax for JMeter Functions?
9.
Conclusion
Last Updated: Mar 27, 2024
Easy

What are JMeter ─ Functions?

Author Geetika Dua
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

So, what exactly is JMeter?

JMeter is an open-source Java application to analyze the performance of web applications.

Introduction

It was inclined to test Web Applications. It has now expanded to other test functions. Apache JMeter is widely used to test performance on static and dynamic resources and web applications. Let us know more about JMeter Functions in this article.

What are JMeter Functions?

JMeter functions are unique values that can occupy fields of any Sampler or other element in a test tree.

Let us define the syntax in the following way-

${__functioncodingninjaName(variable01,variable02,variable03)} , 

Here "__functioncodingninjaName" is the name of a function and parentheses enclose the parameters sent to the function.

Function Type

Name

Comment

Information threadNum It gets the thread number.
Information samplerName It gets the sampler name.
Information machineIP It gets the local machine IP address.
Information machineName It gets the local machine name.
Information time Its task is to return the current time in various formats.
Information log It displays a message.
Information logn It logs or displays a message.
Input StringFromFile It reads a line from a file.
Input FileToString This function reads the entire file.
Input CSVRead This function reads from a CSV file.
Input XPath XPath expression helps to read a file.
Calculation counter Its job is to generate an incrementing number.
Calculation intSum This function adds int numbers.
Calculation longSum This function adds long numbers.
Calculation Random It generates a random number.
Calculation RandomString It generates an arbitrary string.
Calculation UUID It generates a random type 4 UUID.
Scripting BeanShell The job of this function is to run a BeanShell Script.
Scripting javaScript It processes javascript.
Scripting jexl, jexl2 It evaluates a Commons Jexl expression.
Properties property It reads a property.
Properties P It reads a property by the shorthand method.
Properties setProperty It sets a JMeter property.
Variables split The job of this function is to split a string into variables.
Variables V This function evaluates a variable name.
Variables eval It evaluates a variable expression.
Variables evalVar It evaluates a word stored in a variable.
String regexFunction Its job is to parse the previous response using a regular expression.
String escapeOroRegexpChars This function quotes meta chars. 
String char This function generates Unicode char values from a list of numbers.
String unescape It processes strings containing Java escapes (e.g. \n & \t).
String unescapeHtml Its job is to decode HTML-encoded strings.
String escapeHtml Its task is to encode strings using HTML encoding.
String TestPlanName It returns the name of the current test plan.

 

Let us consider an example of a Log Function to understand the use of functions in JMeter.

Syntax

This is the syntax of the JMeter log function.

${__log("Welcome to Coding Ninjas")}  

To carry out the execution, we will first create a JMeter Test plan and execute an HTTP request.

How to Create JMeter Test Plan?

Follow these steps to create a JMeter Test Plan after completing the installation.

  • Navigate to the JMeterbin folder and select the Apache JMeter ".jar" file. It will successfully launch the JMeter interface if done correctly. 
  • Click on the test plan node and right-click.
  • Go to the  "Add" option. You will see a list.
  • Now you have to select Threads (Users) > Thread Group.
  • Rename this Thread Group as Thread Group CodingNinjas1.

How to Add Sampler?

We have to add an HTTP request sampler in our Thread Group called Thread Group CodingNinjas1.

  • First, Select the Thread Group CodingNinjas1 and right-click on that.
  • Hover on the "Add" option to see the lists of elements.
  • Now, you have to select the Sampler > HTTP request option.
  • You will see that it will add an empty HTTP Request Sampler.
HTTP

Let us try to configure the fields of the HTTP Request Sampler in the following way

  • Name - HTTP Request Sampler 1.
  • Server Name or IP -The web server name will be www.codingninjas.com
  • Protocol - This field is left unchanged.
  • Path - Writing it as "/" (slash) signifies that we want the root page of the server.

Now, let us duplicate Thread Group 1 and do the following-

  • Rename the other two thread groups as Thread Group CodingNinjas2 and Thread Group CodingNinjas3, respectively, and samples will be HTTP Request 2 and HTTP Request 3, respectively.

The following image visualizes the directory structure of our test plan.

 

test plan

How to Add Listener?

  • Select the Test Plan node and right-click on the selected item.
  • Mouse hovers on the "Add" option, then display the elements list.
  • Now, you have to select Listener > Summary Report.
Summary

Save and Execute Test Plan

  • To save the file, click on File, then Save Test Plan as CodingNinjas.jmx
Save
  • To execute the test plan, Click on Run > Start.

Verify the Output

Verify

After we have executed our test plan; we will use the log function.

Log message

Click on Run > Start to perform the test plan.

After we run the test plan, We will see that the Log function displays Welcome to Coding Ninjas instead of the name of the sampler.

Must Read Apache Server

Frequently Asked Questions 

What does the counter function do?

The job of the counter function is to generate an incrementing number.

What is the use of JMeter?

JMeter was inclined to test Web Applications. It has now expanded to other test functions. Apache JMeter is widely used to test performance on static and dynamic resources and web applications.

What does the slash signify while entering the path?

Writing Path as "/" (slash) suggests that we want the root page of the server.

What is the job of the BeanShell function?

The work of the BeanShell function is to run a BeanShell Script.

What is the significance of parenthesis while writing the syntax for JMeter Functions?

The parentheses enclose the parameters sent to the function.

Conclusion

This blog has given an overview of JMeter Functions. It has also discussed the detailed implementation of JMeter by creating a JMeter Test Plan; We hope it added to your knowledge.

For more information on JMeter, Refer to our other articles-

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass