(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:
- Insert five web_reg_save_param functions using "Ord=1" (2, 3, ...) attribute:
- web_reg_save_param ("ID1Value", "LB= value=\"", "RB=\"", "Ord=1", LAST);
- web_reg_save_param ("ID2Value", "LB= value=\"", "RB=\"", "Ord=2", LAST);
- web_reg_save_param ("ID3Value", "LB= value=\"", "RB=\"", "Ord=3", LAST);
- web_reg_save_param ("ID4Value", "LB= value=\"", "RB=\"", "Ord=4", LAST);
- 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. - Insert five web_reg_save_param functions with extended boundaries:
- web_reg_save_param ("ID1Value", "LB=ID1\" value=\"", "RB=\"", LAST);
- web_reg_save_param ("ID2Value", "LB=ID2\" value=\"", "RB=\"", LAST);
- web_reg_save_param ("ID3Value", "LB=ID3\" value=\"", "RB=\"", LAST);
- web_reg_save_param ("ID4Value", "LB=ID4\" value=\"", "RB=\"", LAST);
- 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: - Insert web_reg_save_param function using "Ord=All" attribute:
- 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:- web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);
- // get number of matches
- nCount = atoi(lr_eval_string("{IDValue_count}"));
- for (i = 1; i <= nCount; i++) {
- // create full name of a current parameter
- sprintf(szParamName, "{IDValue_%d}", i);
- // output a value of current parameter
- lr_output_message("Value of %s: %s",szParamName, lr_eval_string(szParamName));
- }
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. - web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);
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:
- Using Correlation in LoadRunner scripts - visual tutorial
- What are LoadRunner parameter and parameterization?
- Boundaries for web_reg_save_param LoadRunner function?
- How to perform basic operations on LoadRunner parameters?
- Using parameters in Loadrunner VuGen script