A Regular Expression Extractor from JMeter works as a Post Processor. When using a regular expression regex extractor as a Sampler child element you need to fill up five fields:
Name of created variables: The variable name will be used to assign the extracted data by using ${var} format.
Regular Expression: This is the space where regular expression will be written to extract data.
Template: This I will use to give the index number of the extracted variable using $1$ format
Match no: If I have many matches then I will use this to tell which item to be used from the index. If 0 is entered that means any random value will be picked
Default Value: This is used when there is no value found.
Here we will see how to extract Auth token from Response Headers using Jmeter Regular Expression Extractor Post Processor.
Let’s see it with a working example.
I have a Login HTTP Request in a sampler which will make a request to a web service and will return data as a JSON response. From this response I need to extract the auth token which is part of Response Header.
My regular expression is – “x-auth:\s+(.+)”
This expression selects the parameter for the x-auth response header and selects everything after colon blank space i.e. the actual value of the x-auth response header.
The value that will be extracted from the above regular expression will be stored in authToken variable which will be used by entering ${authToken} in the subsequent samplers.
Remember to select the radio button “Response Headers” in the Field to Check section.
Now when I run the test, the header manager in the logout HTTP request will use the data that gets assigned to authToken variable from the regular expression extractor jmeter correlation in the login HTTP request and logout HTTP request will be executed successfully.
I hope the tutorial gives you the insights you need to start using this great framework. For any queries, you can contact us here.