Introduction to JMeter Regular Expression Extractor
We know that JMeter is an open-source, free tool for performing performance, loading, and stress testing on static and dynamic applications. JMeter expression extractor is one feature used to extract the required information from the response of the test plan. Typically regular expression provides the method to extract the data, but this is not effectively implemented with the help of a regular expression extractor.
- With the help of regular expression, we search and manipulate the text based on the specified pattern.
- This is one of the powerful features of JMeter.
- Using a regular expression extractor, we can extract the text from the response server, such as token, Auth2, specified file name, etc.
Overview of JMeter Regular Expression Extractor
JMeter, the most famous open-source presentation testing instrument, can work with ordinary articulations with the Regular Expression Extractor. Ordinary articulations are an instrument used to separate an expected piece of the text by utilizing progressed controls. Normal articulations are well known while testing web applications since they can be used to approve and perform procedures on a reaction from a web application. Regular expression helps extract the required information from the response per our requirement. Another use case is saving the removed data to a variable, which may be utilized later in the exhibition test, for instance, while testing an application that utilizes token validation, such as CSRF/XSRF.
Working of JMeter Regular Expression Extractor
Let’s see how we can use a regular expression extractor in JMeter as follows:
JMeter regular expression extractor is used to fetch the information from the response server, so first, we need to create the test plan, and inside the test plan, we need to add the thread group, as shown below screenshot.
Now we need to add the Post Processors that are Regular Expression Extractors, so first, we need to right-click on the Test Plan, select Add and hover the mouse on the Post Processor tab and click on Regular Expression Extractor as shown below screenshot.
After clicking on Regular Expression Extractor, we get a new screen, as shown in the screenshot below.
In the above screenshot, we can see the different fields such as Name; Comments Apply to, Field to check, Variable name, Regular expression template Match No and Default value. So as per our requirement, we need to fill in these details as shown below screenshot.
In the above point, we see how it works. But first, let’s know the purpose of this Regular Expression Extractor as follows.
To correlate the dynamic value, we need to use Regular expression. The handling of the dynamic parameter is effortless. First, we need to put the CSRF token into the category we already created, but there is no single token. Instead, we have multiple tokens such as .NET, Oauth2, and many more. On the other hand, we can say that the dynamic parameter is nothing but the session or token value that frequently changes over the request and response.
JMeter Regular Expression Extractor Element
Let’s see what the elements we use to extract the regular expression are as follows:
To involve customary articulations in your test plan, you want to utilize the Regular Expression Extractor of JMeter. You can put standard articulations in any part of a Test Plan.
It merits focusing on the distinction between contains and coordinates, as utilized on the Response Assertion test component: contains implies that the customary articulation matched in any event some piece of the objective, so’ letter set’ “contains” ‘ph.b.’ because the normal articulation matches the substring ‘page.’
Matches imply that the customary articulation matched the entire objective. Subsequently, the ‘letter set’ is “coordinated” by ‘al.*t.’
Let’s consider an example: Suppose we want to match the following pattern.
name = "specified file" value ="read.txt"
We can use the following regular expression to extract the read.txt file.
name = "specified file" value =(.+?)>
- (): It is used to match the string that we want.
- .: It is used to match any character.
- +: It is used to specify one or more strings.
- ?: With the help of questions, we can stop the regular expression when the match succeeds.
JMeter Regular Expression HTTP Request
First, we need to create a Test Plan. Then, inside the Test Plan, we need to add the Thread and Thread Group, same as the above example as shown below screenshot.
Now we need to add the HTTP request and fill in all the required details as shown below screenshot.
Next, we need to add the Regular Expression Extractor, so select the HTTP request, select the Add, and then Post Processor, and click on the Regular Expression Extractor option, as shown in the screenshot below.
In the screenshot, we can see the different fields; let’s see the meaning one by one as follows:
- Reference Name: This is nothing but the variable name which we need to extract.
- Regular Expression: This is nothing but the specified pattern we need to extract from the response string, which will be matched.
- Template: The template stores the extracted text as the variable.
- Match No: This is used to see the matching pattern, 0 is for a random matching string, and 2 is a volunteer.
- Default: If there is no item to display or not found, we can set the default value.
Now run the Test Plan and see the result in the Listener, as shown in the below screenshot.
Given below is the FAQ of JMeter Regular Expression Extractor:
Q1. What is the use of regular expression in performance testing?
It helps us to fetch the required string to get the dynamic values.
Q2. How to explain regular expression?
A regular expression is nothing but the method used for pattern matching.
Q3. What are the types of Regular Expressions?
There are two types of Basic and Extended Regular Expressions.
In this article, we are trying to explore JMeter regular expression extractor. In this article, we saw the different types of JMeter regular expression extractors and the uses and features of these JMeter regular expression extractors. Another point from the article is how we can perform and set up the regular expression extractor in JMeter.
This is a guide to JMeter Regular Expression Extractor. Here we discuss the introduction, working, JMeter regular expression extractor element, and FAQ. You may also have a look at the following articles to learn more –