The regular expression in LoadRunner is one of the easiest options to implement the correlation logic for handling dynamic value in the script. web_reg_save_param_regex function helps to capture the dynamic values in the response using regular expression token. The main advantage of web_reg_save_param_regexp over web_reg_save_param is that you have an option to escape the content (string) to capture the required value. See the example given in this post later. If you got expertise in writing the regular expression then web_reg_save_param_regexp is an ultimate option for you.
Why the function name is like this?
web_reg_save_param_regexp function is used for web protocol (denoted by ‘web’). This function registers a request (denoted by ‘reg’) to find out the dynamic value based on the regular expression (denoted by ‘regexp’). After registering the request, the next task is to save the dynamic value in a parameter (denoted by ‘save_param’ words). Hence it is named as ‘web_reg_save_param_regexp’.
Follow the navigation to open web_reg_save_param_regexp input box:
- Press ‘Ctrl+Alt+B’ or View -> Steps Toolbox
- Type ‘web_reg_save_param_regexp’ in the search box. VuGen will show you the matched content.
- Double click on ‘web_reg_save_param_regexp’ function. The window will appear with the following inputs:
Attributes of ‘web_reg_save_param_regexp’:
a. Parameter Name: The name of the correlation parameter which saves the dynamic value. This is a mandatory field.
b. RegExp: This is a mandatory attribute. In this attribute, you have to write a regular expression to capture the dynamic data. Refer to the post to learn how to write regular expression?
c. Group: This is an optional attribute. Group attribute provides the option to capture multiple dynamic values using the same regular expression. If you pass 0 (zero) then it saves the entire expression along with the specified text. The maximum value is 10. Example: If you have specified the regular expression as given below and you need to capture SurName, then Group will be 2
"RegExp=Name=(.*?) and SurName=(.*?)",
d. DFEs: This is an optional attribute. It is a comma-separated list of Data Formats Extensions that are to be used before the required search operation is to be performed.
e. Ordinal (ORD): This is an optional attribute. It is used to capture dynamic value on a specific occurrence. If you specify the value of Ordinal (ORD) =ALL then all the occurrences of the matched boundary are saved in an array. Each element of the array is represented by the ParamName_index. In the following example, the parameter name is c_custID:
web_reg_save_param_regexp( "ParamName=c_custID", "RegExp=customerID=(.*?);", "NotFound=warning", "Group=2", "Ordinal=ALL", LAST);
The first match is saved as c_custID_1, the second match is saved as c_custID_2, and so forth. You can retrieve the total number of matches by using the following parameter ParamName_count. For example, to retrieve the total number of matches saved to the parameter array you can use the below statement:
h. Warn if text was not found (Default is Error) (NotFound): This is an optional attribute and has ‘Error’ as a default value. This option handles the situation when the defined boundary does not match and generates an empty string. It has the following input options:
- ERROR: This is a default value. When a boundary is not found then LoadRunner highlight it as an error in the log.
- WARNING: LoadRunner does not issue an error. If the boundary is not found, it sets the parameter count to 0 and continues executing the script. The ‘warning’ option is good when you want to see whether the string was found or not, but do not want the script to fail.
Note: If ‘Continue on Error’ option is enabled for the script then even when NOTFOUND is set to ‘ERROR’; the script continues when the boundary is not found, but an error message is written to the Extended log file.
i. Scope: This attribute comes under ‘Filters (SEARCH_FILTERS)’ option. This is also an optional attribute with default value “All”. It specifies the scope of the search of dynamic value within the response. The input options are:
- All: The scope of search is body, headers, and resources
- Headers: It indicates to search only in the headers
- Body: The scope of the search is only body, not headers
- Cookies: The scope of the search only cookies.
j. Header Name (HeaderNames): To enable this attribute you need to select ‘Scope’ type as Headers. Here, you can provide a comma-separated list of HTTP response header names then LoadRunner will search the dynamic values only in the specified headers. This is an optional attribute.
k. RequestURL: The dynamic values will be searched only in the responses of specified requests. The URL can contain the * wildcard. It is specially used to correlate the value coming in the response of flex_amf_call.
l. Content Type (ContentType): LoadRunner searches the dynamic value in the responses with the specified ContentType header. The ContentType can contain the * wildcard. This is an optional attribute.
m. Frame ID (RelFrameID): This is an optional attribute. The hierarchy level of the HTML page relative to the requested URL. The possible values are ‘All’ or a number.
Note: GUI level scripts do not support RelFrameID.
n. Ignore Redirection (IgnoreRedirections): This is an optional attribute with default value “No”. The inputs are:
- Check (Yes): By setting the ‘IgnoreRedirections=Yes’, it instructs LoadRunner not to search the dynamic value in the response of the redirected request. You can identify the redirected request by its response code HTTP 3XX.
- Uncheck (No): LoadRunner even searches the existence of dynamic value in the response of the redirected request.
Example: ‘web_reg_save_param_ex’ with attributes
web_reg_save_param_regexp( "ParamName=c_custInfo", "RegExp=Name=(.*?) and SurName=(.*?)", "NotFound=warning", "Group=2", "Ordinal=ALL", SEARCH_FILTERS, "Scope=BODY", "IgnoreRedirections=Yes", "RelFrameID=2", "RequestUrl=http://myperformancetetsingdemosite.com", LAST);
How to use web_reg_save_param_regexp function in the script?
- Identify the dynamic value in the script (How?)
- Locate the cursor before the request which has dynamic value in the response.
- Right click -> Insert -> New Step -> Steps Toolbox -> (Search for keyword) web_reg_save_param_regexp -> (Double Click on) web_reg_save_param_regexp -> ‘web_reg_save_regexp – Save Data to a Parameter’ window will open -> Provide the required input and press Ok.
If you know the correct syntax and attributes of web_reg_save_param_regexp function then you can simply type in the script.
Important Point: LoadRunner’s correlation functions are always written/placed before the request whose response contains the dynamic value.
In addition, there are four more correlation functions in the LoadRunner. Refer to the link to get more detail:
Frequently used regular expression tokens:
- (.*?) – It matches any string including a new line
- (.+?) – It matches the strings including letters, digits and space (exclude new line)
- ([a-zA-Z]+) – It matches any characters between a-z or A-Z
- ([\d]) OR ([0-9]+) – It matches any decimal digit
Refer to the link to know more regular expression tokens and how to write them.
How to escape the content in the response and capture the correct value?
Example: A request has below response including class, type, category, foodcategory and name.
class=livingthing,type=mammal,catagory=animal,foodcatagory=carnivores,name=lion; class=livingthing,type=mammal,catagory=animal,foodcatagory=carnivores,name=tiger; class=livingthing,type=mammal,catagory=animal,foodcatagory=carnivores,name=leopard; class=livingthing,type=mammal,catagory=animal,foodcatagory=carnivores,name=dog; class=livingthing,type=reptile,catagory=animal,foodcatagory=carnivores,name=snake; class=livingthing,type=reptile,catagory=animal,foodcatagory=carnivores,name=lizards; class=livingthing,type=mammal,catagory=animal,foodcatagory=carnivores,name=cat;
If you want to capture the name of all the mammals then probably you will write like this:
By using escape token you can shorten the token string like this:
Try at your end and see the magic!