9

Jmeter-Extract data using Post Processor Part- II

 2 years ago
source link: https://blog.knoldus.com/jmeter-extract-data-using-post-processor-part-ii/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Jmeter-Extract data using Post Processor Part- II

Reading Time: 4 minutes

Hello everyone ! I hope you are doing well in this pandemic of COVID-19. In the previous blogs, we saw how we can extract the data from Jmeter using post-processor- JSON Extractor. Here in this blog, we will see other post-processors like Regular Expression. Many of us feel that creating regular expressions is difficult for non-technical people. So most of us avoid using regular expressions for extracting data. Now in this blog, we will learn how easily we can extract data using post-processor -Regular Expressions.

Now the first  question in your mind will arise- What is Regular Expressions and then we will move how to extract data from Jmeter using Post Processor

Regular Expression- 

It is an expression of pattern in the string used to search and manipulate text, based on patterns.

Here we extract the digit(1001) from this expression  on the left side (Jill rollnumber is 1001).

So in Jmeter when we need to extract any data from any response. We can extract that particular data and pass the same in another chaining request. I hope you will get to know about regular expressions from this example. For more, you can check on this link.

How to Create Regular Expression to extract Data- 

Here our motive is not to learn the regular expression. We will see how we can use this regular expression for extracting data. So for ease, I‘ll suggest using the tool Regex to write the regular expression. In this, you can validate your regular expression and get some cheat hints to create regular expressions.

Here you can add  your response or string from which you want to extract the data-

Now you can use the cheat sheet to learn the syntax of regular expression-

Let’s take an example with a response API. If you have any response and you need to extract a token. Then you can perform these actions-

  • Firstly copy the response of any API in the regex tool.
  • Then find the value with ctrl+f which you need to extract.
  • Find some unique string/characters around that value.
  • With the help of those strings and cheat sheets, you can write the regular expression.
  • Check that regular expression is correct from the match on the right side.
  • Now you will be confirmed this regular expression matches that value.
  • You can copy that regular expression.

Then you can use the regular expression post processor. So for it you have to create regular expressions in regex.

How to use Regular expression in JMeter – 

I hope you will know how to create and record the Jmeter script. You can also check my earlier blogs to learn script creation here.

  • Add Post Processor- Regular Expression Extractor which  should be placed under the Http sampler and will be  run after the request.
  • Now Regular Expression Extractor contains these fields given below.
  1. Name – Here you can add the name of the postprocessor. By default, it is named as Regular Expression. 
  1. Name of created variable – In this, you can set the variable name of the value which you need to extract so that you can pass the variable in other requests.
  1. Regular Expression– In this, you have to add the correct regular expression.
  1. Template-Templates are references or pointers to the groups. A regex may have more than one group. It allows you to specify which group value to extract by specifying the group number as $1$ or $2$ or $1$$2$ (extract both groups) and $0$ (default group)
  1. Match No.-A regex applied to the response data may have more than one match. You can specify which match should be returned.
  1. Default Value- This is the default value when extraction does not apply to the response then this value will display there.
  • Next, add that copied regular expression from the regex tool in the Jmeter regular expression postprocessor. Also, add all the fields like-

Regular Expression postprocessor in Jmeter

  • Pass the variable name ‘token’ in the other request as ${token}
  • Then run the test and check the result. The extracted value should be reflected in the request.
  • You can also print that variable to see good results.
  • Now time to see the results of this overall blog-

So this is how we can add the regular expression and extract any type of data.It is very easy to use in Jmeter. If you have any questions and queries related to Jmeter ,you can ask in the comments. I’ll provide the solution asap.

I hope you enjoyed it and it helped you!! stay connected for more future blogs. 

Thank you!!  🙂

References:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK