LoadRunner Correlation - How to capture an array of dynamic data with web_reg_save_param function

LoadRunner Correlation - How to capture an array of dynamic data with web_reg_save_param function

Imagine, that server returns the following response:
(since blogspot.com doesn't show tags correctly, I'm reluctant to show server response as image) .

And we have to capture dynamic values of all IDs (underlined with green lines). These values can be used later - say, for LoadRunner script correlation.

As usual, several solutions exist :) Let's see them:

  1. Insert five web_reg_save_param functions using "Ord=1" (2, 3, ...) attribute:

    1. web_reg_save_param ("ID1Value", "LB= value=\"", "RB=\"", "Ord=1", LAST);
    2. web_reg_save_param ("ID2Value", "LB= value=\"", "RB=\"", "Ord=2", LAST);
    3. web_reg_save_param ("ID3Value", "LB= value=\"", "RB=\"", "Ord=3", LAST);
    4. web_reg_save_param ("ID4Value", "LB= value=\"", "RB=\"", "Ord=4", LAST);
    5. web_reg_save_param ("ID5Value", "LB= value=\"", "RB=\"", "Ord=5", LAST);


    Tips: Please, note that web_reg_save_param function does not perform correlation. web_reg_save_param function just registers a request for correlation from the next server response. That's why web_reg_save_param function should be placed before action functions, such as: web_url, web_submit_form, and others.

    Tips: Enable extended logging for LoadRunner parameters substitutions. It will be helpful for script debugging:

    OK, let's execute our script and see results - whether values will be captured or not:
    As you can see, web_reg_save_param functions executed correctly and parameters contain values.
    I would remind you that, we used "Ord" attribute. It indicates the ordinal position or instance of the match. Read LoadRunner Help on web_reg_save_param function for detailed info.

    Then, you can perform any operations with saved parameters (for instance, read article How to perform basic operations on LoadRunner parameters?)


    Another solution is to not use "Ord" attribute. Instead of it, we will extend boundaries to capture values from a server response.


  2. Insert five web_reg_save_param functions with extended boundaries:

    1. web_reg_save_param ("ID1Value", "LB=ID1\" value=\"", "RB=\"", LAST);
    2. web_reg_save_param ("ID2Value", "LB=ID2\" value=\"", "RB=\"", LAST);
    3. web_reg_save_param ("ID3Value", "LB=ID3\" value=\"", "RB=\"", LAST);
    4. web_reg_save_param ("ID4Value", "LB=ID4\" value=\"", "RB=\"", LAST);
    5. web_reg_save_param ("ID5Value", "LB=ID5\" value=\"", "RB=\"", LAST);


    I extended left boundaries and included ID1, ID2, etc with inverted quote. Since new boundaries will define values explicitly, we don't need use "Ord" attribute. That's why I deleted "Ord" attribute from web_reg_save_param function.

    Let's execute new code and see results:
    Values captured successfully! :) Ain't it fun? :)


    I think, now is a time to introduce third way how to capture an array of dynamic data.
    For that, we will use "Ord=All" attribute of web_reg_save_param function:


  3. Insert web_reg_save_param function using "Ord=All" attribute:

    1. web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);


    It looks very simple, doesn't it? :) Let's execute it and see results:

    Values captured. Great!
    There are several important items and I would like to pay your attention:
    • We specified one web_reg_save_param function only with "Ord=All" attribute, and it captured all values.
    • Captured values were saved into parameters with automatically generated names.
      Please, note that I specified initial parameter name - "IDValues". Values were saved into parameters "IDValues_1", "IDValues_2", "IDValues_3", etc. So, an array of values were created.
    • Additional parameter was created automatically - "IDValues_count". It contains number of matches saved to the parameter array.

    Please, see this example - how to use "_count" LoadRunner parameter to iterate all items in a array of captured values:

    1. web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);

    2. // get number of matches
    3. nCount = atoi(lr_eval_string("{IDValue_count}"));

    4. for (i = 1; i <= nCount; i++) {
    5.     // create full name of a current parameter
    6.     sprintf(szParamName, "{IDValue_%d}", i);

    7.     // output a value of current parameter
    8.     lr_output_message("Value of %s: %s",szParamName, lr_eval_string(szParamName));
    9. }


    And the result of execution is:
    (click to enlarge image).

    Using above example, you can simplify LoadRunner script correlation. If you have to capture an array of values from server response, do not forget about web_reg_save_param function only with "Ord=All" attribute.


Summary:
  • I provided several solutions how to perform correlation and capture an array of dynamic values.
  • Last solution (web_reg_save_param function using "Ord=All" attribute) is more simple and convenient.
  • One call of web_reg_save_param function can capture five, ten or hundred values and place them into an array of parameters.
    It is convenient - LoadRunner correlation becomes easier.


Do you have questions on LoadRunner correlation, my dear reader?
Ask me, and I will do my best to prepare exhaustive and detailed answer...

