Regexp Variable Extractor¶
Regular Expression Extractors lets you extract values from HTTP responses, using regular expressions.
Extracting variables from HTTP response helps you make your Virtual User have a dynamic behavior. Extracted variables can be injected in Logic Actions or HTTP Request Actions.
The first line displays the extracted variable name. This field is mandatory if you want to inject what you extract. The second line contains tab headers to access:
- Simple Configuration, to easily generate a regular expression,
- Advanced Configuration, for more specific needs,
- Check, to validate the result of your Regexp against a recorded HTTP response.
The response selector, on the right, lets you choose which HTTP response is used for configuring and checking the Regexp Action. So if neither recorded responses nor Validate VU responses are available, you have to configure the Regexp Action blindly.
The Regexp Action is used to extract values from both HTTP response headers and body.
To extract a value from a response body :
- Select the Configuration tab,
Bodyon the right toggle buttons,
- Browse the response body, and select the text you want to extract,
- Blue and green selections appear on the sides of the selected text, it displays the left and right text delimiters,
- Adjust left and right offsets to stretch or shrink the text delimiters,
- The generated regexp is shown on the bottom of the tab, it has the form 'Any text between left delimiter and right delimiter' and can be edited in Advanced mode.
- Click on the body text area,
- Type CTRL + F (or CMD + F on Mac), a dialog appears on top of the area,
- Type the text to search or a regex,
- Press Enter to start searching for the first term occurrence
- Press CTRL + G (or CMD + G on Mac) to find the next occurrence, or SHIFT + CTRL + G (or SHIFT + CMD + G on Mac) to find the previous one.
To extract a value from the headers of an HTTP response :
- Select the Configuration tab,
Headerson the right toggle buttons,
- Browse the response headers, and select the one whose value you want to extract,
- The generated regexp is shown on the bottom of the tab and can be edited in advanced mode.
You may start by using the simple mode, and then switch to advanced to customise the generated regexp.
The Advanced tab may fulfil more complex requirements.
The following procedure explains how to configure a Regexp Action:
- Select the Advanced tab,
Bodyon the right toggle buttons, depending on where your want to apply the regular expression,
- Fill in the
Regexp fieldusing ORO matcher syntax,
- Type the template to extract,
- Select the match number. The regexp may match multiple values in the HTTP response, in such case you can select which value to extract,
- Fill in the default value (if the regexp does not match the HTTP response).
The response panel only displays the content of the HTTP response Body / Headers. To select the text to extract, use the simple Configuration tab.
The template format:
- $0$ extracts the whole regexp,
- The default
$1$value, to extract the first group value (a group is what is between a set of parenthesis). E.g. for the regexp
$1$extracts the string matched by
- In case you use multiple groups in the regexp,
$n$extracts the nth group value.
- You can also include arbitrary text in the template. E.g. 'cat$1$' to generate the string 'cat' followed by the content of the first group.
The match number format:
- Random, to select any of the values.
- Select nth, to select a particular value.
- All, to select all values. If you select this option, the generated variable can be used in the ForEach Action.
Check regexp result¶
To check the result of a Regexp action just click on the Check tab.
The check process is automatically launched when this tab is opened. It can also be manually started using the Refresh button.
A table contains the extracted values :
|Extracted variable name||The name of the extracted variable. A single Regexp Action can lead to multiple extracted variables. More information below.|
|Extracted variable value||The value of the extracted variable.|
Multiple variables can be generated by a single Regexp Action.
E.g. for an extractor named
categoryId with the regexp value
Select nth match number and a template
categoryId: the base variable, it contains the extracted value (or the default value), e.g.
categoryId_g: the count of groups used in the regexp,
categoryId_g0: the whole extraction, delimiters included, e.g.
categoryId_gn: where n=0,1,2 - the groups values.
All match number, multiple variables are generated to be used in the ForEach Action :
categoryId: always has the default value,
categoryId_matchNr: the number of values extracted, e.g. 5,
categoryId_N: the Nth value extracted,
- and for each
The error message 'Variable name must not be null to run the test.' may be displayed if the Regexp Action has no name. An extracted variable without name cannot be used for value injection.