Regular Expression Extractor uses regular expression string to fetch some values from response of one request and pass it on to another request.
The value(s) which is extracted can be stored in any variable and can be used for reference in any further request in the test plan.
Values can be extracted from Response Body, Response/Request Headers, URL, Response Code and Response Message of the request when you add this Post Processors to it.
Using of Regular Expression Extractor in a test plan, will save us a lot of time in creating or enhancing a test plan.
Adding Regular Expression Extractor in a test plan:
Choose a request in a Test Plan from which you want to extract the value and Right click the request and select Add >>Post Processors >>Regular Expression Extractor .
Fields of Regular Expression Extractor:
- Reference Name: The name of the variable in which to store the extracted value.
- Regular Expression: Expression for parse the response data and save it in the Variable as Reference Name .
- Template: Used to create a string from the matches found. The syntax to refer to a group is:
-'$1$' to refer to group 1
-'$2$' to refer to group 2
-'$0$'refers to whatever the entire expression matches
- Match No.: Can specify which value should be used from the character sequence.
-Zero indicates, to choose a match at random.
-A positive number N means to select the nth match from the sequence etc.
- Default Value: If the regular expression does not match, then the reference variable will be set to the default value.
Below is the response data of the login request which we have and we need pass ID for the next or further requests in the Test Plan.
By adding Regular Expression Extractor post processor to the login request and fields of the post processor can be defined as:
The special characters used for regular expressions are:
RegExp Tester: We have RegExp Tester in View Result Tree to test regular expressions directly on sampler response data.
This is all about the Regular Expression Extractor in JMeter and its usage. Read more blogs related to JMeter and various aspects of testing here.