---
Thank you,
Dmitry Motevich



Related articles:

20 comments:

Dmitry Motevich said...

Exactly, Melnykenator :)

Anonymous said...

In Our JDE application system creating few unique values, those we have to enter in next step of operation.

- I want to know..how to capture those unique values which are getting recorded in the script?
- Can you tell us how to correlate these values manually ?

Anonymous said...

I am getting the following errors when I use your 3rd method using "atoi and sprintf".

Action.c (483): undeclared identifier `nCount'
Action.c (484): undeclared identifier `i'
Action.c (486): undeclared identifier `szParamName'
Action.c (487): type error in argument 1 to `lr_eval_string'; found `int' expected `pointer to char'
e:\\vuser scripts\\tmt\\service bp\\\\combined_Service BP.c (5): 4 errors, not writing pre_cci.ci

Raja said...

Hi Dmitry, please help me with the above error message. I will be very thankful to you. T

The values were captured successfully, however when I add the for loop section with nCount, sprintf and atoi I get the above mentioned errors

Dmitry Motevich said...

2Harpreet:

The errors "undeclared identifier" mean that you didn't declare your variables (nCount, i, szParamName) in the current scope.

Please, declare them like in my example script screenshot:

int i, nCount;
char szParamName[50];

Anonymous said...

not many know about the "Ordinal" attribute in web_reg_save_param().

after seeing the 2 examples, one can appreciate the value or importance of the ordinal attribute. u have explained it well. :-)

Raja said...

Hi Dmitry, thank you for clearing my previous doubts. It worked all well. Thanks.

I have another query- can you please help me with that as well. because its related to correlation for the same project I asked you earlier..

The project is like we have dynamic values in a table that we captured earlier with your above example and it later returned the values as well.

The project is like we have to select those values (or capture them in a array like we did) and then pass them into search option which futher opens the properties of those all values and further do the processing. Do I have to create seperate loop for the search option as well..

Please help me with the above.

Thank you.

Dmitry Motevich said...

2Harpreet:
Please, contact me by email for my consultation:
mangazey [ at ] gmail dot com

Anonymous said...

Hi
Thanx a lot for such a cool n clear
explanation.

i could get rid of most of the doubts with this example.

Really nice one.ur making it explorative and simplier.I have tried with my assignment i could solve it.

Thanx once again.
Raji.

Its Me ~~~ AKS said...

this is really great.can i have some detail information about "web_custom_request()" function.i am having lots of difficulty with this function.


Thanks and regards,
Shwena

Dmitry Motevich said...

2Anonymous:
Thank you :)
Keep tracking the blog!

vasu said...

Dmitry,

It'a awesome blogs really you are making life easy for the people who are assgined with LR scripting. Thanks a lot.

i was perparing a script on a web application whcih checks for didgital badge before logining into application i am facing lod of problems here. and even i am not able to see the script recored in VUgen. please share any you thoughts how to over come this issue.

Regards,
Vasu

Dmitry Motevich said...

2Vasu:
Provide more detailed info

Unknown said...

when you are trying to use "ORD=ALL" in the web_reg_save_param function, r u going to replace the 5 dynamic value with the single param name, since you have used one corelation function for 5 dynamic values

Dmitry Motevich said...

2maddy,
Yes, "ORD=ALL" means that we capture all values into into one LoadRunner parameter.

Anonymous said...

Hi Dmitry,

Very clear explaination! You must be a good prof (I guess). If you have time, could you show what happens in the following case:

web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);

web_url(...);
web_submit_form(...);

Will all the dymanic values from web_sumit_form be also captured in the array IDValues?

And what happen with the following case:

web_reg_save_param ("Array1", "LB= value=\"", "RB=\"", "Ord=All", LAST);

web_url(...);

web_reg_save_param ("Array2", "LB= value=\"", "RB=\"", "Ord=All", LAST);

web_submit_form(...);

Will Array1 contains ONLY dymanic values of web_url? And Array2 contains ONLY dynamic values of web_submit_form?

(With assumption that the LB, RB of the dynamic values are same?)

Thanks for your reply.

Dmitry Motevich said...

@Loc Pham,

1.
web_reg_save_param (...);
web_url(...);
web_submit_form(...);

In this case web_reg_save_param will capture values from web_url function only.
Values from web_submit_form won't be captured


2.
web_reg_save_param (...);
web_url(...);
web_reg_save_param (...);
web_submit_form(...);

In this case, 1st web_reg_save_param will capture values from web_url's response.
2nd web_reg_save_param will capture values from web_submit_form's response.

Anonymous said...

Hi,

This is very helpful to learn and work quickly on correlation. Thanks for poasting

Dmitry Motevich said...

@Anonymous (January 31, 2009),
Thank you very much!

Dmitry Motevich said...

Dear Readers!
Thank you very much for you comments!

Since this article was published more than one year ago, I've just disabled an adding of new comments for the article.