Posts tagged ‘Creating Custom Request in VuGen LoadRunner’

Creating Custom Request in VuGen LoadRunner

There are some situations where you need to create custom request so that you can manipulate the request according to your need. Here we will see how to create custom request and tamper with it to get our job done.

Basic:

When we record the script for any web application, we generally choose HTML-based recording because it is easy and minimizes the correlations you have to handle in the script.

LoadRunner do generate custom request when some request does not fall under category of lr_web_submit_data() or lr_web_submit_form() requests category.

Challenge:

Suppose there is one request where you are sending some data items with it and every time there will be random number of data items like, first time there will be four data items second time there will be five data items in the same request. Here you cannot use same recorded request as number of data items are going to be different every time.

In below example you can see that there are only four data items in the request next time there may be five data item.

1
2
3
4
"Name=SearchResultsGrid_ctl04_ViewPackageDialogResult", "Value=291570", ENDITEM,
"Name=SearchResultsGrid_ctl08_ViewPackageDialogResult", "Value=291566", ENDITEM,
"Name=SearchResultsGrid_ctl11_ViewPackageDialogResult", "Value=291563", ENDITEM,
"Name=SearchResultsGrid_ctl12_ViewPackageDialogResult", "Value=291562", ENDITEM,

Solution:

Here you can create a custom request and use a parameter which will hold the manipulated string of data items. In that string you can save different number of data items and you can change it as required.

Procedure:

  1. First record the script with HTML-based recording and with proper transaction names for every action.
  2. Save that script and then click on Tools> Regenerate Script…


  3. Below popup will come, click on Options…


  4. It will show you the Regenerate options, Click on General> Recoding


  5. There are two options available, HTML-based script and URL-based script. Choose URL-based script.
  6. For URL-based script there is a button for advanced settings named URL Advanced, click on it.
  7. From the new popup select Use web_custom_request only.
  8. Save the settings and regenerate the script.
  9. In the regenerated script you can see that new script is generated which contain only web_custom_request.
  10. Now find the particular request which you want to manipulate with the help of transaction names which you have given while recording the script.

Below is the HTML-based recorded request, You can see that there are four data items of grid results,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
web_submit_data("managepackages.aspx_4",
"Action=http://{p_Url}/site/secure/reportcenter/managepackages.aspx",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://{p_Url}/site/secure/reportcenter/managepackages.aspx",
"Snapshot=t50.inf",
"Mode=HTML",
ITEMDATA,
"Name=SearchResultsGrid_ctl03_ViewPackageDialogResult", "Value={c_PackageID}", ENDITEM,
"Name=SearchResultsGrid_ctl04_ViewPackageDialogResult", "Value=291570", ENDITEM,
"Name=SearchResultsGrid_ctl08_ViewPackageDialogResult", "Value=291566", ENDITEM,
"Name=SearchResultsGrid_ctl11_ViewPackageDialogResult", "Value=291563", ENDITEM,
"Name=SearchResultsGrid_ctl12_ViewPackageDialogResult", "Value=291562", ENDITEM,
LAST);

Below is the custom request which is URL-based,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
web_custom_request("managepackages.aspx_4",
"URL=http:// {p_Url}/site/secure/reportcenter/managepackages.aspx",
"Method=POST",
"Resource=0",
"RecContentType=text/html",
"Referer= http://{p_Url}/site/secure/reportcenter/managepackages.aspx",
"Snapshot=t135.inf",
"Mode=HTTP",
"Body=SearchResultsGrid_ctl03_ViewPackageDialogResult={c_PackageID}"
"{final_string}",
/*//below string is going to vary every time so we are going to manipulate it every time using string manipulation functions//

"&SearchResultsGrid_ctl04_ViewPackageDialogResult=291570"
"&SearchResultsGrid_ctl08_ViewPackageDialogResult=291566"
"&SearchResultsGrid_ctl11_ViewPackageDialogResult=291563"
"&SearchResultsGrid_ctl12_ViewPackageDialogResult=291562"
*/

LAST);

In custom request you can manipulate final string every time using string manipulation functions available in VuGen.

final_sting= “&SearchResultsGrid_ctl04_ViewPackageDialogResult=291570&SearchResultsGrid_ctl08_ViewPackageDialogResult=291566&SearchResultsGrid_ctl11_ViewPackageDialogResult=291563&SearchResultsGrid_ctl12_ViewPackageDialogResult=291562″




P.S. : Thanks to Kranti.