web_reg_save_param_json

web_reg_save_param_json

web_reg_save_param_json is used to capture the value of a JSON node in the server response. Mostly, this function is used where the server response is formatted in JSON. The required dynamic value can be easily captured by providing the path of the element name (node) in the query string of the function. The captured value is used in the subsequent requests. To use this function, you must have the knowledge to write the query string in JSON or you can simply use JSON pathfinder online tool (Link).

Why the function name is like this?

‘web_reg_save_param_json’ function is used for web protocol (denoted by “web”). This function registers a request (denoted by “reg”) to find out the dynamic data that has been formatted as JSON (denoted by “json”). After registering the request, the next task is to save the dynamic value in a parameter (represented by “save_param” words). Hence it is named as ‘web_reg_save_param_json’.

Follow the navigation to open web_reg_save_param_json input box:

  1. Press ‘Ctrl+Alt+B’ or View -> Steps Toolbox
  2. Type ‘web_reg_save_param_json’ in the search box. VuGen will show the matched content.
  3. Double click on ‘web_reg_save_param_json’ function. The window will appear with the following inputs:
web_reg_save_param_json
Figure 01

Attributes of ‘web_reg_save_param_json’:

a. Parameter Name: The name of the correlation parameter to store the dynamic value. This is a mandatory field.

b. QueryString: This is a mandatory attribute. In this attribute, you have to provide the path of the value to save.

c. SelectAll: This is an optional attribute. When you specify SelectAll=Yes, all the occurrences of the match are saved in an array. Each element of the array is represented by the ParamName_index and used to capture dynamic value on a specific occurrence. The first match is saved as ParamName_1, the second match is saved as ParamName_2, and so forth.

d. 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.

e. 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 the 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.

f. 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.

g. 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.

h. 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.

i. 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.

j. 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_json’

If you want to capture ‘Bengali’ in the below JSON response:

{
  "Indo-European": {
    "Indo-Iranian": {
      "Iranian": [
        "Persian"
      ],
      "Indic": [
        "Assamese",
        "Bengali"
      ]
    },
    "Baltic": [
      "Latvian",
      "Lithuanian"
    ],
    "Slavic": {
      "East Slavic": [
        "Russian"
      ],
      "South Slavic": [
        "Bulgarian"
      ]
    }
  }
}
web_reg_save_param_json(
	"ParamName=c_JSONValue",
	"QueryString=$.Indo-European.Indo-Iranian.Indic[1]",
	"NotFound=warning",
	"SelectAll=Yes",
	SEARCH_FILTERS,
	"Scope=BODY",
	"IgnoreRedirections=Yes",
	"RelFrameID=1",
	"RequestUrl=http://demoptsite.com",
	LAST);
web_reg_save_param_json - attribute
Figure 02

How to use web_reg_save_param_json function in the script?

  1. Identify the dynamic value in the script (How?)
  2. Locate the cursor before the request which has dynamic value in the response.
  3. Right click -> Insert -> New Step -> Steps Toolbox -> (Search for keyword) web_reg_save_param_json -> (Double Click on) web_reg_save_param_json -> ‘web_reg_save_param_json – Save Data to a Parameter’ window will open -> Provide the required input and press Ok.
    OR
    If you know the correct syntax and attributes of web_reg_save_param_json 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:

  1. web_reg_save_param
  2. web_reg_save_param_regexp
  3. web_reg_save_param_xpath
  4. web_reg_save_param_ex
  5. web_reg_save_attrib

Leave a Reply

Your email address will not be published. Required fields are marked *